react-native-snow-backgroud 0.1.3 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/module/snow/SnowEngine.js +3 -3
- package/lib/module/snow/SnowEngine.js.map +1 -1
- package/lib/module/snow/SnowView.js +3 -1
- package/lib/module/snow/SnowView.js.map +1 -1
- package/lib/typescript/src/snow/SnowEngine.d.ts.map +1 -1
- package/lib/typescript/src/snow/SnowView.d.ts +2 -4
- package/lib/typescript/src/snow/SnowView.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/snow/SnowEngine.ts +4 -4
- package/src/snow/SnowView.tsx +8 -7
|
@@ -10,15 +10,15 @@ export class SnowEngine {
|
|
|
10
10
|
}).map(() => ({
|
|
11
11
|
x: Math.random() * width,
|
|
12
12
|
y: Math.random() * height,
|
|
13
|
-
speed: Math.random() *
|
|
13
|
+
speed: Math.random() * 2 + 1,
|
|
14
14
|
size: Math.random() * 2 + 1
|
|
15
15
|
}));
|
|
16
16
|
}
|
|
17
17
|
update() {
|
|
18
18
|
for (const p of this.particles) {
|
|
19
|
-
p.y += p.speed;
|
|
19
|
+
p.y += p.speed * 2;
|
|
20
20
|
if (p.y > this.height) {
|
|
21
|
-
p.y =
|
|
21
|
+
p.y = -10;
|
|
22
22
|
p.x = Math.random() * this.width;
|
|
23
23
|
}
|
|
24
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["SnowEngine","particles","constructor","count","width","height","Array","from","length","map","x","Math","random","y","speed","size","update","p"],"sourceRoot":"../../../src","sources":["snow/SnowEngine.ts"],"mappings":";;
|
|
1
|
+
{"version":3,"names":["SnowEngine","particles","constructor","count","width","height","Array","from","length","map","x","Math","random","y","speed","size","update","p"],"sourceRoot":"../../../src","sources":["snow/SnowEngine.ts"],"mappings":";;AAME,OAAO,MAAMA,UAAU,CAAC;EACtBC,SAAS,GAAmB,EAAE;EAE9BC,WAAWA,CACTC,KAAa,EACLC,KAAa,EACbC,MAAc,EACtB;IAAA,KAFQD,KAAa,GAAbA,KAAa;IAAA,KACbC,MAAc,GAAdA,MAAc;IAEtB,IAAI,CAACJ,SAAS,GAAGK,KAAK,CAACC,IAAI,CAAC;MAAEC,MAAM,EAAEL;IAAM,CAAC,CAAC,CAACM,GAAG,CAAC,OAAO;MACxDC,CAAC,EAAEC,IAAI,CAACC,MAAM,CAAC,CAAC,GAAGR,KAAK;MACxBS,CAAC,EAAEF,IAAI,CAACC,MAAM,CAAC,CAAC,GAAGP,MAAM;MACzBS,KAAK,EAAEH,IAAI,CAACC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC;MAC5BG,IAAI,EAAEJ,IAAI,CAACC,MAAM,CAAC,CAAC,GAAG,CAAC,GAAG;IAC5B,CAAC,CAAC,CAAC;EACL;EAEAI,MAAMA,CAAA,EAAG;IACP,KAAK,MAAMC,CAAC,IAAI,IAAI,CAAChB,SAAS,EAAE;MAC9BgB,CAAC,CAACJ,CAAC,IAAII,CAAC,CAACH,KAAK,GAAG,CAAC;MAElB,IAAIG,CAAC,CAACJ,CAAC,GAAG,IAAI,CAACR,MAAM,EAAE;QACrBY,CAAC,CAACJ,CAAC,GAAG,CAAC,EAAE;QACTI,CAAC,CAACP,CAAC,GAAGC,IAAI,CAACC,MAAM,CAAC,CAAC,GAAG,IAAI,CAACR,KAAK;MAClC;IACF;EACF;AACF","ignoreList":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
import { useEffect, useRef } from "react";
|
|
3
|
+
import { useEffect, useRef, useState } from "react";
|
|
4
4
|
import { Dimensions, View, StyleSheet } from "react-native";
|
|
5
5
|
import { Canvas, Circle } from "@shopify/react-native-skia";
|
|
6
6
|
import { SnowEngine } from "./SnowEngine.js";
|
|
@@ -14,6 +14,7 @@ export function SnowView({
|
|
|
14
14
|
height
|
|
15
15
|
} = Dimensions.get("window");
|
|
16
16
|
const engineRef = useRef(null);
|
|
17
|
+
const [, forceRender] = useState(0);
|
|
17
18
|
if (!engineRef.current) {
|
|
18
19
|
engineRef.current = new SnowEngine(count, width, height);
|
|
19
20
|
}
|
|
@@ -21,6 +22,7 @@ export function SnowView({
|
|
|
21
22
|
let raf;
|
|
22
23
|
const loop = () => {
|
|
23
24
|
engineRef.current?.update();
|
|
25
|
+
forceRender(v => v + 1);
|
|
24
26
|
raf = requestAnimationFrame(loop);
|
|
25
27
|
};
|
|
26
28
|
loop();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","useRef","Dimensions","View","StyleSheet","Canvas","Circle","SnowEngine","jsx","_jsx","jsxs","_jsxs","SnowView","count","children","width","height","get","engineRef","current","raf","loop","update","requestAnimationFrame","cancelAnimationFrame","snow","style","flex","absoluteFill","zIndex","pointerEvents","particles","map","p","i","cx","x","cy","y","r","size","color"],"sourceRoot":"../../../src","sources":["snow/SnowView.tsx"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,MAAM,QAAQ,OAAO;
|
|
1
|
+
{"version":3,"names":["useEffect","useRef","useState","Dimensions","View","StyleSheet","Canvas","Circle","SnowEngine","jsx","_jsx","jsxs","_jsxs","SnowView","count","children","width","height","get","engineRef","forceRender","current","raf","loop","update","v","requestAnimationFrame","cancelAnimationFrame","snow","style","flex","absoluteFill","zIndex","pointerEvents","particles","map","p","i","cx","x","cy","y","r","size","color"],"sourceRoot":"../../../src","sources":["snow/SnowView.tsx"],"mappings":";;AAAA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEnD,SAASC,UAAU,EAAEC,IAAI,EAAEC,UAAU,QAAQ,cAAc;AAC3D,SAASC,MAAM,EAAEC,MAAM,QAAQ,4BAA4B;AAC3D,SAASC,UAAU,QAAQ,iBAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAE1C,OAAO,SAASC,QAAQA,CAAC;EAAEC,KAAK,GAAG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AEN,CAAC,CAACO,IAAK;QAACC,KAAK,EAAC;MAAO,GAA7CP,CAA+C,CAC7D;IAAC,CACI,CAAC;EAAA,CACL,CAAC;AAEX","ignoreList":[]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnowEngine.d.ts","sourceRoot":"","sources":["../../../../src/snow/SnowEngine.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACvB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;
|
|
1
|
+
{"version":3,"file":"SnowEngine.d.ts","sourceRoot":"","sources":["../../../../src/snow/SnowEngine.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,YAAY,GAAG;IACvB,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AACF,qBAAa,UAAU;IAKnB,OAAO,CAAC,KAAK;IACb,OAAO,CAAC,MAAM;IALhB,SAAS,EAAE,YAAY,EAAE,CAAM;gBAG7B,KAAK,EAAE,MAAM,EACL,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,MAAM;IAUxB,MAAM;CAUP"}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
|
|
2
|
+
export declare function SnowView({ count, children }: {
|
|
3
3
|
count?: number;
|
|
4
4
|
children?: ReactNode;
|
|
5
|
-
};
|
|
6
|
-
export declare function SnowView({ count, children }: SnowViewProps): import("react/jsx-runtime").JSX.Element;
|
|
7
|
-
export {};
|
|
5
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
8
6
|
//# sourceMappingURL=SnowView.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SnowView.d.ts","sourceRoot":"","sources":["../../../../src/snow/SnowView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"SnowView.d.ts","sourceRoot":"","sources":["../../../../src/snow/SnowView.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAKvC,wBAAgB,QAAQ,CAAC,EAAE,KAAW,EAAE,QAAQ,EAAE,EAAE;IAClD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB,2CAqCA"}
|
package/package.json
CHANGED
package/src/snow/SnowEngine.ts
CHANGED
|
@@ -4,7 +4,6 @@ export type SnowParticle = {
|
|
|
4
4
|
speed: number;
|
|
5
5
|
size: number;
|
|
6
6
|
};
|
|
7
|
-
|
|
8
7
|
export class SnowEngine {
|
|
9
8
|
particles: SnowParticle[] = [];
|
|
10
9
|
|
|
@@ -16,16 +15,17 @@ export type SnowParticle = {
|
|
|
16
15
|
this.particles = Array.from({ length: count }).map(() => ({
|
|
17
16
|
x: Math.random() * width,
|
|
18
17
|
y: Math.random() * height,
|
|
19
|
-
speed: Math.random() *
|
|
18
|
+
speed: Math.random() * 2 + 1,
|
|
20
19
|
size: Math.random() * 2 + 1,
|
|
21
20
|
}));
|
|
22
21
|
}
|
|
23
22
|
|
|
24
23
|
update() {
|
|
25
24
|
for (const p of this.particles) {
|
|
26
|
-
p.y += p.speed;
|
|
25
|
+
p.y += p.speed * 2;
|
|
26
|
+
|
|
27
27
|
if (p.y > this.height) {
|
|
28
|
-
p.y =
|
|
28
|
+
p.y = -10;
|
|
29
29
|
p.x = Math.random() * this.width;
|
|
30
30
|
}
|
|
31
31
|
}
|
package/src/snow/SnowView.tsx
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import { useEffect, useRef } from "react";
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
2
|
import type { ReactNode } from "react";
|
|
3
|
-
type SnowViewProps = {
|
|
4
|
-
count?: number;
|
|
5
|
-
children?: ReactNode;
|
|
6
|
-
};
|
|
7
3
|
import { Dimensions, View, StyleSheet } from "react-native";
|
|
8
4
|
import { Canvas, Circle } from "@shopify/react-native-skia";
|
|
9
5
|
import { SnowEngine } from "./SnowEngine";
|
|
10
|
-
export function SnowView({ count = 100, children }: SnowViewProps) {
|
|
11
6
|
|
|
7
|
+
export function SnowView({ count = 100, children }: {
|
|
8
|
+
count?: number;
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
}) {
|
|
12
11
|
const { width, height } = Dimensions.get("window");
|
|
13
12
|
const engineRef = useRef<SnowEngine | null>(null);
|
|
13
|
+
const [, forceRender] = useState(0);
|
|
14
14
|
|
|
15
15
|
if (!engineRef.current) {
|
|
16
16
|
engineRef.current = new SnowEngine(count, width, height);
|
|
@@ -20,6 +20,7 @@ export function SnowView({ count = 100, children }: SnowViewProps) {
|
|
|
20
20
|
let raf: number;
|
|
21
21
|
const loop = () => {
|
|
22
22
|
engineRef.current?.update();
|
|
23
|
+
forceRender(v => v + 1);
|
|
23
24
|
raf = requestAnimationFrame(loop);
|
|
24
25
|
};
|
|
25
26
|
loop();
|
|
@@ -42,5 +43,5 @@ export function SnowView({ count = 100, children }: SnowViewProps) {
|
|
|
42
43
|
))}
|
|
43
44
|
</Canvas>
|
|
44
45
|
</View>
|
|
45
|
-
);
|
|
46
|
+
);
|
|
46
47
|
}
|