@flare-engine/react 0.3.0 → 0.4.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 CHANGED
@@ -5,10 +5,18 @@ React Native integration — `<GameView>` (Skia Canvas + game loop + input), `<V
5
5
  ## Install
6
6
 
7
7
  ```sh
8
- bun add @flare-engine/react @shopify/react-native-skia react-native-safe-area-context
8
+ bun add @flare-engine/react @shopify/react-native-skia react-native-reanimated react-native-worklets react-native-safe-area-context
9
9
  ```
10
10
 
11
- Peer deps: `react` (>=19), `react-native` (>=0.79), `@shopify/react-native-skia` (>=2), `react-native-safe-area-context` (>=4). The last one is a value import in `<GameView>` (`useSafeAreaInsets`), not type-only — a project without it fails to resolve at runtime.
11
+ Peer deps: `react` (>=19), `react-native` (>=0.79), `@shopify/react-native-skia` (>=2), `react-native-reanimated` (>=4), `react-native-worklets` (>=0.7), `react-native-safe-area-context` (>=4). `react-native-reanimated`, `react-native-worklets` and `react-native-safe-area-context` are all value imports in `<GameView>` — a project without any of them fails to resolve at runtime.
12
+
13
+ > **The New Architecture is required.** Reanimated 4 is New-Architecture-only, so an app using
14
+ > `<GameView>` must run with `newArchEnabled=true`. This costs nothing in practice — it has been
15
+ > RN's default since 0.76, and every `@flare-engine/create` template pins Expo 57 / RN 0.86, which
16
+ > force it on. Old-architecture support was dropped deliberately in
17
+ > [ADR-0002](https://github.com/grzott/flare-engine/blob/main/docs/design/adr-0002-worklets-migration-and-new-arch-floor.md):
18
+ > the previous `>=3.19.1` floor promised something no scaffolder template could produce, so it was
19
+ > never verifiable.
12
20
 
13
21
  ## Usage
14
22
 
package/dist/index.d.mts CHANGED
@@ -71,7 +71,7 @@ interface PostFxPassDescriptor {
71
71
  readonly uniforms: Record<string, number | readonly number[]>;
72
72
  /**
73
73
  * Extra child shader slots beyond the implicit scene sampler. Empty for every
74
- * built-in PT effect; only color-grading-lut would populate it. Each entry
74
+ * built-in effect; only color-grading-lut would populate it. Each entry
75
75
  * is an SkImage that GameView wraps in `<ImageShader>`.
76
76
  */
77
77
  readonly children: readonly SkImage[];
@@ -203,8 +203,19 @@ interface GameConfig {
203
203
  * RN siblings on certain Android devices/Fabric configurations.
204
204
  *
205
205
  * Implies the canvas content is opaque — the clearColor's alpha must be
206
- * fully opaque (0xFF). Defaults to `false` to preserve the current
207
- * iOS-equivalent behavior.
206
+ * fully opaque (0xFF), which the default `0xff000000` already satisfies.
207
+ * Defaults to `false` to preserve the current iOS-equivalent behavior.
208
+ *
209
+ * **Recommended on Android.** Measured on a Pixel 7 (Android 17, release
210
+ * build, XR-1c): with the default TextureView path RN-Skia logs its
211
+ * `updateTexImage: LegacySurfaceTexture is not attached!` /
212
+ * `updateAndRelease() failed` pair **22 028 times per 60 s** — 90% of all
213
+ * logcat output, saturating the 256 KiB ring buffer so unrelated diagnostics
214
+ * are lost. With `opaque: true` the same build over three 60 s windows logs
215
+ * the pair **zero** times and total log volume drops ~10x. RN-Skia labels the
216
+ * pair ignorable and rendering is correct either way, so this is log noise
217
+ * and TextureView overhead, not a correctness fix. Native memory is flat
218
+ * across a 6-minute soak on both paths.
208
219
  */
209
220
  opaque?: boolean;
210
221
  }
@@ -218,9 +229,9 @@ interface GameViewProps {
218
229
  style?: ViewStyle;
219
230
  /** Optional overlay children (e.g. VirtualJoystick, VirtualButton). */
220
231
  children?: React.ReactNode;
221
- /** Explicit safe-area insets. If omitted, resolved from react-native-safe-area-context
222
- * via `useSafeAreaInsets()` (requires a `<SafeAreaProvider>` ancestor; falls back to
223
- * zero insets when no provider is mounted). */
232
+ /** Explicit safe-area insets. If omitted, resolved via `useContext(SafeAreaInsetsContext)`
233
+ * from react-native-safe-area-context; falls back to `{ top: 0, right: 0, bottom: 0,
234
+ * left: 0 }` when no `<SafeAreaProvider>` ancestor is mounted. */
224
235
  safeArea?: SafeArea;
225
236
  }
226
237
  /**
@@ -303,8 +314,9 @@ interface VirtualButtonProps {
303
314
  /**
304
315
  * VirtualButton — an on-screen button overlay component.
305
316
  *
306
- * Claims the React Native touch responder so press/release fire reliably
307
- * even when an ancestor (e.g. <GameView>) also claims the responder.
317
+ * Uses raw `onTouchStart`/`onTouchEnd` so press and release fire regardless
318
+ * of which ancestor holds the RN responder — enabling simultaneous use with
319
+ * `<VirtualJoystick>` without responder conflicts.
308
320
  */
309
321
  declare function VirtualButton({ onStateChange, style, children }: VirtualButtonProps): React.ReactElement;
310
322
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/game-context.ts","../src/skia-bridge.ts","../src/safe-area.ts","../src/game-view.tsx","../src/hooks.ts","../src/loading-screen.tsx","../src/overlay-hooks.ts","../src/skia-atlas.ts","../src/virtual-button.tsx","../src/virtual-joystick.tsx"],"mappings":";;;;;;;;;;;;;UAUiB;;EAEf,OAAO;;EAEP,QAAQ;;EAER,OAAO;;EAEP,OAAO;;EAEP,QAAQ;;EAER,QAAQ;;EAER,MAAM;;EAEN,UAAU;;EAEV,OAAO;;;;;;cAOI,6BAAW,QAAA;;;;UCrBP;EACf,YAAY;EACZ,cAAc,gBAAgB,cAAc,cAAc;EAC1D,SAAS,eAAe;EACxB,MAAM;;;UAIS;EACf,aAAa;EACb,qBAAqB;;;;EAIrB;;;;;;UAOe;;WAEN;;WAEA,QAAQ;;;;;;WAMR,UAAU;;;;;;WAMV,mBAAmB;;;UAuBb;WACN;WACA;WACA;WACA;;WAEA;;;UAIM;WACN;WACA;;WAEA;WACA,iBAAiB;;;;;;;;;;KAWhB,iBAAiB;EAC3B;IAAkB,KAAK,eAAe;;EACtC;IACE,KAAK,eAAe,iBAAiB;IACrC,eAAe,eAAe,iBAAiB;;;EAGjD;IACE,eACE,YACA,YACA,gBACA,gBACA,OAAO,SACP,OAAO,uBACN;;;;;;;KAQK,mBAAmB;;;;;KAMnB,oBAAoB;;KAGpB,kBAAkB;;;;;;KAOlB,oBAAoB;;;;;;;;;;;iBAYhB,wBAAwB,MAAM,iBAAiB;;;;;;;iBAc/C,oBACd,MAAM,gBACN,MAAM,mBACL;;;UCtKc;EACf;EACA;EACA;EACA;;cAGW,iCAAe,QAAA;iBAEZ,eAAe;;;;;;;KCoBnB,cAAc,KAAK,kBAAkB;;;;;;;KAQrC,oBACV,KAAK,kBACL,iBACA,QAFK;;UAMU;;EAEf;;EAEA;;EAEA;;EAEA,cAAc;;;EAGd,qBAAqB;;;;;EAKrB,iBAAiB;;;;;;;;;;;;;;;EAejB;;;UAIe;;EAEf,SAAS;;EAET,WAAW,KAAK;;EAEhB,QAAQ;;EAER,WAAW,MAAM;;;;EAIjB,WAAW;;;;;;;;;iBAUG,WACd,QACA,SACA,OACA,UACA,YACC,gBAAgB,MAAM;;;;;;;iBCrGT,WAAW;;;;;;;iBAcX,UAAU,OAAO;;;;;;;;iBA4BjB,YAAY,WAAW;;;;UC7CtB;;EAEf;;EAEA,QAAQ;;EAER;;EAEA;;EAEA;;;;;;;;;;iBAWc,gBACd,UACA,OACA,UACA,YACA,mBACC,qBAAqB,MAAM;;;iBC5Bd,eAAe,kBAAkB;iBAoCjC,WAAW,gBAAgB;iBAmC3B,eAAe,GAAG,QAAQ,OAAO,IAAI,SAAS,IAAI;;;;;;;cCpErD,iBAAiB;;;;UCMb;;EAEf,iBAAiB,OAAO;;EAExB,QAAQ;;EAER,WAAW,MAAM;;;;;;;;iBASH,gBACd,eACA,OACA,YACC,qBAAqB,MAAM;;;;UCnBb;;EAEf,SAAS;;EAET,iBAAiB,OAAO;;EAExB,QAAQ;;EAER,OAAO,MAAM;;EAEb,QAAQ,MAAM;;;;;;;;;iBAUA,kBACd,QACA,eACA,OACA,MACA,SACC,uBAAuB,MAAM"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/game-context.ts","../src/skia-bridge.ts","../src/safe-area.ts","../src/game-view.tsx","../src/hooks.ts","../src/loading-screen.tsx","../src/overlay-hooks.ts","../src/skia-atlas.ts","../src/virtual-button.tsx","../src/virtual-joystick.tsx"],"mappings":";;;;;;;;;;;;;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;;;;;;;;iBA4BjB,YAAY,WAAW;;;;UC7CtB;;EAEf;;EAEA,QAAQ;;EAER;;EAEA;;EAEA;;;;;;;;;;iBAWc,gBACd,UACA,OACA,UACA,YACA,mBACC,qBAAqB,MAAM;;;iBC5Bd,eAAe,kBAAkB;iBAoCjC,WAAW,gBAAgB;iBAmC3B,eAAe,GAAG,QAAQ,OAAO,IAAI,SAAS,IAAI;;;;;;;cCpErD,iBAAiB;;;;UCMb;;EAEf,iBAAiB,OAAO;;EAExB,QAAQ;;EAER,WAAW,MAAM;;;;;;;;;iBAUH,gBACd,eACA,OACA,YACC,qBAAqB,MAAM;;;;UCpBb;;EAEf,SAAS;;EAET,iBAAiB,OAAO;;EAExB,QAAQ;;EAER,OAAO,MAAM;;EAEb,QAAQ,MAAM;;;;;;;;;iBAUA,kBACd,QACA,eACA,OACA,MACA,SACC,uBAAuB,MAAM"}
package/dist/index.d.ts CHANGED
@@ -71,7 +71,7 @@ interface PostFxPassDescriptor {
71
71
  readonly uniforms: Record<string, number | readonly number[]>;
72
72
  /**
73
73
  * Extra child shader slots beyond the implicit scene sampler. Empty for every
74
- * built-in PT effect; only color-grading-lut would populate it. Each entry
74
+ * built-in effect; only color-grading-lut would populate it. Each entry
75
75
  * is an SkImage that GameView wraps in `<ImageShader>`.
76
76
  */
77
77
  readonly children: readonly SkImage[];
@@ -203,8 +203,19 @@ interface GameConfig {
203
203
  * RN siblings on certain Android devices/Fabric configurations.
204
204
  *
205
205
  * Implies the canvas content is opaque — the clearColor's alpha must be
206
- * fully opaque (0xFF). Defaults to `false` to preserve the current
207
- * iOS-equivalent behavior.
206
+ * fully opaque (0xFF), which the default `0xff000000` already satisfies.
207
+ * Defaults to `false` to preserve the current iOS-equivalent behavior.
208
+ *
209
+ * **Recommended on Android.** Measured on a Pixel 7 (Android 17, release
210
+ * build, XR-1c): with the default TextureView path RN-Skia logs its
211
+ * `updateTexImage: LegacySurfaceTexture is not attached!` /
212
+ * `updateAndRelease() failed` pair **22 028 times per 60 s** — 90% of all
213
+ * logcat output, saturating the 256 KiB ring buffer so unrelated diagnostics
214
+ * are lost. With `opaque: true` the same build over three 60 s windows logs
215
+ * the pair **zero** times and total log volume drops ~10x. RN-Skia labels the
216
+ * pair ignorable and rendering is correct either way, so this is log noise
217
+ * and TextureView overhead, not a correctness fix. Native memory is flat
218
+ * across a 6-minute soak on both paths.
208
219
  */
209
220
  opaque?: boolean;
210
221
  }
@@ -218,9 +229,9 @@ interface GameViewProps {
218
229
  style?: ViewStyle;
219
230
  /** Optional overlay children (e.g. VirtualJoystick, VirtualButton). */
220
231
  children?: React.ReactNode;
221
- /** Explicit safe-area insets. If omitted, resolved from react-native-safe-area-context
222
- * via `useSafeAreaInsets()` (requires a `<SafeAreaProvider>` ancestor; falls back to
223
- * zero insets when no provider is mounted). */
232
+ /** Explicit safe-area insets. If omitted, resolved via `useContext(SafeAreaInsetsContext)`
233
+ * from react-native-safe-area-context; falls back to `{ top: 0, right: 0, bottom: 0,
234
+ * left: 0 }` when no `<SafeAreaProvider>` ancestor is mounted. */
224
235
  safeArea?: SafeArea;
225
236
  }
226
237
  /**
@@ -303,8 +314,9 @@ interface VirtualButtonProps {
303
314
  /**
304
315
  * VirtualButton — an on-screen button overlay component.
305
316
  *
306
- * Claims the React Native touch responder so press/release fire reliably
307
- * even when an ancestor (e.g. <GameView>) also claims the responder.
317
+ * Uses raw `onTouchStart`/`onTouchEnd` so press and release fire regardless
318
+ * of which ancestor holds the RN responder — enabling simultaneous use with
319
+ * `<VirtualJoystick>` without responder conflicts.
308
320
  */
309
321
  declare function VirtualButton({ onStateChange, style, children }: VirtualButtonProps): React.ReactElement;
310
322
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../src/game-context.ts","../src/skia-bridge.ts","../src/safe-area.ts","../src/game-view.tsx","../src/hooks.ts","../src/loading-screen.tsx","../src/overlay-hooks.ts","../src/skia-atlas.ts","../src/virtual-button.tsx","../src/virtual-joystick.tsx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AU,OAAO;;;;;;;;iBA4BjB,YAAY,WAAW;;;;UC7CtB;;EAEf;;EAEA,QAAQ;;EAER;;EAEA;;EAEA;;;;;;;;;;iBAWc,gBACd,UACA,OACA,UACA,YACA,mBACC,qBAAqB,MAAM;;;iBC5Bd,eAAe,kBAAkB;iBAoCjC,WAAW,gBAAgB;iBAmC3B,eAAe,GAAG,QAAQ,OAAO,IAAI,SAAS,IAAI;;;;;;;cCpErD,iBAAiB;;;;UCMb;;EAEf,iBAAiB,OAAO;;EAExB,QAAQ;;EAER,WAAW,MAAM;;;;;;;;iBASH,gBACd,eACA,OACA,YACC,qBAAqB,MAAM;;;;UCnBb;;EAEf,SAAS;;EAET,iBAAiB,OAAO;;EAExB,QAAQ;;EAER,OAAO,MAAM;;EAEb,QAAQ,MAAM;;;;;;;;;iBAUA,kBACd,QACA,eACA,OACA,MACA,SACC,uBAAuB,MAAM"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../src/game-context.ts","../src/skia-bridge.ts","../src/safe-area.ts","../src/game-view.tsx","../src/hooks.ts","../src/loading-screen.tsx","../src/overlay-hooks.ts","../src/skia-atlas.ts","../src/virtual-button.tsx","../src/virtual-joystick.tsx"],"mappings":";;;;;;;;;;;;;UAUiB;;EAEf,OAAO;;EAEP,QAAQ;;EAER,OAAO;;EAEP,OAAO;;EAEP,QAAQ;;EAER,QAAQ;;EAER,MAAM;;EAEN,UAAU;;EAEV,OAAO;;;;;;cAOI,6BAAW,QAAA;;;;UCrBP;EACf,YAAY;EACZ,cAAc,gBAAgB,cAAc,cAAc;EAC1D,SAAS,eAAe;EACxB,MAAM;;;UAIS;EACf,aAAa;EACb,qBAAqB;;;;EAIrB;;;;;;UAOe;;WAEN;;WAEA,QAAQ;;;;;;WAMR,UAAU;;;;;;WAMV,mBAAmB;;;UAuBb;WACN;WACA;WACA;WACA;;WAEA;;;UAIM;WACN;WACA;;WAEA;WACA,iBAAiB;;;;;;;;;;KAWhB,iBAAiB;EAC3B;IAAkB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;;EAEb,QAAQ,MAAM;;;;;;;;;iBAUA,kBACd,QACA,eACA,OACA,MACA,SACC,uBAAuB,MAAM"}
package/dist/index.js CHANGED
@@ -9,7 +9,9 @@ let _flare_engine_render = require("@flare-engine/render");
9
9
  let _flare_engine_scene = require("@flare-engine/scene");
10
10
  let _shopify_react_native_skia = require("@shopify/react-native-skia");
11
11
  let react_native = require("react-native");
12
+ let react_native_reanimated = require("react-native-reanimated");
12
13
  let react_native_safe_area_context = require("react-native-safe-area-context");
14
+ let react_native_worklets = require("react-native-worklets");
13
15
  let react_jsx_runtime = require("react/jsx-runtime");
14
16
  let _flare_engine_math = require("@flare-engine/math");
15
17
  //#region src/game-context.ts
@@ -103,8 +105,9 @@ function createSceneSurfaceCache(Skia) {
103
105
  * released once the ring exceeds depth 3, ensuring the canvas's rAF always has
104
106
  * a live image to paint from.
105
107
  */
106
- const RETENTION_DEPTH = 3;
107
- function createSceneCapture(Skia) {
108
+ function createSceneCapture(Skia, opts) {
109
+ const useNonTexture = opts?.nonTextureImage ?? true;
110
+ const retentionDepth = opts?.retentionDepth ?? 3;
108
111
  const surfaces = createSceneSurfaceCache(Skia);
109
112
  const ring = [];
110
113
  return {
@@ -115,10 +118,10 @@ function createSceneCapture(Skia) {
115
118
  surface.flush();
116
119
  const snapshot = surface.makeImageSnapshot();
117
120
  const detachable = snapshot;
118
- const detached = detachable.makeNonTextureImage ? detachable.makeNonTextureImage() : snapshot;
121
+ const detached = useNonTexture && detachable.makeNonTextureImage ? detachable.makeNonTextureImage() : snapshot;
119
122
  if (detached !== snapshot) releaseSkiaObject(snapshot);
120
123
  ring.push(detached);
121
- if (ring.length > RETENTION_DEPTH) releaseSkiaObject(ring.shift());
124
+ if (ring.length > retentionDepth) releaseSkiaObject(ring.shift());
122
125
  return detached;
123
126
  },
124
127
  dispose() {
@@ -128,54 +131,6 @@ function createSceneCapture(Skia) {
128
131
  }
129
132
  };
130
133
  }
131
- /**
132
- * Web scene texture (imperative form): expose a `capture` callback that
133
- * `GameView`'s `onPreRender` frame callback invokes directly instead of pushing
134
- * a picture through React state.
135
- *
136
- * The previous reactive form called `setImage` from a `useEffect` keyed on
137
- * `[Skia, picture, width, height]`. `onPreRender` would call `setPicture`,
138
- * React would re-render, the effect would re-run, `setImage` would re-render
139
- * again. That is a setState-in-a-passive-effect cascade; React's
140
- * NESTED_PASSIVE_UPDATE_LIMIT (50) trips and logs `Maximum update depth
141
- * exceeded` on every web load. It also costs two React renders per frame and
142
- * delays the captured image by two hops.
143
- *
144
- * `GameLoop` schedules via `requestAnimationFrame`, so calling `setImage`
145
- * directly from `onPreRender` is an ordinary root update that never touches the
146
- * passive-update counter. Both hooks still run on both platforms so hook order
147
- * never varies, but this hook is now inert on native simply because nothing
148
- * calls `capture` on that platform.
149
- *
150
- * `makeNonTextureImage()` is required regardless of reuse: the offscreen surface
151
- * has its own WebGL context, and a texture-backed image cannot be sampled by the
152
- * on-screen canvas's context. It also makes reuse safe — the snapshot is copied
153
- * off the GPU so next frame's draw into the same surface cannot disturb the image
154
- * React still holds.
155
- *
156
- * The surface is never cleared here: `Renderer.begin()` records
157
- * `canvas.clear(clearColor)` into the picture itself (packages/render
158
- * `renderer.ts:75`), so replaying the picture repaints the full surface.
159
- */
160
- function useWebSceneTexture(Skia) {
161
- const captureRef = (0, react.useRef)(null);
162
- const [image, setImage] = (0, react.useState)(null);
163
- (0, react.useEffect)(() => {
164
- return () => {
165
- captureRef.current?.dispose();
166
- captureRef.current = null;
167
- };
168
- }, []);
169
- return {
170
- image,
171
- capture: (0, react.useCallback)((picture, width, height) => {
172
- if (picture === null || picture === void 0) return;
173
- if (captureRef.current === null) captureRef.current = createSceneCapture(Skia);
174
- const next = captureRef.current.capture(picture, width, height);
175
- if (next !== null) setImage(next);
176
- }, [Skia])
177
- };
178
- }
179
134
  //#endregion
180
135
  //#region src/skia-bridge.ts
181
136
  /**
@@ -240,6 +195,38 @@ function unpackArgb(out, argb) {
240
195
  //#endregion
241
196
  //#region src/game-view.tsx
242
197
  /**
198
+ * Capture the frame's picture into an offscreen surface **on the UI thread**.
199
+ *
200
+ * The thread is the entire point, and getting it wrong is invisible to every
201
+ * test in this repo. RN-Skia's own `usePictureAsTexture` does exactly this work
202
+ * inside `runOnUI` (`external/reanimated/textures.ts`), and it must: a surface
203
+ * built on the JS thread belongs to a different GL context than the on-screen
204
+ * `<Canvas>`, so the `<Image>` samples nothing and the app renders a black
205
+ * frame while the game loop runs happily. Building the surface here — same
206
+ * thread, same context as the canvas that samples it — is what makes the
207
+ * snapshot drawable without a `makeNonTextureImage()` GPU→CPU readback.
208
+ *
209
+ * Verified on device (Pixel 7 / Android 17): JS-thread capture → black canvas;
210
+ * this path → renders. See external-review-2026-08.md §11.4b.
211
+ *
212
+ * The surface is cached across frames in a shared value rather than rebuilt per
213
+ * frame (RN-Skia rebuilds it every call; that is NEW-2). `surfaceKey` packs the
214
+ * pixel size so a viewport change reallocates exactly once.
215
+ */
216
+ const captureSceneOnUI = (target, surfaceSV, surfaceKey, picture, w, h) => {
217
+ "worklet";
218
+ const key = w * 65536 + h;
219
+ if (surfaceSV.value === null || surfaceKey.value !== key) {
220
+ surfaceSV.value = _shopify_react_native_skia.Skia.Surface.MakeOffscreen(w, h);
221
+ surfaceKey.value = key;
222
+ }
223
+ const surface = surfaceSV.value;
224
+ if (surface === null) return;
225
+ surface.getCanvas().drawPicture(picture);
226
+ surface.flush();
227
+ target.value = surface.makeImageSnapshot();
228
+ };
229
+ /**
243
230
  * GameView — root component that sets up the Skia canvas, game loop,
244
231
  * and all core game systems. Provides GameContext to descendants.
245
232
  *
@@ -247,28 +234,20 @@ function unpackArgb(out, argb) {
247
234
  * as children; they render on top of the Skia canvas.
248
235
  */
249
236
  function GameView({ config, onReady, style, children, safeArea }) {
250
- const insets = (0, react_native_safe_area_context.useSafeAreaInsets)();
251
- const resolvedSafeArea = safeArea ?? insets;
237
+ const contextInsets = (0, react.useContext)(react_native_safe_area_context.SafeAreaInsetsContext);
238
+ const resolvedSafeArea = safeArea ?? contextInsets ?? ZERO_INSETS;
252
239
  const canvasRef = (0, _shopify_react_native_skia.useCanvasRef)();
253
- const [picture, setPicture] = (0, react.useState)(null);
254
240
  const [passes, setPasses] = (0, react.useState)(EMPTY_PASSES);
255
241
  const [viewportSize, setViewportSize] = (0, react.useState)({
256
242
  w: 0,
257
243
  h: 0
258
244
  });
259
245
  const pd = react_native.PixelRatio.get();
260
- const sceneSize = (0, react.useMemo)(() => ({
261
- width: viewportSize.w * pd,
262
- height: viewportSize.h * pd
263
- }), [
264
- viewportSize.w,
265
- viewportSize.h,
266
- pd
267
- ]);
268
246
  const isWeb = react_native.Platform.OS === "web";
269
- const nativeTexture = (0, _shopify_react_native_skia.usePictureAsTexture)(isWeb ? null : picture, sceneSize);
270
- const { image: webTexture, capture: captureWebScene } = useWebSceneTexture(_shopify_react_native_skia.Skia);
271
- const sceneTexture = isWeb ? webTexture : nativeTexture;
247
+ const sceneImage = (0, react_native_reanimated.useSharedValue)(null);
248
+ const captureRef = (0, react.useRef)(null);
249
+ const uiSurface = (0, react_native_reanimated.useSharedValue)(null);
250
+ const uiSurfaceKey = (0, react_native_reanimated.useSharedValue)(0);
272
251
  const ctx = (0, react.useMemo)(() => {
273
252
  const loop = new _flare_engine_core.GameLoop({
274
253
  fixedDt: config?.fixedDt,
@@ -317,8 +296,14 @@ function GameView({ config, onReady, style, children, safeArea }) {
317
296
  if (onRenderPostFx) onRenderPostFx(ctx, ctx.renderer.canvas, bridge);
318
297
  ctx.renderer.end();
319
298
  const pic = bridge.endFrame();
320
- if (pic !== null) if (isWeb) captureWebScene(pic, w * pd, h * pd);
321
- else setPicture(pic);
299
+ if (pic !== null) if (isWeb) {
300
+ if (captureRef.current === null) captureRef.current = createSceneCapture(_shopify_react_native_skia.Skia, {
301
+ nonTextureImage: true,
302
+ retentionDepth: 3
303
+ });
304
+ const img = captureRef.current.capture(pic, w * pd, h * pd);
305
+ if (img !== null) sceneImage.value = img;
306
+ } else (0, react_native_worklets.scheduleOnUI)(captureSceneOnUI, sceneImage, uiSurface, uiSurfaceKey, pic, w * pd, h * pd);
322
307
  if (!isWeb) {
323
308
  const built = bridge.buildPostFxPasses(null, null, w, h);
324
309
  if (!samePasses(prevBuilt, built)) {
@@ -336,6 +321,8 @@ function GameView({ config, onReady, style, children, safeArea }) {
336
321
  return () => {
337
322
  unsubscribeLate();
338
323
  unsubscribePre();
324
+ captureRef.current?.dispose();
325
+ captureRef.current = null;
339
326
  ctx.loop.stop();
340
327
  };
341
328
  }, []);
@@ -348,13 +335,40 @@ function GameView({ config, onReady, style, children, safeArea }) {
348
335
  });
349
336
  }, [ctx]);
350
337
  const onGrant = (0, react.useCallback)((e) => {
351
- ctx.input.onPointerDown(0, e.nativeEvent.locationX, e.nativeEvent.locationY);
338
+ const { changedTouches, identifier, locationX, locationY } = e.nativeEvent;
339
+ if (changedTouches.length === 0) {
340
+ ctx.input.onPointerDown(Number(identifier), locationX, locationY);
341
+ return;
342
+ }
343
+ for (let i = 0; i < changedTouches.length; i++) {
344
+ const t = changedTouches[i];
345
+ if (t === void 0) continue;
346
+ ctx.input.onPointerDown(Number(t.identifier), t.locationX, t.locationY);
347
+ }
352
348
  }, [ctx]);
353
349
  const onMove = (0, react.useCallback)((e) => {
354
- ctx.input.onPointerMove(0, e.nativeEvent.locationX, e.nativeEvent.locationY);
350
+ const { changedTouches, identifier, locationX, locationY } = e.nativeEvent;
351
+ if (changedTouches.length === 0) {
352
+ ctx.input.onPointerMove(Number(identifier), locationX, locationY);
353
+ return;
354
+ }
355
+ for (let i = 0; i < changedTouches.length; i++) {
356
+ const t = changedTouches[i];
357
+ if (t === void 0) continue;
358
+ ctx.input.onPointerMove(Number(t.identifier), t.locationX, t.locationY);
359
+ }
355
360
  }, [ctx]);
356
361
  const onRelease = (0, react.useCallback)((e) => {
357
- ctx.input.onPointerUp(0, e.nativeEvent.locationX, e.nativeEvent.locationY);
362
+ const { changedTouches, identifier, locationX, locationY } = e.nativeEvent;
363
+ if (changedTouches.length === 0) {
364
+ ctx.input.onPointerUp(Number(identifier), locationX, locationY);
365
+ return;
366
+ }
367
+ for (let i = 0; i < changedTouches.length; i++) {
368
+ const t = changedTouches[i];
369
+ if (t === void 0) continue;
370
+ ctx.input.onPointerUp(Number(t.identifier), t.locationX, t.locationY);
371
+ }
358
372
  }, [ctx]);
359
373
  const containerStyle = (0, react.useMemo)(() => [styles$3.container, style], [style]);
360
374
  const passElements = (0, react.useMemo)(() => passes.map((p) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_shopify_react_native_skia.RuntimeShader, {
@@ -368,7 +382,7 @@ function GameView({ config, onReady, style, children, safeArea }) {
368
382
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_native.View, {
369
383
  style: containerStyle,
370
384
  onLayout: handleLayout,
371
- onStartShouldSetResponder: returnTrue$2,
385
+ onStartShouldSetResponder: returnTrue$1,
372
386
  onResponderGrant: onGrant,
373
387
  onResponderMove: onMove,
374
388
  onResponderRelease: onRelease,
@@ -378,8 +392,8 @@ function GameView({ config, onReady, style, children, safeArea }) {
378
392
  style: react_native.StyleSheet.absoluteFill,
379
393
  pointerEvents: "none",
380
394
  opaque: config?.opaque ?? false,
381
- children: viewportSize.w === 0 || sceneTexture == null ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_shopify_react_native_skia.Image, {
382
- image: sceneTexture,
395
+ children: viewportSize.w === 0 ? null : /* @__PURE__ */ (0, react_jsx_runtime.jsx)(_shopify_react_native_skia.Image, {
396
+ image: sceneImage,
383
397
  x: 0,
384
398
  y: 0,
385
399
  width: viewportSize.w,
@@ -392,12 +406,19 @@ function GameView({ config, onReady, style, children, safeArea }) {
392
406
  })
393
407
  });
394
408
  }
395
- function returnTrue$2() {
409
+ function returnTrue$1() {
396
410
  return true;
397
411
  }
398
412
  /** Stable empty-chain reference — an empty `buildPostFxPasses` result collapses
399
413
  * to this so the `passes` state never changes for a postfx-free GameView. */
400
414
  const EMPTY_PASSES = [];
415
+ /** Fallback insets when no `<SafeAreaProvider>` ancestor supplies a context value. */
416
+ const ZERO_INSETS = {
417
+ top: 0,
418
+ right: 0,
419
+ bottom: 0,
420
+ left: 0
421
+ };
401
422
  /**
402
423
  * Shallow structural equality of two pass lists. The signature is length +
403
424
  * per-pass `id` + shader ref + child-image refs + uniform values. Uniforms are
@@ -615,8 +636,9 @@ const skiaAtlasModule = _shopify_react_native_skia.Skia;
615
636
  /**
616
637
  * VirtualButton — an on-screen button overlay component.
617
638
  *
618
- * Claims the React Native touch responder so press/release fire reliably
619
- * even when an ancestor (e.g. <GameView>) also claims the responder.
639
+ * Uses raw `onTouchStart`/`onTouchEnd` so press and release fire regardless
640
+ * of which ancestor holds the RN responder — enabling simultaneous use with
641
+ * `<VirtualJoystick>` without responder conflicts.
620
642
  */
621
643
  function VirtualButton({ onStateChange, style, children }) {
622
644
  const stateRef = (0, react.useRef)((0, _flare_engine_input.createButtonState)());
@@ -632,16 +654,12 @@ function VirtualButton({ onStateChange, style, children }) {
632
654
  }, [onStateChange]);
633
655
  return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.View, {
634
656
  style: [styles$1.button, style],
635
- onStartShouldSetResponder: returnTrue$1,
636
- onResponderGrant: handlePress,
637
- onResponderRelease: handleRelease,
638
- onResponderTerminate: handleRelease,
657
+ onTouchStart: handlePress,
658
+ onTouchEnd: handleRelease,
659
+ onTouchCancel: handleRelease,
639
660
  children
640
661
  });
641
662
  }
642
- function returnTrue$1() {
643
- return true;
644
- }
645
663
  const styles$1 = react_native.StyleSheet.create({ button: {
646
664
  width: 60,
647
665
  height: 60,
@@ -713,6 +731,7 @@ function VirtualJoystick({ config, onStateChange, style, base, thumb }) {
713
731
  onResponderMove: handleTouch,
714
732
  onResponderRelease: handleRelease,
715
733
  onResponderTerminate: handleRelease,
734
+ onResponderTerminationRequest: returnFalse,
716
735
  children: [base ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_native.View, {
717
736
  style: react_native.StyleSheet.absoluteFill,
718
737
  pointerEvents: "none",
@@ -727,6 +746,9 @@ function VirtualJoystick({ config, onStateChange, style, base, thumb }) {
727
746
  function returnTrue() {
728
747
  return true;
729
748
  }
749
+ function returnFalse() {
750
+ return false;
751
+ }
730
752
  const styles = react_native.StyleSheet.create({
731
753
  center: {
732
754
  alignItems: "center",