@tastic/shell 0.21.0 → 0.21.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/dist/index.js +77 -10
- package/dist/index.mjs +78 -11
- package/package.json +1 -1
- package/src/RootLayout.tsx +40 -5
- package/src/hooks/useLastActiveGame.tsx +34 -5
- package/src/screens/GameRoute.tsx +13 -0
- package/src/screens/HomeScreen.tsx +27 -6
package/dist/index.js
CHANGED
|
@@ -373,8 +373,15 @@ function LastActiveGameProvider({ children }) {
|
|
|
373
373
|
const [initial] = (0, import_react7.useState)(() => store.getState().lastActiveGame?.gameId ?? null);
|
|
374
374
|
const pendingResume = (0, import_react7.useRef)(initial);
|
|
375
375
|
const persisted = (0, import_react7.useRef)(initial);
|
|
376
|
-
const
|
|
377
|
-
|
|
376
|
+
const resume = (0, import_react7.useRef)("idle");
|
|
377
|
+
const resumeListeners = (0, import_react7.useRef)(/* @__PURE__ */ new Set());
|
|
378
|
+
const value = (0, import_react7.useMemo)(() => {
|
|
379
|
+
const setResume = (next) => {
|
|
380
|
+
if (resume.current === next) return;
|
|
381
|
+
resume.current = next;
|
|
382
|
+
resumeListeners.current.forEach((listener) => listener());
|
|
383
|
+
};
|
|
384
|
+
return {
|
|
378
385
|
consumeResumeGame: () => {
|
|
379
386
|
const game = pendingResume.current;
|
|
380
387
|
pendingResume.current = null;
|
|
@@ -394,10 +401,20 @@ function LastActiveGameProvider({ children }) {
|
|
|
394
401
|
if (persisted.current === null) return;
|
|
395
402
|
persisted.current = null;
|
|
396
403
|
dispatch(lastActiveGameActions.setGameId(null));
|
|
404
|
+
},
|
|
405
|
+
beginResume: () => setResume("opening"),
|
|
406
|
+
playScreenUp: () => {
|
|
407
|
+
if (resume.current === "opening") setResume("up");
|
|
408
|
+
},
|
|
409
|
+
endResume: () => setResume("idle"),
|
|
410
|
+
resumeState: () => resume.current,
|
|
411
|
+
subscribeResume: (listener) => {
|
|
412
|
+
const listeners = resumeListeners.current;
|
|
413
|
+
listeners.add(listener);
|
|
414
|
+
return () => void listeners.delete(listener);
|
|
397
415
|
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
);
|
|
416
|
+
};
|
|
417
|
+
}, [dispatch]);
|
|
401
418
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(LastActiveGameContext.Provider, { value, children });
|
|
402
419
|
}
|
|
403
420
|
function useLastActiveGame() {
|
|
@@ -496,16 +513,43 @@ var REPLACE_AS_FORWARD = { animationTypeForReplace: "push" };
|
|
|
496
513
|
var TRANSPARENT_CONTENT = { backgroundColor: "transparent" };
|
|
497
514
|
var noScreenOptions = () => ({});
|
|
498
515
|
function useFirstScreenGate() {
|
|
516
|
+
const { resumeState, subscribeResume } = useLastActiveGame();
|
|
499
517
|
const marked = (0, import_react9.useRef)(false);
|
|
500
518
|
return (0, import_react9.useCallback)(() => {
|
|
501
519
|
if (marked.current) return;
|
|
502
520
|
marked.current = true;
|
|
503
|
-
requestAnimationFrame(() => requestAnimationFrame(() => markSplashReady("screen")));
|
|
504
|
-
|
|
521
|
+
const mark = () => requestAnimationFrame(() => requestAnimationFrame(() => markSplashReady("screen")));
|
|
522
|
+
requestAnimationFrame(
|
|
523
|
+
() => requestAnimationFrame(() => {
|
|
524
|
+
if (resumeState() !== "opening") {
|
|
525
|
+
markSplashReady("screen");
|
|
526
|
+
return;
|
|
527
|
+
}
|
|
528
|
+
const unsubscribe = subscribeResume(() => {
|
|
529
|
+
if (resumeState() === "opening") return;
|
|
530
|
+
unsubscribe();
|
|
531
|
+
mark();
|
|
532
|
+
});
|
|
533
|
+
})
|
|
534
|
+
);
|
|
535
|
+
}, [resumeState, subscribeResume]);
|
|
536
|
+
}
|
|
537
|
+
function useResumeShown() {
|
|
538
|
+
const { endResume } = useLastActiveGame();
|
|
539
|
+
return (0, import_react9.useCallback)(
|
|
540
|
+
({ route }) => ({
|
|
541
|
+
transitionEnd: (event) => {
|
|
542
|
+
if (route.name === PLAY_ROUTE && !event.data?.closing) endResume();
|
|
543
|
+
}
|
|
544
|
+
}),
|
|
545
|
+
[endResume]
|
|
546
|
+
);
|
|
505
547
|
}
|
|
548
|
+
var PLAY_ROUTE = "play/[game]";
|
|
506
549
|
function AppStack() {
|
|
507
550
|
const pack = usePack();
|
|
508
551
|
const onFirstLayout = useFirstScreenGate();
|
|
552
|
+
const screenListeners = useResumeShown();
|
|
509
553
|
const { Backdrop } = pack;
|
|
510
554
|
const { dark } = (0, import_auto_paper2.useAutoPaperTheme)();
|
|
511
555
|
const darkRoot = Backdrop ? true : dark;
|
|
@@ -531,9 +575,9 @@ function AppStack() {
|
|
|
531
575
|
}, [darkRoot, navigationBackground]);
|
|
532
576
|
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_react_native3.View, { style: styles.root, onLayout: onFirstLayout, children: [
|
|
533
577
|
Backdrop && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(Backdrop, {}),
|
|
534
|
-
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_expo_router.ThemeProvider, { value: navigationTheme, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_expo_router.Stack, { screenOptions: { ...rootBackground, statusBarStyle, ...REPLACE_AS_BACK, ...backdropOptions, ...packOptions }, children: [
|
|
578
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_expo_router.ThemeProvider, { value: navigationTheme, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_expo_router.Stack, { screenListeners, screenOptions: { ...rootBackground, statusBarStyle, ...REPLACE_AS_BACK, ...backdropOptions, ...packOptions }, children: [
|
|
535
579
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_expo_router.Stack.Screen, { name: "index" }),
|
|
536
|
-
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_expo_router.Stack.Screen, { name:
|
|
580
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_expo_router.Stack.Screen, { name: PLAY_ROUTE, options: playOptions })
|
|
537
581
|
] }) })
|
|
538
582
|
] });
|
|
539
583
|
}
|
|
@@ -1130,10 +1174,20 @@ function PlayRoute() {
|
|
|
1130
1174
|
const { game: id } = (0, import_expo_router8.useLocalSearchParams)();
|
|
1131
1175
|
const game = usePackGame(id);
|
|
1132
1176
|
useResumePoint(game?.resumable ? game.id : null);
|
|
1177
|
+
useResumeUp();
|
|
1133
1178
|
if (!game) return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_expo_router8.Redirect, { href: "/" });
|
|
1134
1179
|
const { PlayScreen } = game;
|
|
1135
1180
|
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(PlayScreen, {}, game.id);
|
|
1136
1181
|
}
|
|
1182
|
+
function useResumeUp() {
|
|
1183
|
+
const { playScreenUp } = useLastActiveGame();
|
|
1184
|
+
(0, import_react14.useEffect)(() => {
|
|
1185
|
+
let frame = requestAnimationFrame(() => {
|
|
1186
|
+
frame = requestAnimationFrame(playScreenUp);
|
|
1187
|
+
});
|
|
1188
|
+
return () => cancelAnimationFrame(frame);
|
|
1189
|
+
}, [playScreenUp]);
|
|
1190
|
+
}
|
|
1137
1191
|
var playScreensUp = 0;
|
|
1138
1192
|
function useResumePoint(gameId) {
|
|
1139
1193
|
const { setLastActiveGame, clearLastActiveGame } = useLastActiveGame();
|
|
@@ -1268,11 +1322,24 @@ function useResume(game) {
|
|
|
1268
1322
|
);
|
|
1269
1323
|
}
|
|
1270
1324
|
function useMenuShown(resuming) {
|
|
1325
|
+
const { beginResume, endResume, resumeState, subscribeResume } = useLastActiveGame();
|
|
1271
1326
|
const isFocused = (0, import_expo_router9.useIsFocused)();
|
|
1272
1327
|
const [covered, setCovered] = (0, import_react16.useState)(false);
|
|
1273
1328
|
if (resuming && !covered && !isFocused) setCovered(true);
|
|
1274
|
-
|
|
1329
|
+
(0, import_react16.useLayoutEffect)(() => {
|
|
1330
|
+
if (!resuming) return;
|
|
1331
|
+
beginResume();
|
|
1332
|
+
const id = setTimeout(endResume, RESUME_SHOWN_MAX_MS);
|
|
1333
|
+
return () => {
|
|
1334
|
+
clearTimeout(id);
|
|
1335
|
+
endResume();
|
|
1336
|
+
};
|
|
1337
|
+
}, [resuming, beginResume, endResume]);
|
|
1338
|
+
const onItsWay = (0, import_react16.useSyncExternalStore)(subscribeResume, resumeState, resumeState) !== "idle";
|
|
1339
|
+
const gameShown = covered && !onItsWay;
|
|
1340
|
+
return (0, import_react16.useDeferredValue)(!resuming || gameShown || covered && isFocused);
|
|
1275
1341
|
}
|
|
1342
|
+
var RESUME_SHOWN_MAX_MS = 4e3;
|
|
1276
1343
|
function HomeMenu() {
|
|
1277
1344
|
const pack = usePack();
|
|
1278
1345
|
const showPicker = pack.homePlayerPicker !== false;
|
package/dist/index.mjs
CHANGED
|
@@ -294,8 +294,15 @@ function LastActiveGameProvider({ children }) {
|
|
|
294
294
|
const [initial] = useState2(() => store.getState().lastActiveGame?.gameId ?? null);
|
|
295
295
|
const pendingResume = useRef2(initial);
|
|
296
296
|
const persisted = useRef2(initial);
|
|
297
|
-
const
|
|
298
|
-
|
|
297
|
+
const resume = useRef2("idle");
|
|
298
|
+
const resumeListeners = useRef2(/* @__PURE__ */ new Set());
|
|
299
|
+
const value = useMemo2(() => {
|
|
300
|
+
const setResume = (next) => {
|
|
301
|
+
if (resume.current === next) return;
|
|
302
|
+
resume.current = next;
|
|
303
|
+
resumeListeners.current.forEach((listener) => listener());
|
|
304
|
+
};
|
|
305
|
+
return {
|
|
299
306
|
consumeResumeGame: () => {
|
|
300
307
|
const game = pendingResume.current;
|
|
301
308
|
pendingResume.current = null;
|
|
@@ -315,10 +322,20 @@ function LastActiveGameProvider({ children }) {
|
|
|
315
322
|
if (persisted.current === null) return;
|
|
316
323
|
persisted.current = null;
|
|
317
324
|
dispatch(lastActiveGameActions.setGameId(null));
|
|
325
|
+
},
|
|
326
|
+
beginResume: () => setResume("opening"),
|
|
327
|
+
playScreenUp: () => {
|
|
328
|
+
if (resume.current === "opening") setResume("up");
|
|
329
|
+
},
|
|
330
|
+
endResume: () => setResume("idle"),
|
|
331
|
+
resumeState: () => resume.current,
|
|
332
|
+
subscribeResume: (listener) => {
|
|
333
|
+
const listeners = resumeListeners.current;
|
|
334
|
+
listeners.add(listener);
|
|
335
|
+
return () => void listeners.delete(listener);
|
|
318
336
|
}
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
);
|
|
337
|
+
};
|
|
338
|
+
}, [dispatch]);
|
|
322
339
|
return /* @__PURE__ */ jsx8(LastActiveGameContext.Provider, { value, children });
|
|
323
340
|
}
|
|
324
341
|
function useLastActiveGame() {
|
|
@@ -417,16 +434,43 @@ var REPLACE_AS_FORWARD = { animationTypeForReplace: "push" };
|
|
|
417
434
|
var TRANSPARENT_CONTENT = { backgroundColor: "transparent" };
|
|
418
435
|
var noScreenOptions = () => ({});
|
|
419
436
|
function useFirstScreenGate() {
|
|
437
|
+
const { resumeState, subscribeResume } = useLastActiveGame();
|
|
420
438
|
const marked = useRef3(false);
|
|
421
439
|
return useCallback6(() => {
|
|
422
440
|
if (marked.current) return;
|
|
423
441
|
marked.current = true;
|
|
424
|
-
requestAnimationFrame(() => requestAnimationFrame(() => markSplashReady("screen")));
|
|
425
|
-
|
|
442
|
+
const mark = () => requestAnimationFrame(() => requestAnimationFrame(() => markSplashReady("screen")));
|
|
443
|
+
requestAnimationFrame(
|
|
444
|
+
() => requestAnimationFrame(() => {
|
|
445
|
+
if (resumeState() !== "opening") {
|
|
446
|
+
markSplashReady("screen");
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
const unsubscribe = subscribeResume(() => {
|
|
450
|
+
if (resumeState() === "opening") return;
|
|
451
|
+
unsubscribe();
|
|
452
|
+
mark();
|
|
453
|
+
});
|
|
454
|
+
})
|
|
455
|
+
);
|
|
456
|
+
}, [resumeState, subscribeResume]);
|
|
457
|
+
}
|
|
458
|
+
function useResumeShown() {
|
|
459
|
+
const { endResume } = useLastActiveGame();
|
|
460
|
+
return useCallback6(
|
|
461
|
+
({ route }) => ({
|
|
462
|
+
transitionEnd: (event) => {
|
|
463
|
+
if (route.name === PLAY_ROUTE && !event.data?.closing) endResume();
|
|
464
|
+
}
|
|
465
|
+
}),
|
|
466
|
+
[endResume]
|
|
467
|
+
);
|
|
426
468
|
}
|
|
469
|
+
var PLAY_ROUTE = "play/[game]";
|
|
427
470
|
function AppStack() {
|
|
428
471
|
const pack = usePack();
|
|
429
472
|
const onFirstLayout = useFirstScreenGate();
|
|
473
|
+
const screenListeners = useResumeShown();
|
|
430
474
|
const { Backdrop } = pack;
|
|
431
475
|
const { dark } = useAutoPaperTheme();
|
|
432
476
|
const darkRoot = Backdrop ? true : dark;
|
|
@@ -452,9 +496,9 @@ function AppStack() {
|
|
|
452
496
|
}, [darkRoot, navigationBackground]);
|
|
453
497
|
return /* @__PURE__ */ jsxs2(View, { style: styles.root, onLayout: onFirstLayout, children: [
|
|
454
498
|
Backdrop && /* @__PURE__ */ jsx10(Backdrop, {}),
|
|
455
|
-
/* @__PURE__ */ jsx10(NavigationThemeProvider, { value: navigationTheme, children: /* @__PURE__ */ jsxs2(Stack, { screenOptions: { ...rootBackground, statusBarStyle, ...REPLACE_AS_BACK, ...backdropOptions, ...packOptions }, children: [
|
|
499
|
+
/* @__PURE__ */ jsx10(NavigationThemeProvider, { value: navigationTheme, children: /* @__PURE__ */ jsxs2(Stack, { screenListeners, screenOptions: { ...rootBackground, statusBarStyle, ...REPLACE_AS_BACK, ...backdropOptions, ...packOptions }, children: [
|
|
456
500
|
/* @__PURE__ */ jsx10(Stack.Screen, { name: "index" }),
|
|
457
|
-
/* @__PURE__ */ jsx10(Stack.Screen, { name:
|
|
501
|
+
/* @__PURE__ */ jsx10(Stack.Screen, { name: PLAY_ROUTE, options: playOptions })
|
|
458
502
|
] }) })
|
|
459
503
|
] });
|
|
460
504
|
}
|
|
@@ -1051,10 +1095,20 @@ function PlayRoute() {
|
|
|
1051
1095
|
const { game: id } = useLocalSearchParams3();
|
|
1052
1096
|
const game = usePackGame(id);
|
|
1053
1097
|
useResumePoint(game?.resumable ? game.id : null);
|
|
1098
|
+
useResumeUp();
|
|
1054
1099
|
if (!game) return /* @__PURE__ */ jsx16(Redirect, { href: "/" });
|
|
1055
1100
|
const { PlayScreen } = game;
|
|
1056
1101
|
return /* @__PURE__ */ jsx16(PlayScreen, {}, game.id);
|
|
1057
1102
|
}
|
|
1103
|
+
function useResumeUp() {
|
|
1104
|
+
const { playScreenUp } = useLastActiveGame();
|
|
1105
|
+
useEffect5(() => {
|
|
1106
|
+
let frame = requestAnimationFrame(() => {
|
|
1107
|
+
frame = requestAnimationFrame(playScreenUp);
|
|
1108
|
+
});
|
|
1109
|
+
return () => cancelAnimationFrame(frame);
|
|
1110
|
+
}, [playScreenUp]);
|
|
1111
|
+
}
|
|
1058
1112
|
var playScreensUp = 0;
|
|
1059
1113
|
function useResumePoint(gameId) {
|
|
1060
1114
|
const { setLastActiveGame, clearLastActiveGame } = useLastActiveGame();
|
|
@@ -1075,7 +1129,7 @@ import { IconButton, Pressable } from "@rific/feedback-press";
|
|
|
1075
1129
|
import { PressAwayOverlay as PressAwayOverlay2, usePopoverHost as usePopoverHost2, useWellColors, WELL_SHADOW } from "@tastic/hud/chrome";
|
|
1076
1130
|
import { getProfilePickerContentSize, ProfilePicker } from "@tastic/profile";
|
|
1077
1131
|
import { router as router5, useFocusEffect as useFocusEffect3, useIsFocused } from "expo-router";
|
|
1078
|
-
import { createContext as createContext5, memo, startTransition, useCallback as useCallback10, useContext as useContext5, useDeferredValue, useEffect as useEffect6, useMemo as useMemo6, useRef as useRef6, useState as useState6 } from "react";
|
|
1132
|
+
import { createContext as createContext5, memo, startTransition, useCallback as useCallback10, useContext as useContext5, useDeferredValue, useEffect as useEffect6, useLayoutEffect, useMemo as useMemo6, useRef as useRef6, useState as useState6, useSyncExternalStore } from "react";
|
|
1079
1133
|
import { AppState as AppState2, Platform as Platform5, StyleSheet as StyleSheet4, View as View4 } from "react-native";
|
|
1080
1134
|
import { Icon, Portal, SegmentedButtons, Text as Text2 } from "react-native-paper";
|
|
1081
1135
|
|
|
@@ -1189,11 +1243,24 @@ function useResume(game) {
|
|
|
1189
1243
|
);
|
|
1190
1244
|
}
|
|
1191
1245
|
function useMenuShown(resuming) {
|
|
1246
|
+
const { beginResume, endResume, resumeState, subscribeResume } = useLastActiveGame();
|
|
1192
1247
|
const isFocused = useIsFocused();
|
|
1193
1248
|
const [covered, setCovered] = useState6(false);
|
|
1194
1249
|
if (resuming && !covered && !isFocused) setCovered(true);
|
|
1195
|
-
|
|
1250
|
+
useLayoutEffect(() => {
|
|
1251
|
+
if (!resuming) return;
|
|
1252
|
+
beginResume();
|
|
1253
|
+
const id = setTimeout(endResume, RESUME_SHOWN_MAX_MS);
|
|
1254
|
+
return () => {
|
|
1255
|
+
clearTimeout(id);
|
|
1256
|
+
endResume();
|
|
1257
|
+
};
|
|
1258
|
+
}, [resuming, beginResume, endResume]);
|
|
1259
|
+
const onItsWay = useSyncExternalStore(subscribeResume, resumeState, resumeState) !== "idle";
|
|
1260
|
+
const gameShown = covered && !onItsWay;
|
|
1261
|
+
return useDeferredValue(!resuming || gameShown || covered && isFocused);
|
|
1196
1262
|
}
|
|
1263
|
+
var RESUME_SHOWN_MAX_MS = 4e3;
|
|
1197
1264
|
function HomeMenu() {
|
|
1198
1265
|
const pack = usePack();
|
|
1199
1266
|
const showPicker = pack.homePlayerPicker !== false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tastic/shell",
|
|
3
|
-
"version": "0.21.
|
|
3
|
+
"version": "0.21.1",
|
|
4
4
|
"description": "The app around a pack of React Native games, two-seat or for one player: Home, the loadout, the stats screen, Profiles and Settings, the pack's Redux store and its root providers, driven by one PackDefinition",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
package/src/RootLayout.tsx
CHANGED
|
@@ -21,7 +21,7 @@ import { Theme } from './components/Theme'
|
|
|
21
21
|
import { UpdateDialog } from './components/UpdateDialog'
|
|
22
22
|
import { WindowControlsInsets } from './components/WindowControlsInsets'
|
|
23
23
|
import { useAppSettings } from './hooks/useAppSettings'
|
|
24
|
-
import { LastActiveGameProvider } from './hooks/useLastActiveGame'
|
|
24
|
+
import { LastActiveGameProvider, useLastActiveGame } from './hooks/useLastActiveGame'
|
|
25
25
|
import { ProfilesProvider, useProfiles } from './hooks/useProfiles'
|
|
26
26
|
import { PackProvider, usePack } from './PackContext'
|
|
27
27
|
import type { PackStore } from './redux/createPackStore'
|
|
@@ -88,18 +88,53 @@ const noScreenOptions = () => ({})
|
|
|
88
88
|
// Stylo 6, CardTastic). The stack's layout comes with that commit, whatever screen it opens on, and by the
|
|
89
89
|
// second frame after it Android has mounted it (nothing under a held splash is drawn), so the splash fades
|
|
90
90
|
// straight to the screen.
|
|
91
|
+
//
|
|
92
|
+
// A launch going back into a game (HomeScreen's resume) holds it until that game's play screen is mounted, or
|
|
93
|
+
// the splash would lift on an empty table first. Mounted, not come in: Android draws nothing under a held
|
|
94
|
+
// splash, so a transition waited for here would never run.
|
|
91
95
|
function useFirstScreenGate() {
|
|
96
|
+
const { resumeState, subscribeResume } = useLastActiveGame()
|
|
92
97
|
const marked = useRef(false)
|
|
93
98
|
return useCallback(() => {
|
|
94
99
|
if (marked.current) return
|
|
95
100
|
marked.current = true
|
|
96
|
-
requestAnimationFrame(() => requestAnimationFrame(() => markSplashReady('screen')))
|
|
97
|
-
|
|
101
|
+
const mark = () => requestAnimationFrame(() => requestAnimationFrame(() => markSplashReady('screen')))
|
|
102
|
+
requestAnimationFrame(() =>
|
|
103
|
+
requestAnimationFrame(() => {
|
|
104
|
+
if (resumeState() !== 'opening') {
|
|
105
|
+
markSplashReady('screen')
|
|
106
|
+
return
|
|
107
|
+
}
|
|
108
|
+
const unsubscribe = subscribeResume(() => {
|
|
109
|
+
if (resumeState() === 'opening') return
|
|
110
|
+
unsubscribe()
|
|
111
|
+
mark()
|
|
112
|
+
})
|
|
113
|
+
})
|
|
114
|
+
)
|
|
115
|
+
}, [resumeState, subscribeResume])
|
|
98
116
|
}
|
|
99
117
|
|
|
118
|
+
// Tells a resume that its game's screen has come in (the end of the play screen's transition), so Home may
|
|
119
|
+
// draw its menu beneath it.
|
|
120
|
+
function useResumeShown() {
|
|
121
|
+
const { endResume } = useLastActiveGame()
|
|
122
|
+
return useCallback(
|
|
123
|
+
({ route }: { route: { name: string } }) => ({
|
|
124
|
+
transitionEnd: (event: { data?: { closing?: boolean } }) => {
|
|
125
|
+
if (route.name === PLAY_ROUTE && !event.data?.closing) endResume()
|
|
126
|
+
}
|
|
127
|
+
}),
|
|
128
|
+
[endResume]
|
|
129
|
+
)
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const PLAY_ROUTE = 'play/[game]'
|
|
133
|
+
|
|
100
134
|
function AppStack() {
|
|
101
135
|
const pack = usePack()
|
|
102
136
|
const onFirstLayout = useFirstScreenGate()
|
|
137
|
+
const screenListeners = useResumeShown()
|
|
103
138
|
const { Backdrop } = pack
|
|
104
139
|
const { dark } = useAutoPaperTheme()
|
|
105
140
|
// Over a backdrop the root stays dark whatever the mode: a backdrop is a dark table (the felt), and a
|
|
@@ -134,9 +169,9 @@ function AppStack() {
|
|
|
134
169
|
<View style={styles.root} onLayout={onFirstLayout}>
|
|
135
170
|
{Backdrop && <Backdrop />}
|
|
136
171
|
<NavigationThemeProvider value={navigationTheme}>
|
|
137
|
-
<Stack screenOptions={{ ...rootBackground, statusBarStyle, ...REPLACE_AS_BACK, ...backdropOptions, ...packOptions }}>
|
|
172
|
+
<Stack screenListeners={screenListeners} screenOptions={{ ...rootBackground, statusBarStyle, ...REPLACE_AS_BACK, ...backdropOptions, ...packOptions }}>
|
|
138
173
|
<Stack.Screen name='index' />
|
|
139
|
-
<Stack.Screen name=
|
|
174
|
+
<Stack.Screen name={PLAY_ROUTE} options={playOptions} />
|
|
140
175
|
</Stack>
|
|
141
176
|
</NavigationThemeProvider>
|
|
142
177
|
</View>
|
|
@@ -4,11 +4,23 @@ import { useDispatch, useStore } from 'react-redux'
|
|
|
4
4
|
import { lastActiveGameActions } from '../redux/lastActiveGameSlice'
|
|
5
5
|
import type { ShellState } from '../redux/shellState'
|
|
6
6
|
|
|
7
|
+
// A cold launch on its way back into a game. 'opening' from the Home that resumes it (beginResume) until that
|
|
8
|
+
// game's play screen is mounted (playScreenUp): the splash is held. 'up' from then until the screen has come in
|
|
9
|
+
// (endResume): Home still draws no menu, which would show through the game's screen as it fades in. 'idle'
|
|
10
|
+
// otherwise.
|
|
11
|
+
export type ResumeState = 'idle' | 'opening' | 'up'
|
|
12
|
+
|
|
7
13
|
interface LastActiveGameContextValue {
|
|
8
14
|
// Returns the game a cold launch should drop the player straight back onto (once), or null.
|
|
9
15
|
consumeResumeGame: () => string | null
|
|
10
16
|
setLastActiveGame: (gameId: string) => void
|
|
11
17
|
clearLastActiveGame: () => void
|
|
18
|
+
// A resume on its way (ResumeState), read outside React or through useSyncExternalStore.
|
|
19
|
+
beginResume: () => void
|
|
20
|
+
playScreenUp: () => void
|
|
21
|
+
endResume: () => void
|
|
22
|
+
resumeState: () => ResumeState
|
|
23
|
+
subscribeResume: (listener: () => void) => () => void
|
|
12
24
|
}
|
|
13
25
|
|
|
14
26
|
const LastActiveGameContext = createContext<LastActiveGameContextValue | null>(null)
|
|
@@ -36,9 +48,16 @@ export function LastActiveGameProvider({ children }: { children: ReactNode }) {
|
|
|
36
48
|
// What the store currently holds, so an unchanged value is never rewritten: every game mount sets it
|
|
37
49
|
// and every exit clears it.
|
|
38
50
|
const persisted = useRef<string | null>(initial)
|
|
51
|
+
const resume = useRef<ResumeState>('idle')
|
|
52
|
+
const resumeListeners = useRef(new Set<() => void>())
|
|
39
53
|
|
|
40
|
-
const value = useMemo<LastActiveGameContextValue>(
|
|
41
|
-
() =>
|
|
54
|
+
const value = useMemo<LastActiveGameContextValue>(() => {
|
|
55
|
+
const setResume = (next: ResumeState) => {
|
|
56
|
+
if (resume.current === next) return
|
|
57
|
+
resume.current = next
|
|
58
|
+
resumeListeners.current.forEach((listener) => listener())
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
42
61
|
consumeResumeGame: () => {
|
|
43
62
|
const game = pendingResume.current
|
|
44
63
|
pendingResume.current = null
|
|
@@ -58,10 +77,20 @@ export function LastActiveGameProvider({ children }: { children: ReactNode }) {
|
|
|
58
77
|
if (persisted.current === null) return
|
|
59
78
|
persisted.current = null
|
|
60
79
|
dispatch(lastActiveGameActions.setGameId(null))
|
|
80
|
+
},
|
|
81
|
+
beginResume: () => setResume('opening'),
|
|
82
|
+
playScreenUp: () => {
|
|
83
|
+
if (resume.current === 'opening') setResume('up')
|
|
84
|
+
},
|
|
85
|
+
endResume: () => setResume('idle'),
|
|
86
|
+
resumeState: () => resume.current,
|
|
87
|
+
subscribeResume: (listener) => {
|
|
88
|
+
const listeners = resumeListeners.current
|
|
89
|
+
listeners.add(listener)
|
|
90
|
+
return () => void listeners.delete(listener)
|
|
61
91
|
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
)
|
|
92
|
+
}
|
|
93
|
+
}, [dispatch])
|
|
65
94
|
|
|
66
95
|
return <LastActiveGameContext.Provider value={value}>{children}</LastActiveGameContext.Provider>
|
|
67
96
|
}
|
|
@@ -31,11 +31,24 @@ export function PlayRoute() {
|
|
|
31
31
|
const { game: id } = useLocalSearchParams<{ game: string }>()
|
|
32
32
|
const game = usePackGame(id)
|
|
33
33
|
useResumePoint(game?.resumable ? game.id : null)
|
|
34
|
+
useResumeUp()
|
|
34
35
|
if (!game) return <Redirect href='/' />
|
|
35
36
|
const { PlayScreen } = game
|
|
36
37
|
return <PlayScreen key={game.id} />
|
|
37
38
|
}
|
|
38
39
|
|
|
40
|
+
// Tells a launch going back into a game that its play screen is mounted (by the second frame after this one
|
|
41
|
+
// commits), which is what the splash waits for. Nothing for any other play screen.
|
|
42
|
+
function useResumeUp() {
|
|
43
|
+
const { playScreenUp } = useLastActiveGame()
|
|
44
|
+
useEffect(() => {
|
|
45
|
+
let frame = requestAnimationFrame(() => {
|
|
46
|
+
frame = requestAnimationFrame(playScreenUp)
|
|
47
|
+
})
|
|
48
|
+
return () => cancelAnimationFrame(frame)
|
|
49
|
+
}, [playScreenUp])
|
|
50
|
+
}
|
|
51
|
+
|
|
39
52
|
// A resumable game's play screen (GameDefinition.resumable) is where a cold launch comes back to:
|
|
40
53
|
// remembered as it mounts, and forgotten when the player backs out of it (its own back, hardware back
|
|
41
54
|
// or a browser back), which unmounts it while the app is in use. Backgrounding the app leaves the
|
|
@@ -3,7 +3,7 @@ import { IconButton, Pressable } from '@rific/feedback-press'
|
|
|
3
3
|
import { PressAwayOverlay, usePopoverHost, useWellColors, WELL_SHADOW } from '@tastic/hud/chrome'
|
|
4
4
|
import { getProfilePickerContentSize, type Profile, ProfilePicker, type ProfilePickerColorSection } from '@tastic/profile'
|
|
5
5
|
import { router, useFocusEffect, useIsFocused } from 'expo-router'
|
|
6
|
-
import { createContext, memo, type ReactNode, startTransition, useCallback, useContext, useDeferredValue, useEffect, useMemo, useRef, useState } from 'react'
|
|
6
|
+
import { createContext, memo, type ReactNode, startTransition, useCallback, useContext, useDeferredValue, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'
|
|
7
7
|
import { AppState, type AppStateStatus, type LayoutChangeEvent, type NativeScrollEvent, type NativeSyntheticEvent, Platform, type ScrollView, type StyleProp, StyleSheet, View, type ViewStyle } from 'react-native'
|
|
8
8
|
import { Icon, Portal, SegmentedButtons, Text } from 'react-native-paper'
|
|
9
9
|
|
|
@@ -73,17 +73,38 @@ function useResume(game: PackGameDefinition | null) {
|
|
|
73
73
|
)
|
|
74
74
|
}
|
|
75
75
|
|
|
76
|
-
// Whether Home draws its menu. A Home resuming a game draws nothing until the game
|
|
77
|
-
//
|
|
78
|
-
// (useDeferredValue), behind the game's own first renders.
|
|
79
|
-
//
|
|
76
|
+
// Whether Home draws its menu. A Home resuming a game draws nothing until the game's screen has come in
|
|
77
|
+
// (RootLayout's stack says so, or RESUME_SHOWN_MAX_MS is up), so a launch never shows the menu ahead of the
|
|
78
|
+
// game, and then draws it at low priority (useDeferredValue), behind the game's own first renders. Home losing
|
|
79
|
+
// focus isn't enough: that comes as the navigation starts, and a menu drawn then beat the game's own screen to
|
|
80
|
+
// the glass by half a second on a slow phone, seen through the game's transparent screen. A player who is back
|
|
81
|
+
// on Home sooner gets the menu there and then. From then on it's mounted beneath the game like any Home that
|
|
82
|
+
// opened one, so going back to it is quick.
|
|
80
83
|
function useMenuShown(resuming: boolean): boolean {
|
|
84
|
+
const { beginResume, endResume, resumeState, subscribeResume } = useLastActiveGame()
|
|
81
85
|
const isFocused = useIsFocused()
|
|
82
86
|
const [covered, setCovered] = useState(false)
|
|
83
87
|
if (resuming && !covered && !isFocused) setCovered(true)
|
|
84
|
-
|
|
88
|
+
// A layout effect, so the hold is on before anything waiting on the first screen's layout looks.
|
|
89
|
+
useLayoutEffect(() => {
|
|
90
|
+
if (!resuming) return
|
|
91
|
+
beginResume()
|
|
92
|
+
const id = setTimeout(endResume, RESUME_SHOWN_MAX_MS)
|
|
93
|
+
return () => {
|
|
94
|
+
clearTimeout(id)
|
|
95
|
+
endResume()
|
|
96
|
+
}
|
|
97
|
+
}, [resuming, beginResume, endResume])
|
|
98
|
+
const onItsWay = useSyncExternalStore(subscribeResume, resumeState, resumeState) !== 'idle'
|
|
99
|
+
// Before the layout effect a resume isn't on its way yet, so `covered` is what a first render waits for.
|
|
100
|
+
const gameShown = covered && !onItsWay
|
|
101
|
+
return useDeferredValue(!resuming || gameShown || (covered && isFocused))
|
|
85
102
|
}
|
|
86
103
|
|
|
104
|
+
// The longest a resume is waited for, should the stack never say the game's screen came in (the web's says
|
|
105
|
+
// nothing): a game that never opened would hold the splash, and Home's menu, for good.
|
|
106
|
+
export const RESUME_SHOWN_MAX_MS = 4000
|
|
107
|
+
|
|
87
108
|
function HomeMenu() {
|
|
88
109
|
const pack = usePack()
|
|
89
110
|
const showPicker = pack.homePlayerPicker !== false
|