@flare-engine/react 0.4.17 → 0.4.19

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
@@ -8,7 +8,7 @@ React Native integration — `<GameView>` (Skia Canvas + game loop + input), `<V
8
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-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.
11
+ Peer deps: `react` (>=19), `react-native` (>=0.79), `@shopify/react-native-skia` (>=2), `react-native-reanimated` (>=4; >=4.1.0 from 0.5.0: 4.1.x is the first line that supports worklets 0.7), `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
12
 
13
13
  > **The New Architecture is required.** Reanimated 4 is New-Architecture-only, so an app using
14
14
  > `<GameView>` must run with `newArchEnabled=true`. This costs nothing in practice — it has been
package/dist/index.d.mts CHANGED
@@ -193,28 +193,22 @@ interface GameConfig {
193
193
  onRenderPostFx?: PostFxRenderHook;
194
194
  /**
195
195
  * Promote the underlying Skia surface from a TextureView (default) to a
196
- * SurfaceView on Android. With `opaque: true`, SurfaceView paints in a
197
- * separate compositing layer below the regular RN view tree, which lets
198
- * full-screen RN overlays (HUDs, menus) render on top without needing
199
- * elevation/zIndex tricks.
196
+ * SurfaceView on Android. The SurfaceView paints in its own compositing
197
+ * layer below the RN view tree, so full-screen RN overlays (HUDs, menus)
198
+ * render on top without elevation/zIndex tricks; RN-Skia's TextureView can
199
+ * clip them on some Android devices/Fabric configurations.
200
200
  *
201
- * Without this, RN-Skia's TextureView can clip overlapping full-screen
202
- * RN siblings on certain Android devices/Fabric configurations.
201
+ * Implies opaque content: the clearColor's alpha must be 0xFF, as the
202
+ * default `0xff000000` is. Defaults to `false`.
203
203
  *
204
- * Implies the canvas content is opaque — the clearColor's alpha must be
205
- * fully opaque (0xFF), which the default `0xff000000` already satisfies.
206
- * Defaults to `false` to preserve the current iOS-equivalent behavior.
207
- *
208
- * **Recommended on Android.** Measured on a Pixel 7 (Android 17, release
209
- * build, XR-1c): with the default TextureView path RN-Skia logs its
210
- * `updateTexImage: LegacySurfaceTexture is not attached!` /
211
- * `updateAndRelease() failed` pair **22 028 times per 60 s** — 90% of all
212
- * logcat output, saturating the 256 KiB ring buffer so unrelated diagnostics
213
- * are lost. With `opaque: true` the same build over three 60 s windows logs
214
- * the pair **zero** times and total log volume drops ~10x. RN-Skia labels the
215
- * pair ignorable and rendering is correct either way, so this is log noise
216
- * and TextureView overhead, not a correctness fix. Native memory is flat
217
- * across a 6-minute soak on both paths.
204
+ * **Leave it `false` on Android unless overlays are clipped.** The
205
+ * SurfaceView's buffer queue stays full, so the loop gets every other vsync:
206
+ * on a Pixel 7 an empty scene looped at 45 Hz on a 90 Hz display and 30 Hz
207
+ * at 60 Hz, frames reaching the screen 40 ms after queueing, against the
208
+ * display rate and 22-33 ms by default (#545). The default's cost is log
209
+ * noise, not rendering or memory: RN-Skia logs `LegacySurfaceTexture is not
210
+ * attached!` and `updateAndRelease() failed` on every render. Filter them:
211
+ * `adb logcat | grep -vE "LegacySurfaceTexture|updateAndRelease"`.
218
212
  */
219
213
  opaque?: boolean;
220
214
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":["_$__skia_bridge_js0.SkiaFrameRenderer"],"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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OAAO;;;;;;;;wBA4BjB,YAAY,WAAW;;UC7CtB;;EAEf;;EAEA,QAAQ;;EAER;;EAEA;;EAEA;;;;;;;;;;wBAWc,gBACd,UACA,OACA,UACA,YACA,mBACC,qBAAqB,MAAM;wBCYd,eAAe,kBAAkB;wBAIjC,WAAW,gBAAgB;wBAI3B,eAAe,GAAG,QAAQ,OAAO,IAAI,SAAS,IAAI;;;;;qBC7CrD,iBAAiB;;UCMb;;EAEf,iBAAiB,OAAO;;EAExB,QAAQ;;EAER,WAAW,MAAM;;;;;;;;;wBAUH,gBACd,eACA,OACA,YACC,qBAAqB,MAAM;;UCpBb;;EAEf,SAAS;;EAET,iBAAiB,OAAO;;EAExB,QAAQ;;EAER,OAAO,MAAM;;EAEb,QAAQ,MAAM;;;;;;;;;wBAmBA,kBACd,QACA,eACA,OACA,MACA,SACC,uBAAuB,MAAM"}
1
+ {"version":3,"file":"index.d.mts","names":["_$__skia_bridge_js0.SkiaFrameRenderer"],"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;;;;;;qBAOI,6BAAW,QAAA;;UCpBP;EACf,YAAY;EACZ,cAAc,gBAAgB,cAAc,cAAc;EAC1D,SAAS,eAAe;EACxB,MAAM;;;UAIS;EACf,aAAa;EACb,qBAAqB;;;;EAIrB;;;;;;;UAQe;;WAEN;;WAEA,QAAQ;;;;;;WAMR,UAAU;;;;;;;;;;WAUV,mBAAmB;;;UAuBb;WACN;WACA;WACA;WACA;;WAEA;;;UAIM;WACN;WACA;;WAEA;WACA,iBAAiB;;;;;;;;;;KAWhB,iB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,QAAQ,MAAM;;;;;;;;;wBAmBA,kBACd,QACA,eACA,OACA,MACA,SACC,uBAAuB,MAAM"}
package/dist/index.d.ts CHANGED
@@ -193,28 +193,22 @@ interface GameConfig {
193
193
  onRenderPostFx?: PostFxRenderHook;
194
194
  /**
195
195
  * Promote the underlying Skia surface from a TextureView (default) to a
196
- * SurfaceView on Android. With `opaque: true`, SurfaceView paints in a
197
- * separate compositing layer below the regular RN view tree, which lets
198
- * full-screen RN overlays (HUDs, menus) render on top without needing
199
- * elevation/zIndex tricks.
196
+ * SurfaceView on Android. The SurfaceView paints in its own compositing
197
+ * layer below the RN view tree, so full-screen RN overlays (HUDs, menus)
198
+ * render on top without elevation/zIndex tricks; RN-Skia's TextureView can
199
+ * clip them on some Android devices/Fabric configurations.
200
200
  *
201
- * Without this, RN-Skia's TextureView can clip overlapping full-screen
202
- * RN siblings on certain Android devices/Fabric configurations.
201
+ * Implies opaque content: the clearColor's alpha must be 0xFF, as the
202
+ * default `0xff000000` is. Defaults to `false`.
203
203
  *
204
- * Implies the canvas content is opaque — the clearColor's alpha must be
205
- * fully opaque (0xFF), which the default `0xff000000` already satisfies.
206
- * Defaults to `false` to preserve the current iOS-equivalent behavior.
207
- *
208
- * **Recommended on Android.** Measured on a Pixel 7 (Android 17, release
209
- * build, XR-1c): with the default TextureView path RN-Skia logs its
210
- * `updateTexImage: LegacySurfaceTexture is not attached!` /
211
- * `updateAndRelease() failed` pair **22 028 times per 60 s** — 90% of all
212
- * logcat output, saturating the 256 KiB ring buffer so unrelated diagnostics
213
- * are lost. With `opaque: true` the same build over three 60 s windows logs
214
- * the pair **zero** times and total log volume drops ~10x. RN-Skia labels the
215
- * pair ignorable and rendering is correct either way, so this is log noise
216
- * and TextureView overhead, not a correctness fix. Native memory is flat
217
- * across a 6-minute soak on both paths.
204
+ * **Leave it `false` on Android unless overlays are clipped.** The
205
+ * SurfaceView's buffer queue stays full, so the loop gets every other vsync:
206
+ * on a Pixel 7 an empty scene looped at 45 Hz on a 90 Hz display and 30 Hz
207
+ * at 60 Hz, frames reaching the screen 40 ms after queueing, against the
208
+ * display rate and 22-33 ms by default (#545). The default's cost is log
209
+ * noise, not rendering or memory: RN-Skia logs `LegacySurfaceTexture is not
210
+ * attached!` and `updateAndRelease() failed` on every render. Filter them:
211
+ * `adb logcat | grep -vE "LegacySurfaceTexture|updateAndRelease"`.
218
212
  */
219
213
  opaque?: boolean;
220
214
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":["_$__skia_bridge_js0.SkiaFrameRenderer"],"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;;;;;;qBAOI,6BAAW,QAAA;;UCpBP;EACf,YAAY;EACZ,cAAc,gBAAgB,cAAc,cAAc;EAC1D,SAAS,eAAe;EACxB,MAAM;;;UAIS;EACf,aAAa;EACb,qBAAqB;;;;EAIrB;;;;;;;UAQe;;WAEN;;WAEA,QAAQ;;;;;;WAMR,UAAU;;;;;;;;;;WAUV,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;;;;;;;;;;;wBAYhB,wBAAwB,MAAM,iBAAiB;;;;;;;wBAc/C,oBACd,MAAM,gBACN,MAAM,mBACL;UC5Kc;EACf;EACA;EACA;EACA;;qBAGW,iCAAe,QAAA;wBAEZ,eAAe;;;;;KC0EnB,cAAc,KAAK,kBAAkB;;;;;;;;KASrC,oBACV,KAAK,kBACL,iBACA,QAFKA;;UAMU;;EAEf;;EAEA;;EAEA;;EAEA,cAAc;;;EAGd,qBAAqB;;;;;EAKrB,iBAAiB;;;;;;;;;;;;;;;;;;;;;;;;;;EA0BjB;;;UAIe;;EAEf,SAAS;;EAET,WAAW,KAAK;;EAEhB,QAAQ;;EAER,WAAW,MAAM;;;;EAIjB,WAAW;;;;;;;;;wBAUG,WACd,QACA,SACA,OACA,UACA,YACC,gBAAgB,MAAM;;;;;wBCvKT,WAAW;;;;;;;wBAcX,UAAU,OAAO;;;;;;;;wBA4BjB,YAAY,WAAW;;UC7CtB;;EAEf;;EAEA,QAAQ;;EAER;;EAEA;;EAEA;;;;;;;;;;wBAWc,gBACd,UACA,OACA,UACA,YACA,mBACC,qBAAqB,MAAM;wBCYd,eAAe,kBAAkB;wBAIjC,WAAW,gBAAgB;wBAI3B,eAAe,GAAG,QAAQ,OAAO,IAAI,SAAS,IAAI;;;;;qBC7CrD,iBAAiB;;UCMb;;EAEf,iBAAiB,OAAO;;EAExB,QAAQ;;EAER,WAAW,MAAM;;;;;;;;;wBAUH,gBACd,eACA,OACA,YACC,qBAAqB,MAAM;;UCpBb;;EAEf,SAAS;;EAET,iBAAiB,OAAO;;EAExB,QAAQ;;EAER,OAAO,MAAM;;EAEb,QAAQ,MAAM;;;;;;;;;wBAmBA,kBACd,QACA,eACA,OACA,MACA,SACC,uBAAuB,MAAM"}
1
+ {"version":3,"file":"index.d.ts","names":["_$__skia_bridge_js0.SkiaFrameRenderer"],"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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gB,MAAM;;;;;wBClKT,WAAW;;;;;;;wBAcX,UAAU,OAAO;;;;;;;;wBA4BjB,YAAY,WAAW;;UC7CtB;;EAEf;;EAEA,QAAQ;;EAER;;EAEA;;EAEA;;;;;;;;;;wBAWc,gBACd,UACA,OACA,UACA,YACA,mBACC,qBAAqB,MAAM;wBCYd,eAAe,kBAAkB;wBAIjC,WAAW,gBAAgB;wBAI3B,eAAe,GAAG,QAAQ,OAAO,IAAI,SAAS,IAAI;;;;;qBC7CrD,iBAAiB;;UCMb;;EAEf,iBAAiB,OAAO;;EAExB,QAAQ;;EAER,WAAW,MAAM;;;;;;;;;wBAUH,gBACd,eACA,OACA,YACC,qBAAqB,MAAM;;UCpBb;;EAEf,SAAS;;EAET,iBAAiB,OAAO;;EAExB,QAAQ;;EAER,OAAO,MAAM;;EAEb,QAAQ,MAAM;;;;;;;;;wBAmBA,kBACd,QACA,eACA,OACA,MACA,SACC,uBAAuB,MAAM"}
package/dist/index.js CHANGED
@@ -20,6 +20,66 @@ let react_jsx_runtime = require("react/jsx-runtime");
20
20
  * Null if accessed outside a <GameView>.
21
21
  */
22
22
  const GameContext = (0, react.createContext)(null);
23
+ // src/context-loss.ts
24
+ const LOST = "webglcontextlost";
25
+ const RESTORED = "webglcontextrestored";
26
+ /**
27
+ * Watch a canvas for `webglcontextlost` / `webglcontextrestored`.
28
+ *
29
+ * `onRecover` runs once per loss: at the restore event, or at the first
30
+ * `flush()` after the loss when no restore has arrived by then. The listeners
31
+ * come off the canvas **before** `onRecover` runs. The caller answers by
32
+ * unmounting that canvas, and RN-Skia's web view calls `loseContext()` on the
33
+ * canvas it unmounts; with the listeners still on, that loss would start a
34
+ * second recovery and the remount would loop.
35
+ */
36
+ function createContextLossWatch(onRecover) {
37
+ let target = null;
38
+ let lost = false;
39
+ const onLost = (event) => {
40
+ event.preventDefault();
41
+ lost = true;
42
+ };
43
+ const onRestored = () => {
44
+ if (lost) recover();
45
+ };
46
+ const detach = () => {
47
+ lost = false;
48
+ if (target === null) return;
49
+ target.removeEventListener(LOST, onLost);
50
+ target.removeEventListener(RESTORED, onRestored);
51
+ target = null;
52
+ };
53
+ const recover = () => {
54
+ detach();
55
+ onRecover();
56
+ };
57
+ return {
58
+ attach(next) {
59
+ if (next === target) return;
60
+ detach();
61
+ if (next === null) return;
62
+ target = next;
63
+ next.addEventListener(LOST, onLost);
64
+ next.addEventListener(RESTORED, onRestored);
65
+ },
66
+ flush() {
67
+ if (lost) recover();
68
+ },
69
+ detach
70
+ };
71
+ }
72
+ /**
73
+ * The first `<canvas>` under `host`, or null when `host` is not a DOM element
74
+ * or holds none. `host` is `unknown` because the caller's ref is typed as a
75
+ * React Native `View`, which is a DOM element only under react-native-web.
76
+ */
77
+ function findContextLossTarget(host) {
78
+ if (typeof host !== "object" || host === null) return null;
79
+ const query = host.querySelector;
80
+ if (typeof query !== "function") return null;
81
+ return query.call(host, "canvas");
82
+ }
23
83
  // src/safe-area.ts
24
84
  const SafeAreaContext = (0, react.createContext)(null);
25
85
  function useSafeArea() {
@@ -314,6 +374,14 @@ function GameView({ config, onReady, style, children, safeArea }) {
314
374
  const captureRef = (0, react.useRef)(null);
315
375
  const uiSurface = (0, react_native_reanimated.useSharedValue)(null);
316
376
  const uiSurfaceKey = (0, react_native_reanimated.useSharedValue)(0);
377
+ const containerRef = (0, react.useRef)(null);
378
+ const [canvasEpoch, setCanvasEpoch] = (0, react.useState)(0);
379
+ const lossWatch = (0, react.useMemo)(() => createContextLossWatch(() => {
380
+ captureRef.current?.dispose();
381
+ captureRef.current = null;
382
+ sceneImage.value = null;
383
+ setCanvasEpoch(nextEpoch);
384
+ }), [sceneImage]);
317
385
  const ctx = (0, react.useMemo)(() => {
318
386
  const loop = new _flare_engine_core.GameLoop({
319
387
  fixedDt: config?.fixedDt,
@@ -353,6 +421,7 @@ function GameView({ config, onReady, style, children, safeArea }) {
353
421
  pdRef.current = react_native.PixelRatio.get();
354
422
  });
355
423
  const unsubscribePre = ctx.loop.onPreRender.add(() => {
424
+ if (isWeb) lossWatch.flush();
356
425
  const w = ctx.camera.viewportWidth;
357
426
  const h = ctx.camera.viewportHeight;
358
427
  const pd = pdRef.current;
@@ -403,6 +472,15 @@ function GameView({ config, onReady, style, children, safeArea }) {
403
472
  ctx.loop.stop();
404
473
  };
405
474
  }, []);
475
+ (0, react.useEffect)(() => {
476
+ if (!isWeb) return void 0;
477
+ lossWatch.attach(findContextLossTarget(containerRef.current));
478
+ return lossWatch.detach;
479
+ }, [
480
+ canvasEpoch,
481
+ isWeb,
482
+ lossWatch
483
+ ]);
406
484
  const handleLayout = (0, react.useCallback)((event) => {
407
485
  const { width, height } = event.nativeEvent.layout;
408
486
  ctx.camera.setViewport(width, height);
@@ -520,6 +598,7 @@ function GameView({ config, onReady, style, children, safeArea }) {
520
598
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GameContext.Provider, {
521
599
  value: ctx,
522
600
  children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_native.View, {
601
+ ref: containerRef,
523
602
  style: containerStyle,
524
603
  onLayout: handleLayout,
525
604
  onStartShouldSetResponder: returnTrue$1,
@@ -533,7 +612,7 @@ function GameView({ config, onReady, style, children, safeArea }) {
533
612
  pointerEvents: "none",
534
613
  opaque: config?.opaque ?? false,
535
614
  children: canvasContent
536
- }), children]
615
+ }, canvasEpoch), children]
537
616
  })
538
617
  })
539
618
  });
@@ -541,6 +620,10 @@ function GameView({ config, onReady, style, children, safeArea }) {
541
620
  function returnTrue$1() {
542
621
  return true;
543
622
  }
623
+ /** State updater for the `<Canvas>` key — module-level so a recovery allocates no closure. */
624
+ function nextEpoch(epoch) {
625
+ return epoch + 1;
626
+ }
544
627
  /** Stable empty-chain reference — an empty `buildPostFxPasses` result collapses
545
628
  * to this so the `passes` state never changes for a postfx-free GameView. */
546
629
  const EMPTY_PASSES = [];