@tastic/hud 0.29.0 → 0.30.1
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 +22 -5
- package/dist/chrome/index.d.mts +2 -1
- package/dist/chrome/index.d.ts +2 -1
- package/dist/chrome/index.js +14 -5
- package/dist/chrome/index.mjs +1 -1
- package/dist/{chunk-ACY6UK4V.mjs → chunk-4666H2UG.mjs} +15 -6
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +14 -5
- package/dist/index.mjs +5 -5
- package/dist/locateSkiaWebFile-DAJ0ok2i.d.mts +5 -0
- package/dist/locateSkiaWebFile-DAJ0ok2i.d.ts +5 -0
- package/dist/skia/index.d.mts +6 -3
- package/dist/skia/index.d.ts +6 -3
- package/dist/skia/index.js +12 -0
- package/dist/skia/index.mjs +11 -0
- package/package.json +3 -3
- package/src/BaseSettingsDialog.tsx +30 -7
- package/src/skia/index.ts +4 -2
- package/src/skia/lazySkia.tsx +27 -0
package/README.md
CHANGED
|
@@ -268,6 +268,11 @@ export function SettingsDialog({ visible, onDismiss, rotation = 0, settings, set
|
|
|
268
268
|
}
|
|
269
269
|
```
|
|
270
270
|
|
|
271
|
+
A game with music passes `showMusic`, which adds a Music toggle beside Sound and Haptics. It flips
|
|
272
|
+
`@rific/feedback-press`'s Music setting (`useMusicSettings`, 0.14.0+), which its `useMusic` tracks
|
|
273
|
+
follow; it's apart from Sound, so a player can keep the effects and turn the music off. Hidden unless
|
|
274
|
+
asked for, since most games have no music.
|
|
275
|
+
|
|
271
276
|
## Overlay cards (`OverlayCard`, `OverlayBackdrop`, `useOverlayCardColors`)
|
|
272
277
|
|
|
273
278
|
`ConfirmDialog` and `HowToPlayDialog` draw their card and the dim behind it with these, and a game's
|
|
@@ -742,11 +747,19 @@ export default function BoardHost(props: BoardProps) {
|
|
|
742
747
|
|
|
743
748
|
```tsx
|
|
744
749
|
// BoardHost.web.tsx: web imports the board only once CanvasKit has loaded
|
|
745
|
-
import {
|
|
746
|
-
import { lazy, Suspense } from 'react'
|
|
750
|
+
import { lazySkia } from '@tastic/hud/skia'
|
|
747
751
|
|
|
748
752
|
import type { BoardProps } from './Board'
|
|
749
753
|
|
|
754
|
+
export default lazySkia<BoardProps>(() => import('./Board').then((m) => ({ default: m.Board })))
|
|
755
|
+
```
|
|
756
|
+
|
|
757
|
+
`lazySkia<P extends object>(load: () => Promise<{ default: ComponentType<P> }>): ComponentType<P>` returns a
|
|
758
|
+
component that renders a `React.lazy` over `loadSkiaWeb().then(load)` inside a `Suspense` with a `null`
|
|
759
|
+
fallback: nothing is drawn, and the board's module isn't even imported, until CanvasKit has loaded. Its
|
|
760
|
+
props pass straight through to the board. Written out by hand, it is:
|
|
761
|
+
|
|
762
|
+
```tsx
|
|
750
763
|
const LazyBoard = lazy(() => loadSkiaWeb().then(() => import('./Board').then((m) => ({ default: m.Board }))))
|
|
751
764
|
|
|
752
765
|
export default function BoardHost(props: BoardProps) {
|
|
@@ -759,9 +772,13 @@ export default function BoardHost(props: BoardProps) {
|
|
|
759
772
|
```
|
|
760
773
|
|
|
761
774
|
- Import the host, never `Board` itself, everywhere else in the app.
|
|
762
|
-
-
|
|
763
|
-
|
|
764
|
-
|
|
775
|
+
- Call `lazySkia` at module scope, as above, so the component is created once. Called during a render, it
|
|
776
|
+
would be a new component every time, remounting the board.
|
|
777
|
+
- Import from `@tastic/hud/skia`. It carries none of the main entry's heavier peers (only `react`), so it
|
|
778
|
+
works in every app. `loadSkiaWeb` and `locateSkiaWebFile` are also exported from `@tastic/hud`;
|
|
779
|
+
`lazySkia` is only on `@tastic/hud/skia`.
|
|
780
|
+
- PuckTastic and DuelTastic each had an identical copy of `lazySkia` (`src/shared/lazySkia.tsx`); they
|
|
781
|
+
switch to this one when they take the release that has it.
|
|
765
782
|
- A test that imports a native host imports Skia, which throws under Jest (no native bindings). Mock the
|
|
766
783
|
host, or don't import the screen that uses it.
|
|
767
784
|
|
package/dist/chrome/index.d.mts
CHANGED
|
@@ -57,6 +57,7 @@ interface BaseSettingsDialogProps {
|
|
|
57
57
|
onDeferBottomEdgeGestures?: (value: boolean) => void;
|
|
58
58
|
hideSound?: boolean;
|
|
59
59
|
hideHaptics?: boolean;
|
|
60
|
+
showMusic?: boolean;
|
|
60
61
|
hideAppearance?: boolean;
|
|
61
62
|
hideUpdateCheck?: boolean;
|
|
62
63
|
onUpdateError?: (message: string) => void;
|
|
@@ -64,7 +65,7 @@ interface BaseSettingsDialogProps {
|
|
|
64
65
|
children?: ReactNode;
|
|
65
66
|
leading?: ReactNode;
|
|
66
67
|
}
|
|
67
|
-
declare function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, version, lockOrientation, onLockOrientationChange, deferBottomEdgeGestures, onDeferBottomEdgeGestures, hideSound, hideHaptics, hideAppearance, hideUpdateCheck, onUpdateError, onShowHowToPlay, children, leading }: BaseSettingsDialogProps): react.JSX.Element | null;
|
|
68
|
+
declare function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, version, lockOrientation, onLockOrientationChange, deferBottomEdgeGestures, onDeferBottomEdgeGestures, hideSound, hideHaptics, showMusic, hideAppearance, hideUpdateCheck, onUpdateError, onShowHowToPlay, children, leading }: BaseSettingsDialogProps): react.JSX.Element | null;
|
|
68
69
|
|
|
69
70
|
type MD3TextVariant = 'displayLarge' | 'displayMedium' | 'displaySmall' | 'headlineLarge' | 'headlineMedium' | 'headlineSmall' | 'titleLarge' | 'titleMedium' | 'titleSmall' | 'labelLarge' | 'labelMedium' | 'labelSmall' | 'bodyLarge' | 'bodyMedium' | 'bodySmall';
|
|
70
71
|
interface Props$7 {
|
package/dist/chrome/index.d.ts
CHANGED
|
@@ -57,6 +57,7 @@ interface BaseSettingsDialogProps {
|
|
|
57
57
|
onDeferBottomEdgeGestures?: (value: boolean) => void;
|
|
58
58
|
hideSound?: boolean;
|
|
59
59
|
hideHaptics?: boolean;
|
|
60
|
+
showMusic?: boolean;
|
|
60
61
|
hideAppearance?: boolean;
|
|
61
62
|
hideUpdateCheck?: boolean;
|
|
62
63
|
onUpdateError?: (message: string) => void;
|
|
@@ -64,7 +65,7 @@ interface BaseSettingsDialogProps {
|
|
|
64
65
|
children?: ReactNode;
|
|
65
66
|
leading?: ReactNode;
|
|
66
67
|
}
|
|
67
|
-
declare function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, version, lockOrientation, onLockOrientationChange, deferBottomEdgeGestures, onDeferBottomEdgeGestures, hideSound, hideHaptics, hideAppearance, hideUpdateCheck, onUpdateError, onShowHowToPlay, children, leading }: BaseSettingsDialogProps): react.JSX.Element | null;
|
|
68
|
+
declare function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, version, lockOrientation, onLockOrientationChange, deferBottomEdgeGestures, onDeferBottomEdgeGestures, hideSound, hideHaptics, showMusic, hideAppearance, hideUpdateCheck, onUpdateError, onShowHowToPlay, children, leading }: BaseSettingsDialogProps): react.JSX.Element | null;
|
|
68
69
|
|
|
69
70
|
type MD3TextVariant = 'displayLarge' | 'displayMedium' | 'displaySmall' | 'headlineLarge' | 'headlineMedium' | 'headlineSmall' | 'titleLarge' | 'titleMedium' | 'titleSmall' | 'labelLarge' | 'labelMedium' | 'labelSmall' | 'bodyLarge' | 'bodyMedium' | 'bodySmall';
|
|
70
71
|
interface Props$7 {
|
package/dist/chrome/index.js
CHANGED
|
@@ -515,7 +515,7 @@ var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
|
515
515
|
function SettingIcon({ source, color, containerColor }) {
|
|
516
516
|
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react_native12.View, { style: [styles9.iconBadge, { backgroundColor: containerColor }], children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react_native_paper8.Icon, { source, size: 18, color }) });
|
|
517
517
|
}
|
|
518
|
-
function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, version, lockOrientation, onLockOrientationChange, deferBottomEdgeGestures, onDeferBottomEdgeGestures, hideSound = false, hideHaptics = false, hideAppearance = false, hideUpdateCheck = false, onUpdateError, onShowHowToPlay, children, leading }) {
|
|
518
|
+
function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, version, lockOrientation, onLockOrientationChange, deferBottomEdgeGestures, onDeferBottomEdgeGestures, hideSound = false, hideHaptics = false, showMusic = false, hideAppearance = false, hideUpdateCheck = false, onUpdateError, onShowHowToPlay, children, leading }) {
|
|
519
519
|
const { colors } = (0, import_auto_paper6.useAutoPaperTheme)();
|
|
520
520
|
const ambientRotation = (0, import_core5.useRotation)();
|
|
521
521
|
const rotation = rotationOverride ?? ambientRotation;
|
|
@@ -527,6 +527,7 @@ function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, ve
|
|
|
527
527
|
const isTouchPrimary = (0, import_core5.useIsTouchPrimaryDevice)();
|
|
528
528
|
const { settings: hapticSettings, set: setHapticSettings } = (0, import_feedback_press3.useHapticSettings)();
|
|
529
529
|
const { settings: soundSettings, set: setSoundSettings } = (0, import_feedback_press3.useSoundSettings)();
|
|
530
|
+
const { settings: musicSettings, set: setMusicSettings } = (0, import_feedback_press3.useMusicSettings)();
|
|
530
531
|
const { settings: keepAwakeSettings, set: setKeepAwakeSettings } = (0, import_core4.useKeepAwakeSettings)();
|
|
531
532
|
const expoKeepAwake = (0, import_core4.useExpoKeepAwake)();
|
|
532
533
|
const sound = (0, import_react6.useContext)(import_feedback_press3.SoundContext);
|
|
@@ -584,7 +585,7 @@ function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, ve
|
|
|
584
585
|
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react_native_paper8.Text, { variant: "bodySmall", numberOfLines: 1, style: { color: colors.onSurfaceVariant }, children: "Stop auto-lock mid-match" })
|
|
585
586
|
] })
|
|
586
587
|
] }) }),
|
|
587
|
-
(showSound || showHaptics) && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_react_native12.View, { style: styles9.toggleRow, children: [
|
|
588
|
+
(showSound || showMusic || showHaptics) && /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_react_native12.View, { style: styles9.toggleRow, children: [
|
|
588
589
|
showSound && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
589
590
|
import_feedback_press3.TouchableRipple,
|
|
590
591
|
{
|
|
@@ -602,6 +603,10 @@ function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, ve
|
|
|
602
603
|
] })
|
|
603
604
|
}
|
|
604
605
|
),
|
|
606
|
+
showMusic && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_feedback_press3.TouchableRipple, { onPress: () => setMusicSettings({ enabled: !musicSettings.enabled }), style: styles9.toggleButtonInRow, accessibilityLabel: `Music ${musicSettings.enabled ? "on" : "off"}`, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_react_native12.View, { style: styles9.toggleContent, children: [
|
|
607
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(SettingIcon, { source: musicSettings.enabled ? "music" : "music-off", color: musicSettings.enabled ? colors.tertiary : colors.onSurfaceVariant, containerColor: musicSettings.enabled ? colors.tertiaryContainer : colors.surfaceVariant }),
|
|
608
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_react_native_paper8.Text, { variant: "bodyLarge", style: { color: colors.onSurface }, children: "Music" })
|
|
609
|
+
] }) }),
|
|
605
610
|
showHaptics && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
606
611
|
import_feedback_press3.TouchableRipple,
|
|
607
612
|
{
|
|
@@ -728,11 +733,14 @@ var styles9 = import_react_native12.StyleSheet.create({
|
|
|
728
733
|
overflow: "hidden",
|
|
729
734
|
paddingVertical: 10
|
|
730
735
|
},
|
|
731
|
-
// Same shape as toggleButton,
|
|
732
|
-
// toggleRow share the row's own edge alignment instead of each carrying their own.
|
|
736
|
+
// Same shape as toggleButton, half the row instead of its own width - two of these side by side in
|
|
737
|
+
// toggleRow share the row's own edge alignment instead of each carrying their own. Two to a row:
|
|
738
|
+
// three (Sound, Music, Haptics) don't fit across a phone's dialog (Haptics was cut off on a 402pt
|
|
739
|
+
// iPhone), so a third wraps onto its own row and grows to fill it, like the full-width rows above.
|
|
733
740
|
toggleButtonInRow: {
|
|
734
741
|
borderRadius: 12,
|
|
735
|
-
|
|
742
|
+
flexBasis: "45%",
|
|
743
|
+
flexGrow: 1,
|
|
736
744
|
overflow: "hidden",
|
|
737
745
|
paddingVertical: 10
|
|
738
746
|
},
|
|
@@ -751,6 +759,7 @@ var styles9 = import_react_native12.StyleSheet.create({
|
|
|
751
759
|
// No horizontal margin of its own now either - see toggleButton's identical note.
|
|
752
760
|
toggleRow: {
|
|
753
761
|
flexDirection: "row",
|
|
762
|
+
flexWrap: "wrap",
|
|
754
763
|
gap: 4
|
|
755
764
|
}
|
|
756
765
|
});
|
package/dist/chrome/index.mjs
CHANGED
|
@@ -282,7 +282,7 @@ var styles6 = StyleSheet6.create({
|
|
|
282
282
|
// src/BaseSettingsDialog.tsx
|
|
283
283
|
import { AutoAppearancePicker, Dialog, FadingScrollView, useAutoPaperTheme as useAutoPaperTheme4, useBlurModule, useThemeSettings } from "@rific/auto-paper";
|
|
284
284
|
import { useExpoKeepAwake, useKeepAwakeSettings } from "@rific/core";
|
|
285
|
-
import { Button as Button2, SoundContext, TouchableRipple, useHapticSettings, useSoundSettings, useVibration } from "@rific/feedback-press";
|
|
285
|
+
import { Button as Button2, SoundContext, TouchableRipple, useHapticSettings, useMusicSettings, useSoundSettings, useVibration } from "@rific/feedback-press";
|
|
286
286
|
import { useUpdater } from "@rific/updater";
|
|
287
287
|
import { rotateInsets as rotateInsets2, useIsTouchPrimaryDevice, useRotation as useRotation2 } from "@tastic/core";
|
|
288
288
|
import { useContext, useState as useState3 } from "react";
|
|
@@ -315,7 +315,7 @@ import { jsx as jsx8, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
|
315
315
|
function SettingIcon({ source, color, containerColor }) {
|
|
316
316
|
return /* @__PURE__ */ jsx8(View6, { style: [styles7.iconBadge, { backgroundColor: containerColor }], children: /* @__PURE__ */ jsx8(Icon2, { source, size: 18, color }) });
|
|
317
317
|
}
|
|
318
|
-
function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, version, lockOrientation, onLockOrientationChange, deferBottomEdgeGestures, onDeferBottomEdgeGestures, hideSound = false, hideHaptics = false, hideAppearance = false, hideUpdateCheck = false, onUpdateError, onShowHowToPlay, children, leading }) {
|
|
318
|
+
function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, version, lockOrientation, onLockOrientationChange, deferBottomEdgeGestures, onDeferBottomEdgeGestures, hideSound = false, hideHaptics = false, showMusic = false, hideAppearance = false, hideUpdateCheck = false, onUpdateError, onShowHowToPlay, children, leading }) {
|
|
319
319
|
const { colors } = useAutoPaperTheme4();
|
|
320
320
|
const ambientRotation = useRotation2();
|
|
321
321
|
const rotation = rotationOverride ?? ambientRotation;
|
|
@@ -327,6 +327,7 @@ function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, ve
|
|
|
327
327
|
const isTouchPrimary = useIsTouchPrimaryDevice();
|
|
328
328
|
const { settings: hapticSettings, set: setHapticSettings } = useHapticSettings();
|
|
329
329
|
const { settings: soundSettings, set: setSoundSettings } = useSoundSettings();
|
|
330
|
+
const { settings: musicSettings, set: setMusicSettings } = useMusicSettings();
|
|
330
331
|
const { settings: keepAwakeSettings, set: setKeepAwakeSettings } = useKeepAwakeSettings();
|
|
331
332
|
const expoKeepAwake = useExpoKeepAwake();
|
|
332
333
|
const sound = useContext(SoundContext);
|
|
@@ -384,7 +385,7 @@ function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, ve
|
|
|
384
385
|
/* @__PURE__ */ jsx8(Text6, { variant: "bodySmall", numberOfLines: 1, style: { color: colors.onSurfaceVariant }, children: "Stop auto-lock mid-match" })
|
|
385
386
|
] })
|
|
386
387
|
] }) }),
|
|
387
|
-
(showSound || showHaptics) && /* @__PURE__ */ jsxs7(View6, { style: styles7.toggleRow, children: [
|
|
388
|
+
(showSound || showMusic || showHaptics) && /* @__PURE__ */ jsxs7(View6, { style: styles7.toggleRow, children: [
|
|
388
389
|
showSound && /* @__PURE__ */ jsx8(
|
|
389
390
|
TouchableRipple,
|
|
390
391
|
{
|
|
@@ -402,6 +403,10 @@ function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, ve
|
|
|
402
403
|
] })
|
|
403
404
|
}
|
|
404
405
|
),
|
|
406
|
+
showMusic && /* @__PURE__ */ jsx8(TouchableRipple, { onPress: () => setMusicSettings({ enabled: !musicSettings.enabled }), style: styles7.toggleButtonInRow, accessibilityLabel: `Music ${musicSettings.enabled ? "on" : "off"}`, children: /* @__PURE__ */ jsxs7(View6, { style: styles7.toggleContent, children: [
|
|
407
|
+
/* @__PURE__ */ jsx8(SettingIcon, { source: musicSettings.enabled ? "music" : "music-off", color: musicSettings.enabled ? colors.tertiary : colors.onSurfaceVariant, containerColor: musicSettings.enabled ? colors.tertiaryContainer : colors.surfaceVariant }),
|
|
408
|
+
/* @__PURE__ */ jsx8(Text6, { variant: "bodyLarge", style: { color: colors.onSurface }, children: "Music" })
|
|
409
|
+
] }) }),
|
|
405
410
|
showHaptics && /* @__PURE__ */ jsx8(
|
|
406
411
|
TouchableRipple,
|
|
407
412
|
{
|
|
@@ -528,11 +533,14 @@ var styles7 = StyleSheet7.create({
|
|
|
528
533
|
overflow: "hidden",
|
|
529
534
|
paddingVertical: 10
|
|
530
535
|
},
|
|
531
|
-
// Same shape as toggleButton,
|
|
532
|
-
// toggleRow share the row's own edge alignment instead of each carrying their own.
|
|
536
|
+
// Same shape as toggleButton, half the row instead of its own width - two of these side by side in
|
|
537
|
+
// toggleRow share the row's own edge alignment instead of each carrying their own. Two to a row:
|
|
538
|
+
// three (Sound, Music, Haptics) don't fit across a phone's dialog (Haptics was cut off on a 402pt
|
|
539
|
+
// iPhone), so a third wraps onto its own row and grows to fill it, like the full-width rows above.
|
|
533
540
|
toggleButtonInRow: {
|
|
534
541
|
borderRadius: 12,
|
|
535
|
-
|
|
542
|
+
flexBasis: "45%",
|
|
543
|
+
flexGrow: 1,
|
|
536
544
|
overflow: "hidden",
|
|
537
545
|
paddingVertical: 10
|
|
538
546
|
},
|
|
@@ -551,6 +559,7 @@ var styles7 = StyleSheet7.create({
|
|
|
551
559
|
// No horizontal margin of its own now either - see toggleButton's identical note.
|
|
552
560
|
toggleRow: {
|
|
553
561
|
flexDirection: "row",
|
|
562
|
+
flexWrap: "wrap",
|
|
554
563
|
gap: 4
|
|
555
564
|
}
|
|
556
565
|
});
|
package/dist/index.d.mts
CHANGED
|
@@ -7,7 +7,7 @@ import { M as MenuOption } from './index-BOMA2rLU.mjs';
|
|
|
7
7
|
export { L as LABELED_DROPDOWN_POPOVER_WIDTH, a as LabeledDropdown, b as LabeledDropdownOption, P as PlayerSetupPanel, c as PlayerSetupPanelProps, R as ReadyButton, S as SharedActionBand, g as getColorPopoverId, d as getCpuDifficultyPopoverId, e as getLabeledDropdownContentHeight, f as getProfilePopoverId, u as useZoneClampedAlign } from './index-BOMA2rLU.mjs';
|
|
8
8
|
import { P as PopoverHost, A as AlignResult, a as PopoverRotation } from './usePopoverHost-T8QWb2_A.mjs';
|
|
9
9
|
export { b as PopoverAlign, c as PopoverVerticalAlign, V as ViewInstance, u as useAutoAlign, d as usePopoverHost } from './usePopoverHost-T8QWb2_A.mjs';
|
|
10
|
-
export { loadSkiaWeb, locateSkiaWebFile } from './
|
|
10
|
+
export { l as loadSkiaWeb, a as locateSkiaWebFile } from './locateSkiaWebFile-DAJ0ok2i.mjs';
|
|
11
11
|
import '@tastic/core';
|
|
12
12
|
import '@rific/auto-paper';
|
|
13
13
|
import '@rific/feedback-press';
|
package/dist/index.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import { M as MenuOption } from './index-B2sz-9jr.js';
|
|
|
7
7
|
export { L as LABELED_DROPDOWN_POPOVER_WIDTH, a as LabeledDropdown, b as LabeledDropdownOption, P as PlayerSetupPanel, c as PlayerSetupPanelProps, R as ReadyButton, S as SharedActionBand, g as getColorPopoverId, d as getCpuDifficultyPopoverId, e as getLabeledDropdownContentHeight, f as getProfilePopoverId, u as useZoneClampedAlign } from './index-B2sz-9jr.js';
|
|
8
8
|
import { P as PopoverHost, A as AlignResult, a as PopoverRotation } from './usePopoverHost-T8QWb2_A.js';
|
|
9
9
|
export { b as PopoverAlign, c as PopoverVerticalAlign, V as ViewInstance, u as useAutoAlign, d as usePopoverHost } from './usePopoverHost-T8QWb2_A.js';
|
|
10
|
-
export { loadSkiaWeb, locateSkiaWebFile } from './
|
|
10
|
+
export { l as loadSkiaWeb, a as locateSkiaWebFile } from './locateSkiaWebFile-DAJ0ok2i.js';
|
|
11
11
|
import '@tastic/core';
|
|
12
12
|
import '@rific/auto-paper';
|
|
13
13
|
import '@rific/feedback-press';
|
package/dist/index.js
CHANGED
|
@@ -714,7 +714,7 @@ var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
|
714
714
|
function SettingIcon({ source, color, containerColor }) {
|
|
715
715
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_react_native13.View, { style: [styles10.iconBadge, { backgroundColor: containerColor }], children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_react_native_paper9.Icon, { source, size: 18, color }) });
|
|
716
716
|
}
|
|
717
|
-
function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, version, lockOrientation, onLockOrientationChange, deferBottomEdgeGestures, onDeferBottomEdgeGestures, hideSound = false, hideHaptics = false, hideAppearance = false, hideUpdateCheck = false, onUpdateError, onShowHowToPlay, children, leading }) {
|
|
717
|
+
function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, version, lockOrientation, onLockOrientationChange, deferBottomEdgeGestures, onDeferBottomEdgeGestures, hideSound = false, hideHaptics = false, showMusic = false, hideAppearance = false, hideUpdateCheck = false, onUpdateError, onShowHowToPlay, children, leading }) {
|
|
718
718
|
const { colors } = (0, import_auto_paper7.useAutoPaperTheme)();
|
|
719
719
|
const ambientRotation = (0, import_core5.useRotation)();
|
|
720
720
|
const rotation = rotationOverride ?? ambientRotation;
|
|
@@ -726,6 +726,7 @@ function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, ve
|
|
|
726
726
|
const isTouchPrimary = (0, import_core5.useIsTouchPrimaryDevice)();
|
|
727
727
|
const { settings: hapticSettings, set: setHapticSettings } = (0, import_feedback_press3.useHapticSettings)();
|
|
728
728
|
const { settings: soundSettings, set: setSoundSettings } = (0, import_feedback_press3.useSoundSettings)();
|
|
729
|
+
const { settings: musicSettings, set: setMusicSettings } = (0, import_feedback_press3.useMusicSettings)();
|
|
729
730
|
const { settings: keepAwakeSettings, set: setKeepAwakeSettings } = (0, import_core4.useKeepAwakeSettings)();
|
|
730
731
|
const expoKeepAwake = (0, import_core4.useExpoKeepAwake)();
|
|
731
732
|
const sound = (0, import_react6.useContext)(import_feedback_press3.SoundContext);
|
|
@@ -783,7 +784,7 @@ function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, ve
|
|
|
783
784
|
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_react_native_paper9.Text, { variant: "bodySmall", numberOfLines: 1, style: { color: colors.onSurfaceVariant }, children: "Stop auto-lock mid-match" })
|
|
784
785
|
] })
|
|
785
786
|
] }) }),
|
|
786
|
-
(showSound || showHaptics) && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_react_native13.View, { style: styles10.toggleRow, children: [
|
|
787
|
+
(showSound || showMusic || showHaptics) && /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_react_native13.View, { style: styles10.toggleRow, children: [
|
|
787
788
|
showSound && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
788
789
|
import_feedback_press3.TouchableRipple,
|
|
789
790
|
{
|
|
@@ -801,6 +802,10 @@ function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, ve
|
|
|
801
802
|
] })
|
|
802
803
|
}
|
|
803
804
|
),
|
|
805
|
+
showMusic && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_feedback_press3.TouchableRipple, { onPress: () => setMusicSettings({ enabled: !musicSettings.enabled }), style: styles10.toggleButtonInRow, accessibilityLabel: `Music ${musicSettings.enabled ? "on" : "off"}`, children: /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)(import_react_native13.View, { style: styles10.toggleContent, children: [
|
|
806
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(SettingIcon, { source: musicSettings.enabled ? "music" : "music-off", color: musicSettings.enabled ? colors.tertiary : colors.onSurfaceVariant, containerColor: musicSettings.enabled ? colors.tertiaryContainer : colors.surfaceVariant }),
|
|
807
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_react_native_paper9.Text, { variant: "bodyLarge", style: { color: colors.onSurface }, children: "Music" })
|
|
808
|
+
] }) }),
|
|
804
809
|
showHaptics && /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
805
810
|
import_feedback_press3.TouchableRipple,
|
|
806
811
|
{
|
|
@@ -927,11 +932,14 @@ var styles10 = import_react_native13.StyleSheet.create({
|
|
|
927
932
|
overflow: "hidden",
|
|
928
933
|
paddingVertical: 10
|
|
929
934
|
},
|
|
930
|
-
// Same shape as toggleButton,
|
|
931
|
-
// toggleRow share the row's own edge alignment instead of each carrying their own.
|
|
935
|
+
// Same shape as toggleButton, half the row instead of its own width - two of these side by side in
|
|
936
|
+
// toggleRow share the row's own edge alignment instead of each carrying their own. Two to a row:
|
|
937
|
+
// three (Sound, Music, Haptics) don't fit across a phone's dialog (Haptics was cut off on a 402pt
|
|
938
|
+
// iPhone), so a third wraps onto its own row and grows to fill it, like the full-width rows above.
|
|
932
939
|
toggleButtonInRow: {
|
|
933
940
|
borderRadius: 12,
|
|
934
|
-
|
|
941
|
+
flexBasis: "45%",
|
|
942
|
+
flexGrow: 1,
|
|
935
943
|
overflow: "hidden",
|
|
936
944
|
paddingVertical: 10
|
|
937
945
|
},
|
|
@@ -950,6 +958,7 @@ var styles10 = import_react_native13.StyleSheet.create({
|
|
|
950
958
|
// No horizontal margin of its own now either - see toggleButton's identical note.
|
|
951
959
|
toggleRow: {
|
|
952
960
|
flexDirection: "row",
|
|
961
|
+
flexWrap: "wrap",
|
|
953
962
|
gap: 4
|
|
954
963
|
}
|
|
955
964
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
loadSkiaWeb,
|
|
3
|
-
locateSkiaWebFile
|
|
4
|
-
} from "./chunk-3TCJHMJP.mjs";
|
|
5
1
|
import {
|
|
6
2
|
AchievementCatalogSection,
|
|
7
3
|
AchievementRow,
|
|
@@ -22,7 +18,7 @@ import {
|
|
|
22
18
|
getStaggeredWordDuration,
|
|
23
19
|
useCompactDialog,
|
|
24
20
|
useWellColors
|
|
25
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-4666H2UG.mjs";
|
|
26
22
|
import {
|
|
27
23
|
COMPACT_DIALOG_HEIGHT,
|
|
28
24
|
DialogHeader,
|
|
@@ -34,6 +30,10 @@ import {
|
|
|
34
30
|
overlayStyles,
|
|
35
31
|
useOverlayCardColors
|
|
36
32
|
} from "./chunk-CBH7GQKI.mjs";
|
|
33
|
+
import {
|
|
34
|
+
loadSkiaWeb,
|
|
35
|
+
locateSkiaWebFile
|
|
36
|
+
} from "./chunk-3TCJHMJP.mjs";
|
|
37
37
|
import {
|
|
38
38
|
PlayerSetupPanel,
|
|
39
39
|
ReadyButton,
|
package/dist/skia/index.d.mts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
export { l as loadSkiaWeb, a as locateSkiaWebFile } from '../locateSkiaWebFile-DAJ0ok2i.mjs';
|
|
2
|
+
import { ComponentType } from 'react';
|
|
2
3
|
|
|
3
|
-
declare function
|
|
4
|
+
declare function lazySkia<P extends object>(load: () => Promise<{
|
|
5
|
+
default: ComponentType<P>;
|
|
6
|
+
}>): ComponentType<P>;
|
|
4
7
|
|
|
5
|
-
export {
|
|
8
|
+
export { lazySkia };
|
package/dist/skia/index.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
|
|
1
|
+
export { l as loadSkiaWeb, a as locateSkiaWebFile } from '../locateSkiaWebFile-DAJ0ok2i.js';
|
|
2
|
+
import { ComponentType } from 'react';
|
|
2
3
|
|
|
3
|
-
declare function
|
|
4
|
+
declare function lazySkia<P extends object>(load: () => Promise<{
|
|
5
|
+
default: ComponentType<P>;
|
|
6
|
+
}>): ComponentType<P>;
|
|
4
7
|
|
|
5
|
-
export {
|
|
8
|
+
export { lazySkia };
|
package/dist/skia/index.js
CHANGED
|
@@ -20,6 +20,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
20
20
|
// src/skia/index.ts
|
|
21
21
|
var skia_exports = {};
|
|
22
22
|
__export(skia_exports, {
|
|
23
|
+
lazySkia: () => lazySkia,
|
|
23
24
|
loadSkiaWeb: () => loadSkiaWeb,
|
|
24
25
|
locateSkiaWebFile: () => locateSkiaWebFile
|
|
25
26
|
});
|
|
@@ -34,8 +35,19 @@ function loadSkiaWeb() {
|
|
|
34
35
|
function locateSkiaWebFile(file) {
|
|
35
36
|
return `${process.env.EXPO_BASE_URL ?? ""}/${file}`;
|
|
36
37
|
}
|
|
38
|
+
|
|
39
|
+
// src/skia/lazySkia.tsx
|
|
40
|
+
var import_react = require("react");
|
|
41
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
42
|
+
function lazySkia(load) {
|
|
43
|
+
const LazySkiaComponent = (0, import_react.lazy)(() => loadSkiaWeb().then(load));
|
|
44
|
+
return function SkiaHost(props) {
|
|
45
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_react.Suspense, { fallback: null, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(LazySkiaComponent, { ...props }) });
|
|
46
|
+
};
|
|
47
|
+
}
|
|
37
48
|
// Annotate the CommonJS export names for ESM import in node:
|
|
38
49
|
0 && (module.exports = {
|
|
50
|
+
lazySkia,
|
|
39
51
|
loadSkiaWeb,
|
|
40
52
|
locateSkiaWebFile
|
|
41
53
|
});
|
package/dist/skia/index.mjs
CHANGED
|
@@ -2,7 +2,18 @@ import {
|
|
|
2
2
|
loadSkiaWeb,
|
|
3
3
|
locateSkiaWebFile
|
|
4
4
|
} from "../chunk-3TCJHMJP.mjs";
|
|
5
|
+
|
|
6
|
+
// src/skia/lazySkia.tsx
|
|
7
|
+
import { lazy, Suspense } from "react";
|
|
8
|
+
import { jsx } from "react/jsx-runtime";
|
|
9
|
+
function lazySkia(load) {
|
|
10
|
+
const LazySkiaComponent = lazy(() => loadSkiaWeb().then(load));
|
|
11
|
+
return function SkiaHost(props) {
|
|
12
|
+
return /* @__PURE__ */ jsx(Suspense, { fallback: null, children: /* @__PURE__ */ jsx(LazySkiaComponent, { ...props }) });
|
|
13
|
+
};
|
|
14
|
+
}
|
|
5
15
|
export {
|
|
16
|
+
lazySkia,
|
|
6
17
|
loadSkiaWeb,
|
|
7
18
|
locateSkiaWebFile
|
|
8
19
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tastic/hud",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.1",
|
|
4
4
|
"description": "Visual component kit for local-multiplayer React Native games: inline (non-modal) popovers, dropdowns, color pickers, gauges, ready buttons, and dialogs, built to stay scoped to one player's own zone on a shared screen",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -96,7 +96,7 @@
|
|
|
96
96
|
"@infinitetoken/tsconfig": "^0.7.0",
|
|
97
97
|
"@rific/auto-paper": "^0.14.0",
|
|
98
98
|
"@rific/core": "^0.5.0",
|
|
99
|
-
"@rific/feedback-press": "^0.
|
|
99
|
+
"@rific/feedback-press": "^0.14.0",
|
|
100
100
|
"@rific/updater": "^0.8.0",
|
|
101
101
|
"@shopify/react-native-skia": "^2.14.0",
|
|
102
102
|
"@tastic/achievements": "^0.6.0",
|
|
@@ -125,7 +125,7 @@
|
|
|
125
125
|
"peerDependencies": {
|
|
126
126
|
"@rific/auto-paper": ">=0.13.0",
|
|
127
127
|
"@rific/core": ">=0.4.0",
|
|
128
|
-
"@rific/feedback-press": ">=0.
|
|
128
|
+
"@rific/feedback-press": ">=0.14.0",
|
|
129
129
|
"@rific/updater": ">=0.4.0",
|
|
130
130
|
"@shopify/react-native-skia": ">=2.6.0",
|
|
131
131
|
"@tastic/achievements": ">=0.2.0",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AutoAppearancePicker, Dialog, FadingScrollView, useAutoPaperTheme, useBlurModule, useThemeSettings } from '@rific/auto-paper'
|
|
2
2
|
import { useExpoKeepAwake, useKeepAwakeSettings } from '@rific/core'
|
|
3
|
-
import { Button, SoundContext, TouchableRipple, useHapticSettings, useSoundSettings, useVibration } from '@rific/feedback-press'
|
|
3
|
+
import { Button, SoundContext, TouchableRipple, useHapticSettings, useMusicSettings, useSoundSettings, useVibration } from '@rific/feedback-press'
|
|
4
4
|
import { useUpdater } from '@rific/updater'
|
|
5
5
|
import { rotateInsets, useIsTouchPrimaryDevice, useRotation, type ViewRotation } from '@tastic/core'
|
|
6
6
|
import { ReactNode, useContext, useState } from 'react'
|
|
@@ -23,7 +23,7 @@ interface SettingIconProps {
|
|
|
23
23
|
// Small colored badge per row (icon tinted on its own MD3 container color) - echoes the
|
|
24
24
|
// primary/secondary/tertiary triad that's already each consuming app's own identity, so the
|
|
25
25
|
// settings list picks up that same palette instead of introducing new colors of its own. Every
|
|
26
|
-
// on/off row (Lock Orientation, Edge Guard, Sound, Haptics) is tertiary while on, and an app adding
|
|
26
|
+
// on/off row (Lock Orientation, Edge Guard, Sound, Music, Haptics) is tertiary while on, and an app adding
|
|
27
27
|
// its own toggle rows should match; secondary is for the always-on action row (How to Play).
|
|
28
28
|
function SettingIcon({ source, color, containerColor }: SettingIconProps) {
|
|
29
29
|
return (
|
|
@@ -67,6 +67,10 @@ export interface BaseSettingsDialogProps {
|
|
|
67
67
|
// Haptics is already native-only (see the row's own Platform.OS check) - this hides it even
|
|
68
68
|
// there, for a game that's deliberately silent on vibration.
|
|
69
69
|
hideHaptics?: boolean
|
|
70
|
+
// Opt in, unlike the rows above: a Music toggle beside Sound, for a game with music
|
|
71
|
+
// (@rific/feedback-press's useMusic, gated on its own Music setting, apart from Sound). Most
|
|
72
|
+
// games have none, so it's hidden unless asked for.
|
|
73
|
+
showMusic?: boolean
|
|
70
74
|
hideAppearance?: boolean
|
|
71
75
|
// Check for Updates is already native-only (a web build has no OTA update concept at all) - this
|
|
72
76
|
// hides it even there, for a native app that isn't wired up for EAS/OTA updates at all.
|
|
@@ -98,7 +102,7 @@ export interface BaseSettingsDialogProps {
|
|
|
98
102
|
// is the seam for whatever isn't shared: a game with its own board/difficulty settings (or a stats
|
|
99
103
|
// backup flow, or anything else genuinely specific to it) renders those below Appearance, not by
|
|
100
104
|
// forking this component.
|
|
101
|
-
export function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, version, lockOrientation, onLockOrientationChange, deferBottomEdgeGestures, onDeferBottomEdgeGestures, hideSound = false, hideHaptics = false, hideAppearance = false, hideUpdateCheck = false, onUpdateError, onShowHowToPlay, children, leading }: BaseSettingsDialogProps) {
|
|
105
|
+
export function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverride, version, lockOrientation, onLockOrientationChange, deferBottomEdgeGestures, onDeferBottomEdgeGestures, hideSound = false, hideHaptics = false, showMusic = false, hideAppearance = false, hideUpdateCheck = false, onUpdateError, onShowHowToPlay, children, leading }: BaseSettingsDialogProps) {
|
|
102
106
|
const { colors } = useAutoPaperTheme()
|
|
103
107
|
const ambientRotation = useRotation()
|
|
104
108
|
const rotation = rotationOverride ?? ambientRotation
|
|
@@ -122,6 +126,7 @@ export function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverr
|
|
|
122
126
|
const isTouchPrimary = useIsTouchPrimaryDevice()
|
|
123
127
|
const { settings: hapticSettings, set: setHapticSettings } = useHapticSettings()
|
|
124
128
|
const { settings: soundSettings, set: setSoundSettings } = useSoundSettings()
|
|
129
|
+
const { settings: musicSettings, set: setMusicSettings } = useMusicSettings()
|
|
125
130
|
const { settings: keepAwakeSettings, set: setKeepAwakeSettings } = useKeepAwakeSettings()
|
|
126
131
|
const expoKeepAwake = useExpoKeepAwake()
|
|
127
132
|
// Sound/Haptics toggle themselves: the ripple's automatic press feedback fires on onPressIn,
|
|
@@ -284,7 +289,7 @@ export function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverr
|
|
|
284
289
|
inside it use toggleButtonInRow (flex: 1) instead so the two don't double up on it.
|
|
285
290
|
The row itself only renders when at least one of the two will - an empty flex row
|
|
286
291
|
still eats its own gap/margin otherwise. */}
|
|
287
|
-
{(showSound || showHaptics) && (
|
|
292
|
+
{(showSound || showMusic || showHaptics) && (
|
|
288
293
|
<View style={styles.toggleRow}>
|
|
289
294
|
{showSound && (
|
|
290
295
|
<TouchableRipple
|
|
@@ -306,6 +311,20 @@ export function BaseSettingsDialog({ visible, onDismiss, rotation: rotationOverr
|
|
|
306
311
|
</TouchableRipple>
|
|
307
312
|
)}
|
|
308
313
|
|
|
314
|
+
{/* Music has its own setting, apart from Sound (feedback-press's useMusic plays only
|
|
315
|
+
while it's on). No sound of its own when switched on: the music fading in is
|
|
316
|
+
the confirmation. */}
|
|
317
|
+
{showMusic && (
|
|
318
|
+
<TouchableRipple onPress={() => setMusicSettings({ enabled: !musicSettings.enabled })} style={styles.toggleButtonInRow} accessibilityLabel={`Music ${musicSettings.enabled ? 'on' : 'off'}`}>
|
|
319
|
+
<View style={styles.toggleContent}>
|
|
320
|
+
<SettingIcon source={musicSettings.enabled ? 'music' : 'music-off'} color={musicSettings.enabled ? colors.tertiary : colors.onSurfaceVariant} containerColor={musicSettings.enabled ? colors.tertiaryContainer : colors.surfaceVariant} />
|
|
321
|
+
<Text variant='bodyLarge' style={{ color: colors.onSurface }}>
|
|
322
|
+
Music
|
|
323
|
+
</Text>
|
|
324
|
+
</View>
|
|
325
|
+
</TouchableRipple>
|
|
326
|
+
)}
|
|
327
|
+
|
|
309
328
|
{/* Already native-only (see showHaptics's own definition) - hideHaptics can hide
|
|
310
329
|
it there too, for a game that's deliberately silent on vibration. */}
|
|
311
330
|
{showHaptics && (
|
|
@@ -488,11 +507,14 @@ const styles = StyleSheet.create({
|
|
|
488
507
|
overflow: 'hidden',
|
|
489
508
|
paddingVertical: 10
|
|
490
509
|
},
|
|
491
|
-
// Same shape as toggleButton,
|
|
492
|
-
// toggleRow share the row's own edge alignment instead of each carrying their own.
|
|
510
|
+
// Same shape as toggleButton, half the row instead of its own width - two of these side by side in
|
|
511
|
+
// toggleRow share the row's own edge alignment instead of each carrying their own. Two to a row:
|
|
512
|
+
// three (Sound, Music, Haptics) don't fit across a phone's dialog (Haptics was cut off on a 402pt
|
|
513
|
+
// iPhone), so a third wraps onto its own row and grows to fill it, like the full-width rows above.
|
|
493
514
|
toggleButtonInRow: {
|
|
494
515
|
borderRadius: 12,
|
|
495
|
-
|
|
516
|
+
flexBasis: '45%',
|
|
517
|
+
flexGrow: 1,
|
|
496
518
|
overflow: 'hidden',
|
|
497
519
|
paddingVertical: 10
|
|
498
520
|
},
|
|
@@ -511,6 +533,7 @@ const styles = StyleSheet.create({
|
|
|
511
533
|
// No horizontal margin of its own now either - see toggleButton's identical note.
|
|
512
534
|
toggleRow: {
|
|
513
535
|
flexDirection: 'row',
|
|
536
|
+
flexWrap: 'wrap',
|
|
514
537
|
gap: 4
|
|
515
538
|
}
|
|
516
539
|
})
|
package/src/skia/index.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
// The Skia entry point (`@tastic/hud/skia`): the web CanvasKit loader every app's Skia host files use,
|
|
2
|
-
//
|
|
2
|
+
// the wasm URL rule it applies, and lazySkia (a web host's lazy, Suspense-wrapped component behind that
|
|
3
|
+
// loader), reachable without the main barrel. Several Skia apps lack the
|
|
3
4
|
// barrel's heavier peers (@tastic/profile, @tastic/split-screen), and importing `@tastic/hud` there
|
|
4
5
|
// fails to bundle, so this is the one import path every app's host files share.
|
|
5
6
|
//
|
|
6
7
|
// package.json points both "react-native" and "browser" at this file. That is fine because it has no
|
|
7
8
|
// .web twin itself: Metro doesn't platform-resolve an exports-map target, but it does resolve the
|
|
8
9
|
// relative imports below, so web bundles get loadSkiaWeb.web.ts and native ones the no-op. The
|
|
9
|
-
// boundary (
|
|
10
|
+
// boundary (react, and @shopify/react-native-skia's /src/web subpath only from the .web file) is
|
|
10
11
|
// enforced by src/__tests__/skiaImports.test.ts.
|
|
11
12
|
export { loadSkiaWeb } from '../loadSkiaWeb'
|
|
12
13
|
export { locateSkiaWebFile } from '../locateSkiaWebFile'
|
|
14
|
+
export { lazySkia } from './lazySkia'
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { type ComponentType, lazy, Suspense } from 'react'
|
|
2
|
+
|
|
3
|
+
import { loadSkiaWeb } from '../loadSkiaWeb'
|
|
4
|
+
|
|
5
|
+
// A Skia component for the web (an app's BoardHost.web.tsx, the web half of the host pair: see the
|
|
6
|
+
// README's "Skia on web"). Skia's web target renders through CanvasKit, a WASM build of Skia, and a
|
|
7
|
+
// component's own `Skia` import binds to `global.CanvasKit` once, synchronously, at module-evaluation
|
|
8
|
+
// time (see @shopify/react-native-skia's Skia.web.ts: `export const Skia = JsiSkApi(global.CanvasKit)`)
|
|
9
|
+
// - not lazily, and not reactively. A plain import of the component would evaluate that binding against
|
|
10
|
+
// a not-yet-loaded, undefined CanvasKit before anything renders, since Metro evaluates the whole static
|
|
11
|
+
// import graph up front. A dynamic import is the one thing that defers module evaluation to runtime, so
|
|
12
|
+
// the component's module (and Skia with it) is only imported once loadSkiaWeb() has resolved and set
|
|
13
|
+
// global.CanvasKit for real. On native there's nothing to defer (JSI is ready before any JS runs), so an
|
|
14
|
+
// app's BoardHost.tsx just re-exports its component, which then draws on the first frame.
|
|
15
|
+
//
|
|
16
|
+
// Call it once, at module scope (`export default lazySkia(...)`), so the lazy component is created once:
|
|
17
|
+
// called during a render it would be a new component type every time, remounting the Skia component.
|
|
18
|
+
export function lazySkia<P extends object>(load: () => Promise<{ default: ComponentType<P> }>): ComponentType<P> {
|
|
19
|
+
const LazySkiaComponent = lazy(() => loadSkiaWeb().then(load))
|
|
20
|
+
return function SkiaHost(props: P) {
|
|
21
|
+
return (
|
|
22
|
+
<Suspense fallback={null}>
|
|
23
|
+
<LazySkiaComponent {...props} />
|
|
24
|
+
</Suspense>
|
|
25
|
+
)
|
|
26
|
+
}
|
|
27
|
+
}
|