react-native-snow-backgroud 0.1.0
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/LICENSE +20 -0
- package/README.md +37 -0
- package/lib/module/index.js +4 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/snow/SnowEngine.js +27 -0
- package/lib/module/snow/SnowEngine.js.map +1 -0
- package/lib/module/snow/SnowView.js +41 -0
- package/lib/module/snow/SnowView.js.map +1 -0
- package/lib/typescript/package/src/index.d.ts +2 -0
- package/lib/typescript/package/src/index.d.ts.map +1 -0
- package/lib/typescript/package/src/snow/SnowEngine.d.ts +14 -0
- package/lib/typescript/package/src/snow/SnowEngine.d.ts.map +1 -0
- package/lib/typescript/package/src/snow/SnowView.d.ts +4 -0
- package/lib/typescript/package/src/snow/SnowView.d.ts.map +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/index.d.ts +2 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/lib/typescript/src/snow/SnowEngine.d.ts +14 -0
- package/lib/typescript/src/snow/SnowEngine.d.ts.map +1 -0
- package/lib/typescript/src/snow/SnowView.d.ts +4 -0
- package/lib/typescript/src/snow/SnowView.d.ts.map +1 -0
- package/package.json +130 -0
- package/src/index.ts +1 -0
- package/src/snow/SnowEngine.ts +34 -0
- package/src/snow/SnowView.tsx +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 jonadan
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in all
|
|
12
|
+
copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
20
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# react-native-snow-backgroud
|
|
2
|
+
|
|
3
|
+
A simple snow background effect for React Native CLI using Skia.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
```sh
|
|
9
|
+
npm install react-native-snow-backgroud
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
```js
|
|
17
|
+
import { multiply } from 'react-native-snow-backgroud';
|
|
18
|
+
|
|
19
|
+
// ...
|
|
20
|
+
|
|
21
|
+
const result = await multiply(3, 7);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
## Contributing
|
|
26
|
+
|
|
27
|
+
- [Development workflow](CONTRIBUTING.md#development-workflow)
|
|
28
|
+
- [Sending a pull request](CONTRIBUTING.md#sending-a-pull-request)
|
|
29
|
+
- [Code of conduct](CODE_OF_CONDUCT.md)
|
|
30
|
+
|
|
31
|
+
## License
|
|
32
|
+
|
|
33
|
+
MIT
|
|
34
|
+
|
|
35
|
+
---
|
|
36
|
+
|
|
37
|
+
Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["SnowView"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;AAAA,SAASA,QAAQ,QAAQ,oBAAiB","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
export class SnowEngine {
|
|
4
|
+
particles = [];
|
|
5
|
+
constructor(count, width, height) {
|
|
6
|
+
this.width = width;
|
|
7
|
+
this.height = height;
|
|
8
|
+
this.particles = Array.from({
|
|
9
|
+
length: count
|
|
10
|
+
}).map(() => ({
|
|
11
|
+
x: Math.random() * width,
|
|
12
|
+
y: Math.random() * height,
|
|
13
|
+
speed: Math.random() * 1.5 + 0.5,
|
|
14
|
+
size: Math.random() * 2 + 1
|
|
15
|
+
}));
|
|
16
|
+
}
|
|
17
|
+
update() {
|
|
18
|
+
for (const p of this.particles) {
|
|
19
|
+
p.y += p.speed;
|
|
20
|
+
if (p.y > this.height) {
|
|
21
|
+
p.y = 0;
|
|
22
|
+
p.x = Math.random() * this.width;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=SnowEngine.js.map
|
|
@@ -0,0 +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":";;AAOE,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,GAAG,GAAG,GAAG;MAChCG,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;MACd,IAAIG,CAAC,CAACJ,CAAC,GAAG,IAAI,CAACR,MAAM,EAAE;QACrBY,CAAC,CAACJ,CAAC,GAAG,CAAC;QACPI,CAAC,CAACP,CAAC,GAAGC,IAAI,CAACC,MAAM,CAAC,CAAC,GAAG,IAAI,CAACR,KAAK;MAClC;IACF;EACF;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
import { useEffect, useRef } from "react";
|
|
4
|
+
import { Dimensions } from "react-native";
|
|
5
|
+
import { Canvas, Circle } from "@shopify/react-native-skia";
|
|
6
|
+
import { SnowEngine } from "./SnowEngine.js";
|
|
7
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
+
export function SnowView({
|
|
9
|
+
count = 100
|
|
10
|
+
}) {
|
|
11
|
+
const {
|
|
12
|
+
width,
|
|
13
|
+
height
|
|
14
|
+
} = Dimensions.get("window");
|
|
15
|
+
const engineRef = useRef(null);
|
|
16
|
+
if (!engineRef.current) {
|
|
17
|
+
engineRef.current = new SnowEngine(count, width, height);
|
|
18
|
+
}
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
let raf;
|
|
21
|
+
const loop = () => {
|
|
22
|
+
engineRef.current?.update();
|
|
23
|
+
raf = requestAnimationFrame(loop);
|
|
24
|
+
};
|
|
25
|
+
loop();
|
|
26
|
+
return () => cancelAnimationFrame(raf);
|
|
27
|
+
}, []);
|
|
28
|
+
const snow = engineRef.current;
|
|
29
|
+
return /*#__PURE__*/_jsx(Canvas, {
|
|
30
|
+
style: {
|
|
31
|
+
flex: 1
|
|
32
|
+
},
|
|
33
|
+
children: snow?.particles.map((p, i) => /*#__PURE__*/_jsx(Circle, {
|
|
34
|
+
cx: p.x,
|
|
35
|
+
cy: p.y,
|
|
36
|
+
r: p.size,
|
|
37
|
+
color: "white"
|
|
38
|
+
}, i))
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=SnowView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","useRef","Dimensions","Canvas","Circle","SnowEngine","jsx","_jsx","SnowView","count","width","height","get","engineRef","current","raf","loop","update","requestAnimationFrame","cancelAnimationFrame","snow","style","flex","children","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;AACzC,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,MAAM,EAAEC,MAAM,QAAQ,4BAA4B;AAC3D,SAASC,UAAU,QAAQ,iBAAc;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAE1C,OAAO,SAASC,QAAQA,CAAC;EAAEC,KAAK,GAAG;AAAwB,CAAC,EAAE;EAC5D,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGT,UAAU,CAACU,GAAG,CAAC,QAAQ,CAAC;EAClD,MAAMC,SAAS,GAAGZ,MAAM,CAAoB,IAAI,CAAC;EAEjD,IAAI,CAACY,SAAS,CAACC,OAAO,EAAE;IACtBD,SAAS,CAACC,OAAO,GAAG,IAAIT,UAAU,CAACI,KAAK,EAAEC,KAAK,EAAEC,MAAM,CAAC;EAC1D;EAEAX,SAAS,CAAC,MAAM;IACd,IAAIe,GAAW;IACf,MAAMC,IAAI,GAAGA,CAAA,KAAM;MACjBH,SAAS,CAACC,OAAO,EAAEG,MAAM,CAAC,CAAC;MAC3BF,GAAG,GAAGG,qBAAqB,CAACF,IAAI,CAAC;IACnC,CAAC;IACDA,IAAI,CAAC,CAAC;IACN,OAAO,MAAMG,oBAAoB,CAACJ,GAAG,CAAC;EACxC,CAAC,EAAE,EAAE,CAAC;EAEN,MAAMK,IAAI,GAAGP,SAAS,CAACC,OAAO;EAE9B,oBACEP,IAAA,CAACJ,MAAM;IAACkB,KAAK,EAAE;MAAEC,IAAI,EAAE;IAAE,CAAE;IAAAC,QAAA,EACxBH,IAAI,EAAEI,SAAS,CAACC,GAAG,CAAC,CAACC,CAAC,EAAEC,CAAC,kBACxBpB,IAAA,CAACH,MAAM;MAASwB,EAAE,EAAEF,CAAC,CAACG,CAAE;MAACC,EAAE,EAAEJ,CAAC,CAACK,CAAE;MAACC,CAAC,EAAEN,CAAC,CAACO,IAAK;MAACC,KAAK,EAAC;IAAO,GAA7CP,CAA+C,CAC7D;EAAC,CACI,CAAC;AAEb","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../package/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type SnowParticle = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
speed: number;
|
|
5
|
+
size: number;
|
|
6
|
+
};
|
|
7
|
+
export declare class SnowEngine {
|
|
8
|
+
private width;
|
|
9
|
+
private height;
|
|
10
|
+
particles: SnowParticle[];
|
|
11
|
+
constructor(count: number, width: number, height: number);
|
|
12
|
+
update(): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=SnowEngine.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnowEngine.d.ts","sourceRoot":"","sources":["../../../../../package/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;AAEF,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;CASP"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnowView.d.ts","sourceRoot":"","sources":["../../../../../package/src/snow/SnowView.tsx"],"names":[],"mappings":"AAKA,wBAAgB,QAAQ,CAAC,EAAE,KAAW,EAAE,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,2CA2B3D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type SnowParticle = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
speed: number;
|
|
5
|
+
size: number;
|
|
6
|
+
};
|
|
7
|
+
export declare class SnowEngine {
|
|
8
|
+
private width;
|
|
9
|
+
private height;
|
|
10
|
+
particles: SnowParticle[];
|
|
11
|
+
constructor(count: number, width: number, height: number);
|
|
12
|
+
update(): void;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=SnowEngine.d.ts.map
|
|
@@ -0,0 +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;AAEF,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;CASP"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SnowView.d.ts","sourceRoot":"","sources":["../../../../src/snow/SnowView.tsx"],"names":[],"mappings":"AAKA,wBAAgB,QAAQ,CAAC,EAAE,KAAW,EAAE,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,2CA2B3D"}
|
package/package.json
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-snow-backgroud",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A simple snow background effect for React Native CLI using Skia.",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"*.podspec",
|
|
22
|
+
"react-native.config.js",
|
|
23
|
+
"!ios/build",
|
|
24
|
+
"!android/build",
|
|
25
|
+
"!android/gradle",
|
|
26
|
+
"!android/gradlew",
|
|
27
|
+
"!android/gradlew.bat",
|
|
28
|
+
"!android/local.properties",
|
|
29
|
+
"!**/__tests__",
|
|
30
|
+
"!**/__fixtures__",
|
|
31
|
+
"!**/__mocks__",
|
|
32
|
+
"!**/.*"
|
|
33
|
+
],
|
|
34
|
+
"scripts": {
|
|
35
|
+
"example": "yarn workspace react-native-snow-backgroud-example",
|
|
36
|
+
"clean": "del-cli lib",
|
|
37
|
+
"build": "bob build",
|
|
38
|
+
"prepare": "bob build",
|
|
39
|
+
"typecheck": "tsc",
|
|
40
|
+
"test": "jest",
|
|
41
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\""
|
|
42
|
+
},
|
|
43
|
+
"keywords": [
|
|
44
|
+
"react-native",
|
|
45
|
+
"ios",
|
|
46
|
+
"android"
|
|
47
|
+
],
|
|
48
|
+
"repository": {
|
|
49
|
+
"type": "git",
|
|
50
|
+
"url": "git+https://github.com/gwxodn020/react-native-snow-backgroud.git"
|
|
51
|
+
},
|
|
52
|
+
"author": "jonadan <chunsig435@gmail.com> (https://github.com/gwxodn020)",
|
|
53
|
+
"license": "MIT",
|
|
54
|
+
"bugs": {
|
|
55
|
+
"url": "https://github.com/gwxodn020/react-native-snow-backgroud/issues"
|
|
56
|
+
},
|
|
57
|
+
"homepage": "https://github.com/gwxodn020/react-native-snow-backgroud#readme",
|
|
58
|
+
"publishConfig": {
|
|
59
|
+
"registry": "https://registry.npmjs.org/"
|
|
60
|
+
},
|
|
61
|
+
"devDependencies": {
|
|
62
|
+
"@eslint/compat": "^1.3.2",
|
|
63
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
64
|
+
"@eslint/js": "^9.35.0",
|
|
65
|
+
"@react-native/babel-preset": "0.83.0",
|
|
66
|
+
"@react-native/eslint-config": "0.83.0",
|
|
67
|
+
"@shopify/react-native-skia": "^2.4.14",
|
|
68
|
+
"@types/jest": "^29.5.14",
|
|
69
|
+
"@types/react": "^19.1.12",
|
|
70
|
+
"del-cli": "^6.0.0",
|
|
71
|
+
"eslint": "^9.35.0",
|
|
72
|
+
"eslint-config-prettier": "^10.1.8",
|
|
73
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
74
|
+
"jest": "^29.7.0",
|
|
75
|
+
"prettier": "^3.7.4",
|
|
76
|
+
"react": "19.1.0",
|
|
77
|
+
"react-native": "0.81.5",
|
|
78
|
+
"react-native-builder-bob": "^0.40.17",
|
|
79
|
+
"typescript": "^5.9.2"
|
|
80
|
+
},
|
|
81
|
+
"peerDependencies": {
|
|
82
|
+
"react": "*",
|
|
83
|
+
"react-native": "*"
|
|
84
|
+
},
|
|
85
|
+
"workspaces": [
|
|
86
|
+
"example"
|
|
87
|
+
],
|
|
88
|
+
"packageManager": "yarn@4.11.0",
|
|
89
|
+
"react-native-builder-bob": {
|
|
90
|
+
"source": "src",
|
|
91
|
+
"output": "lib",
|
|
92
|
+
"targets": [
|
|
93
|
+
[
|
|
94
|
+
"module",
|
|
95
|
+
{
|
|
96
|
+
"esm": true
|
|
97
|
+
}
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
"typescript",
|
|
101
|
+
{
|
|
102
|
+
"project": "tsconfig.build.json"
|
|
103
|
+
}
|
|
104
|
+
]
|
|
105
|
+
]
|
|
106
|
+
},
|
|
107
|
+
"jest": {
|
|
108
|
+
"preset": "react-native",
|
|
109
|
+
"modulePathIgnorePatterns": [
|
|
110
|
+
"<rootDir>/example/node_modules",
|
|
111
|
+
"<rootDir>/lib/"
|
|
112
|
+
]
|
|
113
|
+
},
|
|
114
|
+
"prettier": {
|
|
115
|
+
"quoteProps": "consistent",
|
|
116
|
+
"singleQuote": true,
|
|
117
|
+
"tabWidth": 2,
|
|
118
|
+
"trailingComma": "es5",
|
|
119
|
+
"useTabs": false
|
|
120
|
+
},
|
|
121
|
+
"create-react-native-library": {
|
|
122
|
+
"type": "library",
|
|
123
|
+
"languages": "js",
|
|
124
|
+
"tools": [
|
|
125
|
+
"jest",
|
|
126
|
+
"eslint"
|
|
127
|
+
],
|
|
128
|
+
"version": "0.56.1"
|
|
129
|
+
}
|
|
130
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { SnowView } from "./snow/SnowView";
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export type SnowParticle = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
speed: number;
|
|
5
|
+
size: number;
|
|
6
|
+
};
|
|
7
|
+
|
|
8
|
+
export class SnowEngine {
|
|
9
|
+
particles: SnowParticle[] = [];
|
|
10
|
+
|
|
11
|
+
constructor(
|
|
12
|
+
count: number,
|
|
13
|
+
private width: number,
|
|
14
|
+
private height: number,
|
|
15
|
+
) {
|
|
16
|
+
this.particles = Array.from({ length: count }).map(() => ({
|
|
17
|
+
x: Math.random() * width,
|
|
18
|
+
y: Math.random() * height,
|
|
19
|
+
speed: Math.random() * 1.5 + 0.5,
|
|
20
|
+
size: Math.random() * 2 + 1,
|
|
21
|
+
}));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
update() {
|
|
25
|
+
for (const p of this.particles) {
|
|
26
|
+
p.y += p.speed;
|
|
27
|
+
if (p.y > this.height) {
|
|
28
|
+
p.y = 0;
|
|
29
|
+
p.x = Math.random() * this.width;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useEffect, useRef } from "react";
|
|
2
|
+
import { Dimensions } from "react-native";
|
|
3
|
+
import { Canvas, Circle } from "@shopify/react-native-skia";
|
|
4
|
+
import { SnowEngine } from "./SnowEngine";
|
|
5
|
+
|
|
6
|
+
export function SnowView({ count = 100 }: { count?: number }) {
|
|
7
|
+
const { width, height } = Dimensions.get("window");
|
|
8
|
+
const engineRef = useRef<SnowEngine | null>(null);
|
|
9
|
+
|
|
10
|
+
if (!engineRef.current) {
|
|
11
|
+
engineRef.current = new SnowEngine(count, width, height);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
let raf: number;
|
|
16
|
+
const loop = () => {
|
|
17
|
+
engineRef.current?.update();
|
|
18
|
+
raf = requestAnimationFrame(loop);
|
|
19
|
+
};
|
|
20
|
+
loop();
|
|
21
|
+
return () => cancelAnimationFrame(raf);
|
|
22
|
+
}, []);
|
|
23
|
+
|
|
24
|
+
const snow = engineRef.current;
|
|
25
|
+
|
|
26
|
+
return (
|
|
27
|
+
<Canvas style={{ flex: 1 }}>
|
|
28
|
+
{snow?.particles.map((p, i) => (
|
|
29
|
+
<Circle key={i} cx={p.x} cy={p.y} r={p.size} color="white" />
|
|
30
|
+
))}
|
|
31
|
+
</Canvas>
|
|
32
|
+
);
|
|
33
|
+
}
|