react-native-effects 0.1.0 → 0.2.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/README.md +75 -13
- package/lib/module/components/ShaderView/index.js +33 -5
- package/lib/module/components/ShaderView/index.js.map +1 -1
- package/lib/module/components/ShaderViewWithPanGesture/index.js +196 -0
- package/lib/module/components/ShaderViewWithPanGesture/index.js.map +1 -0
- package/lib/module/hooks/useParamsSynchronizable.js +37 -0
- package/lib/module/hooks/useParamsSynchronizable.js.map +1 -0
- package/lib/module/hooks/useWGPUSetup.js +1 -1
- package/lib/module/hooks/useWGPUSetup.js.map +1 -1
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/shaders/uniforms.js +4 -3
- package/lib/module/shaders/uniforms.js.map +1 -1
- package/lib/typescript/src/components/Aurora.d.ts +1 -1
- package/lib/typescript/src/components/Aurora.d.ts.map +1 -1
- package/lib/typescript/src/components/CalicoSwirl.d.ts +1 -1
- package/lib/typescript/src/components/CalicoSwirl.d.ts.map +1 -1
- package/lib/typescript/src/components/Campfire.d.ts +1 -1
- package/lib/typescript/src/components/Campfire.d.ts.map +1 -1
- package/lib/typescript/src/components/CircularGradient.d.ts +1 -1
- package/lib/typescript/src/components/CircularGradient.d.ts.map +1 -1
- package/lib/typescript/src/components/Iridescence.d.ts +1 -1
- package/lib/typescript/src/components/Iridescence.d.ts.map +1 -1
- package/lib/typescript/src/components/LinearGradient.d.ts +1 -1
- package/lib/typescript/src/components/LinearGradient.d.ts.map +1 -1
- package/lib/typescript/src/components/LiquidChrome.d.ts +1 -1
- package/lib/typescript/src/components/LiquidChrome.d.ts.map +1 -1
- package/lib/typescript/src/components/ShaderView/index.d.ts +1 -1
- package/lib/typescript/src/components/ShaderView/index.d.ts.map +1 -1
- package/lib/typescript/src/components/ShaderView/types.d.ts +20 -0
- package/lib/typescript/src/components/ShaderView/types.d.ts.map +1 -1
- package/lib/typescript/src/components/ShaderViewWithPanGesture/index.d.ts +35 -0
- package/lib/typescript/src/components/ShaderViewWithPanGesture/index.d.ts.map +1 -0
- package/lib/typescript/src/components/Silk.d.ts +1 -1
- package/lib/typescript/src/components/Silk.d.ts.map +1 -1
- package/lib/typescript/src/hooks/useParamsSynchronizable.d.ts +22 -0
- package/lib/typescript/src/hooks/useParamsSynchronizable.d.ts.map +1 -0
- package/lib/typescript/src/hooks/useWGPUSetup.d.ts +1 -1
- package/lib/typescript/src/hooks/useWGPUSetup.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +6 -2
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/shaders/uniforms.d.ts +3 -3
- package/lib/typescript/src/shaders/uniforms.d.ts.map +1 -1
- package/package.json +31 -30
- package/src/components/ShaderView/index.tsx +42 -5
- package/src/components/ShaderView/types.ts +21 -0
- package/src/components/ShaderViewWithPanGesture/index.tsx +225 -0
- package/src/hooks/useParamsSynchronizable.ts +52 -0
- package/src/hooks/useWGPUSetup.tsx +1 -1
- package/src/index.tsx +10 -1
- package/src/shaders/uniforms.ts +4 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CalicoSwirl.d.ts","sourceRoot":"","sources":["../../../../src/components/CalicoSwirl.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,KAAK,GAAG,SAAS,GAAG;IACvB,kDAAkD;IAClD,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,KAAiB,EACjB,KAAW,EACX,SAAe,EACf,GAAG,SAAS,EACb,EAAE,KAAK
|
|
1
|
+
{"version":3,"file":"CalicoSwirl.d.ts","sourceRoot":"","sources":["../../../../src/components/CalicoSwirl.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,KAAK,GAAG,SAAS,GAAG;IACvB,kDAAkD;IAClD,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,KAAiB,EACjB,KAAW,EACX,SAAe,EACf,GAAG,SAAS,EACb,EAAE,KAAK,+BAcP"}
|
|
@@ -12,6 +12,6 @@ type Props = ViewProps & {
|
|
|
12
12
|
/** Intensity of the smoke. Default: 1.0 */
|
|
13
13
|
smokeIntensity?: number;
|
|
14
14
|
};
|
|
15
|
-
export default function Campfire({ color, speed, sparkSize, fireIntensity, smokeIntensity, ...viewProps }: Props): import("react
|
|
15
|
+
export default function Campfire({ color, speed, sparkSize, fireIntensity, smokeIntensity, ...viewProps }: Props): import("react").JSX.Element;
|
|
16
16
|
export {};
|
|
17
17
|
//# sourceMappingURL=Campfire.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Campfire.d.ts","sourceRoot":"","sources":["../../../../src/components/Campfire.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,KAAK,GAAG,SAAS,GAAG;IACvB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAC/B,KAAiB,EACjB,KAAW,EACX,SAAe,EACf,aAAmB,EACnB,cAAoB,EACpB,GAAG,SAAS,EACb,EAAE,KAAK
|
|
1
|
+
{"version":3,"file":"Campfire.d.ts","sourceRoot":"","sources":["../../../../src/components/Campfire.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,KAAK,GAAG,SAAS,GAAG;IACvB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,uCAAuC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,0CAA0C;IAC1C,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,2CAA2C;IAC3C,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,EAC/B,KAAiB,EACjB,KAAW,EACX,SAAe,EACf,aAAmB,EACnB,cAAoB,EACpB,GAAG,SAAS,EACb,EAAE,KAAK,+BAiBP"}
|
|
@@ -14,6 +14,6 @@ type Props = ViewProps & {
|
|
|
14
14
|
/** Vertical radius. Default: 0.5 */
|
|
15
15
|
sizeY?: number;
|
|
16
16
|
};
|
|
17
|
-
export default function CircularGradient({ centerColor, edgeColor, centerX, centerY, sizeX, sizeY, ...viewProps }: Props): import("react
|
|
17
|
+
export default function CircularGradient({ centerColor, edgeColor, centerX, centerY, sizeX, sizeY, ...viewProps }: Props): import("react").JSX.Element;
|
|
18
18
|
export {};
|
|
19
19
|
//# sourceMappingURL=CircularGradient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CircularGradient.d.ts","sourceRoot":"","sources":["../../../../src/components/CircularGradient.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,KAAK,GAAG,SAAS,GAAG;IACvB,+CAA+C;IAC/C,WAAW,EAAE,UAAU,CAAC;IACxB,kEAAkE;IAClE,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EACvC,WAAW,EACX,SAA2B,EAC3B,OAAa,EACb,OAAa,EACb,KAAW,EACX,KAAW,EACX,GAAG,SAAS,EACb,EAAE,KAAK
|
|
1
|
+
{"version":3,"file":"CircularGradient.d.ts","sourceRoot":"","sources":["../../../../src/components/CircularGradient.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,KAAK,GAAG,SAAS,GAAG;IACvB,+CAA+C;IAC/C,WAAW,EAAE,UAAU,CAAC;IACxB,kEAAkE;IAClE,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,qDAAqD;IACrD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,mDAAmD;IACnD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sCAAsC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,gBAAgB,CAAC,EACvC,WAAW,EACX,SAA2B,EAC3B,OAAa,EACb,OAAa,EACb,KAAW,EACX,KAAW,EACX,GAAG,SAAS,EACb,EAAE,KAAK,+BAmBP"}
|
|
@@ -6,6 +6,6 @@ type Props = ViewProps & {
|
|
|
6
6
|
/** Animation speed multiplier. Default: 1.0 */
|
|
7
7
|
speed?: number;
|
|
8
8
|
};
|
|
9
|
-
export default function Iridescence({ color, speed, ...viewProps }: Props): import("react
|
|
9
|
+
export default function Iridescence({ color, speed, ...viewProps }: Props): import("react").JSX.Element;
|
|
10
10
|
export {};
|
|
11
11
|
//# sourceMappingURL=Iridescence.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Iridescence.d.ts","sourceRoot":"","sources":["../../../../src/components/Iridescence.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,KAAK,GAAG,SAAS,GAAG;IACvB,iDAAiD;IACjD,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,KAAiB,EACjB,KAAW,EACX,GAAG,SAAS,EACb,EAAE,KAAK
|
|
1
|
+
{"version":3,"file":"Iridescence.d.ts","sourceRoot":"","sources":["../../../../src/components/Iridescence.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,KAAK,GAAG,SAAS,GAAG;IACvB,iDAAiD;IACjD,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,WAAW,CAAC,EAClC,KAAiB,EACjB,KAAW,EACX,GAAG,SAAS,EACb,EAAE,KAAK,+BAaP"}
|
|
@@ -10,6 +10,6 @@ type Props = ViewProps & {
|
|
|
10
10
|
/** Rotation speed in degrees/second. 0 = static. Default: 0 */
|
|
11
11
|
speed?: number;
|
|
12
12
|
};
|
|
13
|
-
export default function LinearGradient({ startColor, endColor, angle, speed, ...viewProps }: Props): import("react
|
|
13
|
+
export default function LinearGradient({ startColor, endColor, angle, speed, ...viewProps }: Props): import("react").JSX.Element;
|
|
14
14
|
export {};
|
|
15
15
|
//# sourceMappingURL=LinearGradient.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LinearGradient.d.ts","sourceRoot":"","sources":["../../../../src/components/LinearGradient.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,KAAK,GAAG,SAAS,GAAG;IACvB,8CAA8C;IAC9C,UAAU,EAAE,UAAU,CAAC;IACvB,4CAA4C;IAC5C,QAAQ,EAAE,UAAU,CAAC;IACrB,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EACrC,UAAU,EACV,QAAQ,EACR,KAAK,EACL,KAAS,EACT,GAAG,SAAS,EACb,EAAE,KAAK
|
|
1
|
+
{"version":3,"file":"LinearGradient.d.ts","sourceRoot":"","sources":["../../../../src/components/LinearGradient.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,KAAK,GAAG,SAAS,GAAG;IACvB,8CAA8C;IAC9C,UAAU,EAAE,UAAU,CAAC;IACvB,4CAA4C;IAC5C,QAAQ,EAAE,UAAU,CAAC;IACrB,oDAAoD;IACpD,KAAK,EAAE,MAAM,CAAC;IACd,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,EACrC,UAAU,EACV,QAAQ,EACR,KAAK,EACL,KAAS,EACT,GAAG,SAAS,EACb,EAAE,KAAK,+BAcP"}
|
|
@@ -12,6 +12,6 @@ type Props = ViewProps & {
|
|
|
12
12
|
/** Vertical frequency. Default: 3 */
|
|
13
13
|
frequencyY?: number;
|
|
14
14
|
};
|
|
15
|
-
export default function LiquidChrome({ color, speed, amplitude, frequencyX, frequencyY, ...viewProps }: Props): import("react
|
|
15
|
+
export default function LiquidChrome({ color, speed, amplitude, frequencyX, frequencyY, ...viewProps }: Props): import("react").JSX.Element;
|
|
16
16
|
export {};
|
|
17
17
|
//# sourceMappingURL=LiquidChrome.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LiquidChrome.d.ts","sourceRoot":"","sources":["../../../../src/components/LiquidChrome.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,KAAK,GAAG,SAAS,GAAG;IACvB,mDAAmD;IACnD,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uCAAuC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,KAAiB,EACjB,KAAW,EACX,SAAe,EACf,UAAc,EACd,UAAc,EACd,GAAG,SAAS,EACb,EAAE,KAAK
|
|
1
|
+
{"version":3,"file":"LiquidChrome.d.ts","sourceRoot":"","sources":["../../../../src/components/LiquidChrome.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,KAAK,GAAG,SAAS,GAAG;IACvB,mDAAmD;IACnD,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gDAAgD;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uCAAuC;IACvC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,qCAAqC;IACrC,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACnC,KAAiB,EACjB,KAAW,EACX,SAAe,EACf,UAAc,EACd,UAAc,EACd,GAAG,SAAS,EACb,EAAE,KAAK,+BAiBP"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { ShaderViewProps } from './types';
|
|
2
|
-
export default function ShaderView({ fragmentShader, colors, speed, params, isStatic, style, ...viewProps }: ShaderViewProps): import("react
|
|
2
|
+
export default function ShaderView({ fragmentShader, colors, speed, params, isStatic, transparent, paramsSynchronizable, style, ...viewProps }: ShaderViewProps): import("react").JSX.Element;
|
|
3
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/ShaderView/index.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAS/C,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,cAAc,EACd,MAAW,EACX,KAAW,EACX,MAAW,EACX,QAAgB,EAChB,KAAK,EACL,GAAG,SAAS,EACb,EAAE,eAAe
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/ShaderView/index.tsx"],"names":[],"mappings":"AAWA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAS/C,MAAM,CAAC,OAAO,UAAU,UAAU,CAAC,EACjC,cAAc,EACd,MAAW,EACX,KAAW,EACX,MAAW,EACX,QAAgB,EAChB,WAAmB,EACnB,oBAAoB,EACpB,KAAK,EACL,GAAG,SAAS,EACb,EAAE,eAAe,+BAiOjB"}
|
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
import type { ViewProps } from 'react-native';
|
|
2
|
+
import type { Synchronizable } from 'react-native-worklets';
|
|
2
3
|
import type { ColorInput } from '../../utils/colors';
|
|
4
|
+
/**
|
|
5
|
+
* A 4-float synchronizable whose values are written into the dedicated `u.live`
|
|
6
|
+
* uniform slot every frame. It has its own slot, so it never collides with the
|
|
7
|
+
* 8 static `params` (`u.params0`/`u.params1`).
|
|
8
|
+
*
|
|
9
|
+
* This is the bridge for live, per-frame input (touch position, scroll
|
|
10
|
+
* progress, velocity) coming from the JS thread into the off-thread render
|
|
11
|
+
* loop. Create one with `useParamsSynchronizable` and update it from
|
|
12
|
+
* gesture/scroll handlers. See `ShaderViewWithPanGesture`.
|
|
13
|
+
*/
|
|
14
|
+
export type ParamsSynchronizable = Synchronizable<Float64Array>;
|
|
3
15
|
export type ShaderViewProps = ViewProps & {
|
|
4
16
|
/** WGSL fragment shader source (must declare the Uniforms struct) */
|
|
5
17
|
fragmentShader: string;
|
|
@@ -11,5 +23,13 @@ export type ShaderViewProps = ViewProps & {
|
|
|
11
23
|
params?: number[];
|
|
12
24
|
/** Render once then stop the RAF loop. Default: false */
|
|
13
25
|
isStatic?: boolean;
|
|
26
|
+
/** Use transparent background (clear to alpha 0). Default: false */
|
|
27
|
+
transparent?: boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Optional live input. Its 4 floats are written into the dedicated `u.live`
|
|
30
|
+
* slot every frame — independent of the static `params`. Use for
|
|
31
|
+
* touch/scroll/audio. Create it with `useParamsSynchronizable`.
|
|
32
|
+
*/
|
|
33
|
+
paramsSynchronizable?: ParamsSynchronizable;
|
|
14
34
|
};
|
|
15
35
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/components/ShaderView/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG;IACxC,qEAAqE;IACrE,cAAc,EAAE,MAAM,CAAC;IACvB,wEAAwE;IACxE,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;IACtB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/components/ShaderView/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAC5D,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAErD;;;;;;;;;GASG;AACH,MAAM,MAAM,oBAAoB,GAAG,cAAc,CAAC,YAAY,CAAC,CAAC;AAEhE,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG;IACxC,qEAAqE;IACrE,cAAc,EAAE,MAAM,CAAC;IACvB,wEAAwE;IACxE,MAAM,CAAC,EAAE,UAAU,EAAE,CAAC;IACtB,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,iFAAiF;IACjF,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,oEAAoE;IACpE,WAAW,CAAC,EAAE,OAAO,CAAC;IACtB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;CAC7C,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ShaderViewProps } from '../ShaderView/types';
|
|
2
|
+
/**
|
|
3
|
+
* A {@link ShaderView} that feeds touch input into the shader's `u.live`:
|
|
4
|
+
*
|
|
5
|
+
* - `live.x` → pointer X, normalized 0..1 (left → right)
|
|
6
|
+
* - `live.y` → pointer Y, normalized 0..1 (bottom → top, matching UV space)
|
|
7
|
+
* - `live.z` → 1.0 while touching, 0.0 when released
|
|
8
|
+
* - `live.w` → 0.0 (reserved)
|
|
9
|
+
*
|
|
10
|
+
* Dragging moves the pointer **relatively** — it pushes from where the pointer
|
|
11
|
+
* already is rather than jumping under the finger — and a fling lets it glide to
|
|
12
|
+
* a stop. The position is **remembered**: it stays wherever it ended and is
|
|
13
|
+
* never reset; only the "touched" flag (`live.z`) toggles on release. A
|
|
14
|
+
* shader can read `live.xy` as a stable resting position and use `live.z`
|
|
15
|
+
* purely for touch-driven emphasis, so the effect never snaps back.
|
|
16
|
+
*
|
|
17
|
+
* The resting value before the first touch is `[0, 0, 0, 0]` by default; pass
|
|
18
|
+
* `initialParamsSynchronizable` to seed it — e.g. `[0.5, 0.5, 0, 0]` to start a
|
|
19
|
+
* pointer at screen center.
|
|
20
|
+
*
|
|
21
|
+
* The drag runs as a **worklet on the UI thread** and writes the synchronizable
|
|
22
|
+
* directly, so pointer updates never hop to the JS thread — matching the rest of
|
|
23
|
+
* the library, which renders off the JS thread. The render runtime reads the
|
|
24
|
+
* same synchronizable each frame.
|
|
25
|
+
*/
|
|
26
|
+
export type ShaderViewWithPanGestureProps = Omit<ShaderViewProps, 'paramsSynchronizable'> & {
|
|
27
|
+
/**
|
|
28
|
+
* Initial value for the gesture channel (`u.live`) before the first touch.
|
|
29
|
+
* Defaults to `[0, 0, 0, 0]`. Use e.g. `[0.5, 0.5, 0, 0]` to rest a pointer at
|
|
30
|
+
* screen center.
|
|
31
|
+
*/
|
|
32
|
+
initialParamsSynchronizable?: readonly [number, number, number, number];
|
|
33
|
+
};
|
|
34
|
+
export default function ShaderViewWithPanGesture({ style, initialParamsSynchronizable, ...props }: ShaderViewWithPanGestureProps): import("react").JSX.Element;
|
|
35
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/ShaderViewWithPanGesture/index.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAE3D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,MAAM,6BAA6B,GAAG,IAAI,CAC9C,eAAe,EACf,sBAAsB,CACvB,GAAG;IACF;;;;OAIG;IACH,2BAA2B,CAAC,EAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;CACzE,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,wBAAwB,CAAC,EAC/C,KAAK,EACL,2BAA0C,EAC1C,GAAG,KAAK,EACT,EAAE,6BAA6B,+BAuK/B"}
|
|
@@ -12,6 +12,6 @@ type Props = ViewProps & {
|
|
|
12
12
|
/** Intensity of the noise grain. Default: 1.5 */
|
|
13
13
|
noiseIntensity?: number;
|
|
14
14
|
};
|
|
15
|
-
export default function Silk({ color, speed, scale, rotation, noiseIntensity, ...viewProps }: Props): import("react
|
|
15
|
+
export default function Silk({ color, speed, scale, rotation, noiseIntensity, ...viewProps }: Props): import("react").JSX.Element;
|
|
16
16
|
export {};
|
|
17
17
|
//# sourceMappingURL=Silk.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Silk.d.ts","sourceRoot":"","sources":["../../../../src/components/Silk.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,KAAK,GAAG,SAAS,GAAG;IACvB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAC3B,KAAiB,EACjB,KAAW,EACX,KAAW,EACX,QAAc,EACd,cAAoB,EACpB,GAAG,SAAS,EACb,EAAE,KAAK
|
|
1
|
+
{"version":3,"file":"Silk.d.ts","sourceRoot":"","sources":["../../../../src/components/Silk.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAGlD,KAAK,KAAK,GAAG,SAAS,GAAG;IACvB,0CAA0C;IAC1C,KAAK,CAAC,EAAE,UAAU,CAAC;IACnB,+CAA+C;IAC/C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yCAAyC;IACzC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,8CAA8C;IAC9C,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,iDAAiD;IACjD,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,IAAI,CAAC,EAC3B,KAAiB,EACjB,KAAW,EACX,KAAW,EACX,QAAc,EACd,cAAoB,EACpB,GAAG,SAAS,EACb,EAAE,KAAK,+BAiBP"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ParamsSynchronizable } from '../components/ShaderView/types';
|
|
2
|
+
/**
|
|
3
|
+
* Creates a {@link ParamsSynchronizable} — a 4-float channel written into the
|
|
4
|
+
* dedicated `u.live` slot of a {@link ShaderView} every frame. It has its own
|
|
5
|
+
* uniform slot, so it leaves all 8 static `params` untouched.
|
|
6
|
+
*
|
|
7
|
+
* The returned `setParamsSynchronizable` runs on the JS thread (call it from gesture or scroll
|
|
8
|
+
* handlers); the values are read by the off-thread render loop. By convention
|
|
9
|
+
* the four floats carry `(x, y, active, extra)` for pointer input, or
|
|
10
|
+
* `(progress, ...)` for scroll-driven effects — but the meaning is up to the
|
|
11
|
+
* shader consuming `u.live`.
|
|
12
|
+
*
|
|
13
|
+
* Pass `initial` to seed the channel's starting value (read once on first
|
|
14
|
+
* render), so the shader has a sane resting state before the first update —
|
|
15
|
+
* e.g. `[0.5, 0.5, 0, 0]` to start a pointer at screen center. Defaults to all
|
|
16
|
+
* zeros.
|
|
17
|
+
*/
|
|
18
|
+
export declare function useParamsSynchronizable(initial?: readonly [number, number, number, number]): {
|
|
19
|
+
paramsSynchronizable: ParamsSynchronizable;
|
|
20
|
+
setParamsSynchronizable: (x: number, y: number, active: number, extra: number) => void;
|
|
21
|
+
};
|
|
22
|
+
//# sourceMappingURL=useParamsSynchronizable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useParamsSynchronizable.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useParamsSynchronizable.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAC;AAE3E;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,uBAAuB,CACrC,OAAO,GAAE,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAgB,GAChE;IACD,oBAAoB,EAAE,oBAAoB,CAAC;IAC3C,uBAAuB,EAAE,CACvB,CAAC,EAAE,MAAM,EACT,CAAC,EAAE,MAAM,EACT,MAAM,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,KACV,IAAI,CAAC;CACX,CAqBA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useWGPUSetup.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useWGPUSetup.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,eAAe,EACrB,MAAM,
|
|
1
|
+
{"version":3,"file":"useWGPUSetup.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useWGPUSetup.tsx"],"names":[],"mappings":"AACA,OAAO,EAEL,KAAK,SAAS,EACd,KAAK,eAAe,EACrB,MAAM,qBAAqB,CAAC;AAE7B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAI5D,KAAK,YAAY,GAAG;IAClB,MAAM,EAAE,SAAS,CAAC;IAClB,OAAO,EAAE,eAAe,CAAC;IACzB,kBAAkB,EAAE,gBAAgB,CAAC;CACtC,CAAC;AAEF,KAAK,eAAe,GAAG;IACrB,SAAS,EAAE,KAAK,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;IACtC,OAAO,EAAE,cAAc,CAAC;IACxB,SAAS,EAAE,YAAY,GAAG,IAAI,CAAC;CAChC,CAAC;AAEF,wBAAgB,YAAY,IAAI,eAAe,CAiD9C"}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import CircularGradient from './components/CircularGradient';
|
|
2
2
|
import LinearGradient from './components/LinearGradient';
|
|
3
3
|
import ShaderView from './components/ShaderView';
|
|
4
|
+
import ShaderViewWithPanGesture from './components/ShaderViewWithPanGesture';
|
|
4
5
|
import Iridescence from './components/Iridescence';
|
|
5
6
|
import LiquidChrome from './components/LiquidChrome';
|
|
6
7
|
import Silk from './components/Silk';
|
|
7
8
|
import Campfire from './components/Campfire';
|
|
8
9
|
import CalicoSwirl from './components/CalicoSwirl';
|
|
9
10
|
import Aurora from './components/Aurora';
|
|
10
|
-
|
|
11
|
-
export {
|
|
11
|
+
import { useParamsSynchronizable } from './hooks/useParamsSynchronizable';
|
|
12
|
+
export type { ShaderViewProps, ParamsSynchronizable, } from './components/ShaderView/types';
|
|
13
|
+
export type { ShaderViewWithPanGestureProps } from './components/ShaderViewWithPanGesture';
|
|
14
|
+
export type { ColorInput } from './utils/colors';
|
|
15
|
+
export { CircularGradient, LinearGradient, ShaderView, ShaderViewWithPanGesture, Iridescence, LiquidChrome, Silk, Campfire, CalicoSwirl, Aurora, useParamsSynchronizable, };
|
|
12
16
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,+BAA+B,CAAC;AAC7D,OAAO,cAAc,MAAM,6BAA6B,CAAC;AACzD,OAAO,UAAU,MAAM,yBAAyB,CAAC;AACjD,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,YAAY,MAAM,2BAA2B,CAAC;AACrD,OAAO,IAAI,MAAM,mBAAmB,CAAC;AACrC,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAC7C,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,MAAM,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,+BAA+B,CAAC;AAC7D,OAAO,cAAc,MAAM,6BAA6B,CAAC;AACzD,OAAO,UAAU,MAAM,yBAAyB,CAAC;AACjD,OAAO,wBAAwB,MAAM,uCAAuC,CAAC;AAC7E,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,YAAY,MAAM,2BAA2B,CAAC;AACrD,OAAO,IAAI,MAAM,mBAAmB,CAAC;AACrC,OAAO,QAAQ,MAAM,uBAAuB,CAAC;AAC7C,OAAO,WAAW,MAAM,0BAA0B,CAAC;AACnD,OAAO,MAAM,MAAM,qBAAqB,CAAC;AACzC,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAE1E,YAAY,EACV,eAAe,EACf,oBAAoB,GACrB,MAAM,+BAA+B,CAAC;AACvC,YAAY,EAAE,6BAA6B,EAAE,MAAM,uCAAuC,CAAC;AAC3F,YAAY,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,UAAU,EACV,wBAAwB,EACxB,WAAW,EACX,YAAY,EACZ,IAAI,EACJ,QAAQ,EACR,WAAW,EACX,MAAM,EACN,uBAAuB,GACxB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
export declare const UNIFORM_BUFFER_SIZE =
|
|
1
|
+
/** 112 bytes = 7 × vec4<f32> */
|
|
2
|
+
export declare const UNIFORM_BUFFER_SIZE = 112;
|
|
3
3
|
/** Number of float32 values in the uniform buffer */
|
|
4
4
|
export declare const UNIFORM_FLOAT_COUNT: number;
|
|
5
|
-
export declare const UNIFORMS_WGSL = "\nstruct Uniforms {\n resolution: vec4<f32>, // (width, height, aspect, pixelRatio)\n time: vec4<f32>, // (seconds, dt, 0, 0)\n color0: vec4<f32>, // colors[0] RGBA\n color1: vec4<f32>, // colors[1] RGBA\n params0: vec4<f32>, // params[0..3]\n params1: vec4<f32>, // params[4..7]\n};\n@group(0) @binding(0) var<uniform> u: Uniforms;\n";
|
|
5
|
+
export declare const UNIFORMS_WGSL = "\nstruct Uniforms {\n resolution: vec4<f32>, // (width, height, aspect, pixelRatio)\n time: vec4<f32>, // (seconds, dt, 0, 0)\n color0: vec4<f32>, // colors[0] RGBA\n color1: vec4<f32>, // colors[1] RGBA\n params0: vec4<f32>, // params[0..3]\n params1: vec4<f32>, // params[4..7]\n live: vec4<f32>, // paramsSynchronizable (touch/scroll/audio); (0,0,0,0) when unused\n};\n@group(0) @binding(0) var<uniform> u: Uniforms;\n";
|
|
6
6
|
//# sourceMappingURL=uniforms.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uniforms.d.ts","sourceRoot":"","sources":["../../../../src/shaders/uniforms.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"uniforms.d.ts","sourceRoot":"","sources":["../../../../src/shaders/uniforms.ts"],"names":[],"mappings":"AAAA,gCAAgC;AAChC,eAAO,MAAM,mBAAmB,MAAM,CAAC;AAEvC,qDAAqD;AACrD,eAAO,MAAM,mBAAmB,QAA0B,CAAC;AAE3D,eAAO,MAAM,aAAa,kdAWzB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-effects",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "WebGPU-powered visual effects running on a background thread in React Native",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -65,45 +65,46 @@
|
|
|
65
65
|
"registry": "https://registry.npmjs.org/"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
68
|
-
"@commitlint/config-conventional": "^
|
|
69
|
-
"@eslint/compat": "^1.
|
|
70
|
-
"@eslint/eslintrc": "^3.3.
|
|
71
|
-
"@eslint/js": "^9.
|
|
72
|
-
"@react-native/babel-preset": "0.
|
|
73
|
-
"@react-native/eslint-config": "0.
|
|
74
|
-
"@
|
|
68
|
+
"@commitlint/config-conventional": "^21.0.2",
|
|
69
|
+
"@eslint/compat": "^2.1.0",
|
|
70
|
+
"@eslint/eslintrc": "^3.3.5",
|
|
71
|
+
"@eslint/js": "^9.39.4",
|
|
72
|
+
"@react-native/babel-preset": "0.85.3",
|
|
73
|
+
"@react-native/eslint-config": "0.85.3",
|
|
74
|
+
"@react-native/jest-preset": "0.85.3",
|
|
75
|
+
"@release-it/conventional-changelog": "^11.0.1",
|
|
75
76
|
"@types/jest": "^29.5.14",
|
|
76
|
-
"@types/react": "^19.
|
|
77
|
-
"@webgpu/types": "0.1.
|
|
78
|
-
"commitlint": "^
|
|
79
|
-
"del-cli": "^
|
|
80
|
-
"eslint": "^9.
|
|
77
|
+
"@types/react": "^19.2.17",
|
|
78
|
+
"@webgpu/types": "0.1.70",
|
|
79
|
+
"commitlint": "^21.0.2",
|
|
80
|
+
"del-cli": "^7.0.0",
|
|
81
|
+
"eslint": "^9.39.4",
|
|
81
82
|
"eslint-config-prettier": "^10.1.8",
|
|
82
|
-
"eslint-plugin-prettier": "^5.5.
|
|
83
|
+
"eslint-plugin-prettier": "^5.5.6",
|
|
83
84
|
"jest": "^29.7.0",
|
|
84
|
-
"lefthook": "^2.
|
|
85
|
-
"prettier": "^
|
|
86
|
-
"react": "19.2.
|
|
87
|
-
"react-native": "0.
|
|
88
|
-
"react-native-builder-bob": "^0.
|
|
89
|
-
"react-native-gesture-handler": "2.
|
|
90
|
-
"react-native-reanimated": "4.3.
|
|
91
|
-
"react-native-
|
|
92
|
-
"react-native-worklets": "0.8.
|
|
93
|
-
"release-it": "^
|
|
94
|
-
"turbo": "^2.
|
|
95
|
-
"typescript": "^
|
|
85
|
+
"lefthook": "^2.1.9",
|
|
86
|
+
"prettier": "^3.8.3",
|
|
87
|
+
"react": "19.2.3",
|
|
88
|
+
"react-native": "0.85.3",
|
|
89
|
+
"react-native-builder-bob": "^0.41.0",
|
|
90
|
+
"react-native-gesture-handler": "2.31.1",
|
|
91
|
+
"react-native-reanimated": "4.3.1",
|
|
92
|
+
"react-native-webgpu": "0.5.14",
|
|
93
|
+
"react-native-worklets": "0.8.3",
|
|
94
|
+
"release-it": "^20.2.0",
|
|
95
|
+
"turbo": "^2.9.16",
|
|
96
|
+
"typescript": "^6.0.3"
|
|
96
97
|
},
|
|
97
98
|
"peerDependencies": {
|
|
98
99
|
"react": "*",
|
|
99
100
|
"react-native": "*",
|
|
100
101
|
"react-native-gesture-handler": ">=2.0.0",
|
|
101
|
-
"react-native-
|
|
102
|
+
"react-native-webgpu": ">=0.5.0",
|
|
102
103
|
"react-native-worklets": ">=0.8.0"
|
|
103
104
|
},
|
|
104
105
|
"resolutions": {
|
|
105
|
-
"metro": "patch:metro@npm%3A0.
|
|
106
|
-
"metro-runtime": "patch:metro-runtime@npm%3A0.
|
|
106
|
+
"metro": "patch:metro@npm%3A0.84.4#./.yarn/patches/metro-npm-0.84.4.patch",
|
|
107
|
+
"metro-runtime": "patch:metro-runtime@npm%3A0.84.4#./.yarn/patches/metro-runtime-npm-0.84.4.patch"
|
|
107
108
|
},
|
|
108
109
|
"workspaces": [
|
|
109
110
|
"example"
|
|
@@ -135,7 +136,7 @@
|
|
|
135
136
|
"useTabs": false
|
|
136
137
|
},
|
|
137
138
|
"jest": {
|
|
138
|
-
"preset": "react-native",
|
|
139
|
+
"preset": "@react-native/jest-preset",
|
|
139
140
|
"modulePathIgnorePatterns": [
|
|
140
141
|
"<rootDir>/example/node_modules",
|
|
141
142
|
"<rootDir>/lib/"
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { PixelRatio, StyleSheet } from 'react-native';
|
|
2
|
-
import { Canvas } from 'react-native-
|
|
2
|
+
import { Canvas } from 'react-native-webgpu';
|
|
3
3
|
import { useEffect, useRef } from 'react';
|
|
4
4
|
import { createSynchronizable, scheduleOnRuntime } from 'react-native-worklets';
|
|
5
5
|
import { colorToVec4 } from '../../utils/colors';
|
|
@@ -24,6 +24,8 @@ export default function ShaderView({
|
|
|
24
24
|
speed = 1.0,
|
|
25
25
|
params = [],
|
|
26
26
|
isStatic = false,
|
|
27
|
+
transparent = false,
|
|
28
|
+
paramsSynchronizable,
|
|
27
29
|
style,
|
|
28
30
|
...viewProps
|
|
29
31
|
}: ShaderViewProps) {
|
|
@@ -88,6 +90,12 @@ export default function ShaderView({
|
|
|
88
90
|
const { device, context, presentationFormat } = resources;
|
|
89
91
|
const dpr = PixelRatio.get();
|
|
90
92
|
|
|
93
|
+
// Per-run cancellation token. On Fast Refresh / dep change / unmount, React
|
|
94
|
+
// runs this effect's cleanup, which flips the flag and stops *this* loop —
|
|
95
|
+
// otherwise the old worklet RAF loop keeps running forever alongside the new
|
|
96
|
+
// one, stacking a duplicate render loop on every Metro reload.
|
|
97
|
+
const cancelled = createSynchronizable<Float64Array>(new Float64Array(1));
|
|
98
|
+
|
|
91
99
|
scheduleOnRuntime(runtime, () => {
|
|
92
100
|
'worklet';
|
|
93
101
|
|
|
@@ -127,6 +135,12 @@ export default function ShaderView({
|
|
|
127
135
|
return;
|
|
128
136
|
}
|
|
129
137
|
|
|
138
|
+
// This loop was superseded (Fast Refresh / unmount) — bail without
|
|
139
|
+
// scheduling another frame so it can be garbage-collected.
|
|
140
|
+
if (cancelled.getDirty()[0] === 1) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
|
|
130
144
|
// Compute dt
|
|
131
145
|
const dt = lastTimestamp === 0 ? 0 : (timestamp - lastTimestamp) / 1000;
|
|
132
146
|
lastTimestamp = timestamp;
|
|
@@ -144,7 +158,7 @@ export default function ShaderView({
|
|
|
144
158
|
const height = canvas.height || 1;
|
|
145
159
|
const aspect = width / height;
|
|
146
160
|
|
|
147
|
-
// Fill uniform data (
|
|
161
|
+
// Fill uniform data (7 × vec4 = 28 floats)
|
|
148
162
|
// resolution: vec4<f32>
|
|
149
163
|
uniformData[0] = width;
|
|
150
164
|
uniformData[1] = height;
|
|
@@ -175,12 +189,23 @@ export default function ShaderView({
|
|
|
175
189
|
uniformData[18] = props[IDX_PARAMS + 2]!;
|
|
176
190
|
uniformData[19] = props[IDX_PARAMS + 3]!;
|
|
177
191
|
|
|
178
|
-
// params1: vec4<f32>
|
|
192
|
+
// params1: vec4<f32> — static params[4..7]
|
|
179
193
|
uniformData[20] = props[IDX_PARAMS + 4]!;
|
|
180
194
|
uniformData[21] = props[IDX_PARAMS + 5]!;
|
|
181
195
|
uniformData[22] = props[IDX_PARAMS + 6]!;
|
|
182
196
|
uniformData[23] = props[IDX_PARAMS + 7]!;
|
|
183
197
|
|
|
198
|
+
// live: vec4<f32> — off-thread input (touch/scroll/audio) from
|
|
199
|
+
// paramsSynchronizable, written into its own slot so it never collides
|
|
200
|
+
// with the static params. Stays (0,0,0,0) when no channel is attached.
|
|
201
|
+
if (paramsSynchronizable) {
|
|
202
|
+
const live = paramsSynchronizable.getDirty();
|
|
203
|
+
uniformData[24] = live[0]!;
|
|
204
|
+
uniformData[25] = live[1]!;
|
|
205
|
+
uniformData[26] = live[2]!;
|
|
206
|
+
uniformData[27] = live[3]!;
|
|
207
|
+
}
|
|
208
|
+
|
|
184
209
|
device.queue.writeBuffer(uniformBuffer, 0, uniformData);
|
|
185
210
|
|
|
186
211
|
const commandEncoder = device.createCommandEncoder();
|
|
@@ -189,7 +214,7 @@ export default function ShaderView({
|
|
|
189
214
|
colorAttachments: [
|
|
190
215
|
{
|
|
191
216
|
view: textureView,
|
|
192
|
-
clearValue: [0, 0, 0, 1],
|
|
217
|
+
clearValue: transparent ? [0, 0, 0, 0] : [0, 0, 0, 1],
|
|
193
218
|
loadOp: 'clear',
|
|
194
219
|
storeOp: 'store',
|
|
195
220
|
},
|
|
@@ -211,7 +236,19 @@ export default function ShaderView({
|
|
|
211
236
|
|
|
212
237
|
requestAnimationFrame(render);
|
|
213
238
|
});
|
|
214
|
-
|
|
239
|
+
|
|
240
|
+
return () => {
|
|
241
|
+
cancelled.setBlocking(() => Float64Array.of(1));
|
|
242
|
+
};
|
|
243
|
+
}, [
|
|
244
|
+
resources,
|
|
245
|
+
runtime,
|
|
246
|
+
propsSync,
|
|
247
|
+
paramsSynchronizable,
|
|
248
|
+
fragmentShader,
|
|
249
|
+
isStatic,
|
|
250
|
+
transparent,
|
|
251
|
+
]);
|
|
215
252
|
|
|
216
253
|
return (
|
|
217
254
|
<Canvas ref={canvasRef} style={[styles.canvas, style]} {...viewProps} />
|
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import type { ViewProps } from 'react-native';
|
|
2
|
+
import type { Synchronizable } from 'react-native-worklets';
|
|
2
3
|
import type { ColorInput } from '../../utils/colors';
|
|
3
4
|
|
|
5
|
+
/**
|
|
6
|
+
* A 4-float synchronizable whose values are written into the dedicated `u.live`
|
|
7
|
+
* uniform slot every frame. It has its own slot, so it never collides with the
|
|
8
|
+
* 8 static `params` (`u.params0`/`u.params1`).
|
|
9
|
+
*
|
|
10
|
+
* This is the bridge for live, per-frame input (touch position, scroll
|
|
11
|
+
* progress, velocity) coming from the JS thread into the off-thread render
|
|
12
|
+
* loop. Create one with `useParamsSynchronizable` and update it from
|
|
13
|
+
* gesture/scroll handlers. See `ShaderViewWithPanGesture`.
|
|
14
|
+
*/
|
|
15
|
+
export type ParamsSynchronizable = Synchronizable<Float64Array>;
|
|
16
|
+
|
|
4
17
|
export type ShaderViewProps = ViewProps & {
|
|
5
18
|
/** WGSL fragment shader source (must declare the Uniforms struct) */
|
|
6
19
|
fragmentShader: string;
|
|
@@ -12,4 +25,12 @@ export type ShaderViewProps = ViewProps & {
|
|
|
12
25
|
params?: number[];
|
|
13
26
|
/** Render once then stop the RAF loop. Default: false */
|
|
14
27
|
isStatic?: boolean;
|
|
28
|
+
/** Use transparent background (clear to alpha 0). Default: false */
|
|
29
|
+
transparent?: boolean;
|
|
30
|
+
/**
|
|
31
|
+
* Optional live input. Its 4 floats are written into the dedicated `u.live`
|
|
32
|
+
* slot every frame — independent of the static `params`. Use for
|
|
33
|
+
* touch/scroll/audio. Create it with `useParamsSynchronizable`.
|
|
34
|
+
*/
|
|
35
|
+
paramsSynchronizable?: ParamsSynchronizable;
|
|
15
36
|
};
|