Skip to content
This repository was archived by the owner on Jan 19, 2025. It is now read-only.

Commit 56e80a2

Browse files
committed
Particle optimized for mobile 🚀
1 parent ec56116 commit 56e80a2

File tree

5 files changed

+86
-89
lines changed

5 files changed

+86
-89
lines changed

graphql-types.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,8 +258,6 @@ export type DirectoryCtimeArgs = {
258258
export type Site = Node & {
259259
buildTime?: Maybe<Scalars['Date']>;
260260
siteMetadata?: Maybe<SiteSiteMetadata>;
261-
port?: Maybe<Scalars['Int']>;
262-
host?: Maybe<Scalars['String']>;
263261
polyfill?: Maybe<Scalars['Boolean']>;
264262
pathPrefix?: Maybe<Scalars['String']>;
265263
id: Scalars['ID'];
@@ -1011,8 +1009,6 @@ export type QueryAllDirectoryArgs = {
10111009
export type QuerySiteArgs = {
10121010
buildTime?: Maybe<DateQueryOperatorInput>;
10131011
siteMetadata?: Maybe<SiteSiteMetadataFilterInput>;
1014-
port?: Maybe<IntQueryOperatorInput>;
1015-
host?: Maybe<StringQueryOperatorInput>;
10161012
polyfill?: Maybe<BooleanQueryOperatorInput>;
10171013
pathPrefix?: Maybe<StringQueryOperatorInput>;
10181014
id?: Maybe<StringQueryOperatorInput>;
@@ -2187,8 +2183,6 @@ export type SiteFieldsEnum =
21872183
| 'siteMetadata___contacts___links___medium'
21882184
| 'siteMetadata___contacts___links___devto'
21892185
| 'siteMetadata___contacts___links___instagram'
2190-
| 'port'
2191-
| 'host'
21922186
| 'polyfill'
21932187
| 'pathPrefix'
21942188
| 'id'
@@ -2290,8 +2284,6 @@ export type SiteGroupConnection = {
22902284
export type SiteFilterInput = {
22912285
buildTime?: Maybe<DateQueryOperatorInput>;
22922286
siteMetadata?: Maybe<SiteSiteMetadataFilterInput>;
2293-
port?: Maybe<IntQueryOperatorInput>;
2294-
host?: Maybe<StringQueryOperatorInput>;
22952287
polyfill?: Maybe<BooleanQueryOperatorInput>;
22962288
pathPrefix?: Maybe<StringQueryOperatorInput>;
22972289
id?: Maybe<StringQueryOperatorInput>;
Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,19 @@
11
import React from "react";
22
import Particles from "react-tsparticles";
3-
import { useIsPowerfulMobileDevice } from "../logic/device";
4-
import { isDesktop } from "react-device-detect";
53
import { useParticlesConfiguration } from "../logic/particles";
64

75
export const BackgroundFullScreen: React.FC = () => {
8-
const isPowerfulMobileDevice = useIsPowerfulMobileDevice();
96
const particlesConfiguration = useParticlesConfiguration();
107

118
return (
12-
<div>
13-
{(isDesktop || isPowerfulMobileDevice) && (
14-
<Particles
15-
id="tsparticles"
16-
style={{
17-
position: "absolute",
18-
top: 0,
19-
left: 0,
20-
}}
21-
options={particlesConfiguration}
22-
/>
23-
)}
24-
</div>
9+
<Particles
10+
id="tsparticles"
11+
style={{
12+
position: "absolute",
13+
top: 0,
14+
left: 0,
15+
}}
16+
options={particlesConfiguration}
17+
/>
2518
);
2619
};

src/logic/device.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,21 @@
11
import { useHardwareConcurrency, useMemoryStatus } from "react-adaptive-hooks";
2-
import { isMobile } from "react-device-detect";
2+
import { isDesktop, isIOS, isMobile } from "react-device-detect";
33

44
export const useIsPowerfulMobileDevice = () => {
55
const { deviceMemory } = useMemoryStatus({ deviceMemory: 1 });
66
const { numberOfLogicalProcessors } = useHardwareConcurrency();
77

88
return (
9-
isMobile &&
10-
deviceMemory >= 3 &&
11-
numberOfLogicalProcessors != null &&
12-
numberOfLogicalProcessors >= 8
9+
isIOS ||
10+
(isMobile &&
11+
deviceMemory >= 4 &&
12+
numberOfLogicalProcessors != null &&
13+
numberOfLogicalProcessors >= 8)
1314
);
1415
};
16+
17+
export const useIsPowerfulDevice = () => {
18+
const isPowerfulMobileDevice = useIsPowerfulMobileDevice();
19+
20+
return isDesktop || isPowerfulMobileDevice;
21+
};

src/logic/particles.ts

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1,75 @@
11
import { textAbovePrimaryColor } from "../components/theme";
22
import { ISourceOptions } from "tsparticles";
3+
import { useIsPowerfulDevice } from "./device";
4+
import { isDesktop, isMobile } from "react-device-detect";
35

4-
export const useParticlesConfiguration: () => ISourceOptions = () => ({
5-
background: {
6-
color: {
7-
value: "transparent",
8-
},
9-
},
10-
fpsLimit: 60,
11-
interactivity: {
12-
detectsOn: "canvas",
13-
events: {
14-
onHover: {
15-
enable: true,
16-
mode: "repulse",
6+
export const useParticlesConfiguration: () => ISourceOptions = () => {
7+
const isPowerfulDevice = useIsPowerfulDevice();
8+
9+
return {
10+
background: {
11+
color: {
12+
value: "transparent",
1713
},
1814
},
19-
modes: {
20-
repulse: {
21-
distance: 150,
22-
duration: 0.5,
15+
fpsLimit: isPowerfulDevice ? 60 : 30,
16+
interactivity: {
17+
detectsOn: "canvas",
18+
events: {
19+
onHover: {
20+
enable: isDesktop,
21+
mode: "repulse",
22+
},
23+
},
24+
modes: {
25+
repulse: {
26+
distance: isMobile ? 100 : 150,
27+
duration: 0.5,
28+
},
2329
},
2430
},
25-
},
26-
particles: {
27-
color: {
28-
value: textAbovePrimaryColor,
29-
},
30-
links: {
31-
enable: true,
32-
color: textAbovePrimaryColor,
33-
blink: true,
34-
distance: 150,
35-
opacity: 0.5,
36-
width: 1,
37-
},
38-
collisions: {
39-
enable: false,
40-
mode: "bounce",
41-
},
42-
move: {
43-
direction: "none",
44-
enable: true,
45-
outMode: "bounce",
46-
random: false,
47-
speed: 3,
48-
straight: false,
49-
},
50-
number: {
51-
density: {
31+
particles: {
32+
color: {
33+
value: textAbovePrimaryColor,
34+
},
35+
links: {
5236
enable: true,
53-
value_area: 800,
37+
color: textAbovePrimaryColor,
38+
blink: true,
39+
distance: isMobile ? 100 : 150,
40+
opacity: 0.5,
41+
width: 1,
42+
},
43+
collisions: {
44+
enable: false,
45+
mode: "bounce",
46+
},
47+
move: {
48+
direction: "none",
49+
enable: true,
50+
outMode: "bounce",
51+
random: false,
52+
speed: 3,
53+
straight: false,
54+
},
55+
number: {
56+
density: {
57+
enable: true,
58+
value_area: 800,
59+
},
60+
value: 80,
61+
},
62+
opacity: {
63+
value: 0.5,
64+
},
65+
shape: {
66+
type: "circle",
67+
},
68+
size: {
69+
random: true,
70+
value: 3,
5471
},
55-
value: 80,
56-
},
57-
opacity: {
58-
value: 0.5,
59-
},
60-
shape: {
61-
type: "circle",
62-
},
63-
size: {
64-
random: true,
65-
value: 3,
6672
},
67-
},
68-
detectRetina: true,
69-
});
73+
detectRetina: true,
74+
};
75+
};

src/posts/2017-08-25-how-to-calculate-reflection-vector.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
---
32
title: "How to calculate the reflection vector"
43
description: "In this post I will talk about reflection vector used in some lighting models, for example the Phong

0 commit comments

Comments
 (0)