@tastic/shell 0.20.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/README.md +4 -4
- package/dist/index.js +166 -53
- package/dist/index.mjs +187 -74
- package/package.json +12 -12
- package/src/RootLayout.tsx +62 -15
- package/src/components/Providers.tsx +6 -3
- package/src/hooks/useLastActiveGame.tsx +34 -5
- package/src/screens/GameRoute.tsx +13 -0
- package/src/screens/HomeScreen.tsx +194 -81
- package/src/splashGate.ts +2 -1
package/src/RootLayout.tsx
CHANGED
|
@@ -7,7 +7,7 @@ import { DialogHeaderStyleProvider, LetteringProvider, ScreenFrame } from '@tast
|
|
|
7
7
|
import { ProfileColorProvider } from '@tastic/profile'
|
|
8
8
|
import * as Haptics from 'expo-haptics'
|
|
9
9
|
import { DarkTheme, DefaultTheme, Stack, ThemeProvider as NavigationThemeProvider } from 'expo-router'
|
|
10
|
-
import { ReactNode, useCallback, useMemo } from 'react'
|
|
10
|
+
import { ReactNode, useCallback, useMemo, useRef } from 'react'
|
|
11
11
|
import { Platform, StyleSheet, View } from 'react-native'
|
|
12
12
|
import { GestureHandlerRootView } from 'react-native-gesture-handler'
|
|
13
13
|
import * as RNPaper from 'react-native-paper'
|
|
@@ -21,11 +21,11 @@ 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'
|
|
28
|
-
import { SplashGate } from './splashGate'
|
|
28
|
+
import { markSplashReady, SplashGate } from './splashGate'
|
|
29
29
|
import type { PackDefinition, PackGameDefinition } from './types'
|
|
30
30
|
|
|
31
31
|
// The pack's root: every provider the shell needs, the pack's games' own providers, and the stack.
|
|
@@ -82,8 +82,59 @@ const TRANSPARENT_CONTENT = { backgroundColor: 'transparent' }
|
|
|
82
82
|
// empty object without them.
|
|
83
83
|
const noScreenOptions = () => ({})
|
|
84
84
|
|
|
85
|
+
// Holds the splash until the stack's first screen is on the glass. The other gates open in the very commit
|
|
86
|
+
// that starts mounting the stack, and on a slow phone React Native draws that commit a second or more later:
|
|
87
|
+
// the splash faded to the theme's plain background and the first screen landed on it after 1 to 1.4 s (an LG
|
|
88
|
+
// Stylo 6, CardTastic). The stack's layout comes with that commit, whatever screen it opens on, and by the
|
|
89
|
+
// second frame after it Android has mounted it (nothing under a held splash is drawn), so the splash fades
|
|
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.
|
|
95
|
+
function useFirstScreenGate() {
|
|
96
|
+
const { resumeState, subscribeResume } = useLastActiveGame()
|
|
97
|
+
const marked = useRef(false)
|
|
98
|
+
return useCallback(() => {
|
|
99
|
+
if (marked.current) return
|
|
100
|
+
marked.current = true
|
|
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])
|
|
116
|
+
}
|
|
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
|
+
|
|
85
134
|
function AppStack() {
|
|
86
135
|
const pack = usePack()
|
|
136
|
+
const onFirstLayout = useFirstScreenGate()
|
|
137
|
+
const screenListeners = useResumeShown()
|
|
87
138
|
const { Backdrop } = pack
|
|
88
139
|
const { dark } = useAutoPaperTheme()
|
|
89
140
|
// Over a backdrop the root stays dark whatever the mode: a backdrop is a dark table (the felt), and a
|
|
@@ -114,19 +165,15 @@ function AppStack() {
|
|
|
114
165
|
const base = darkRoot ? DarkTheme : DefaultTheme
|
|
115
166
|
return { ...base, colors: { ...base.colors, background: navigationBackground } }
|
|
116
167
|
}, [darkRoot, navigationBackground])
|
|
117
|
-
const stack = (
|
|
118
|
-
<NavigationThemeProvider value={navigationTheme}>
|
|
119
|
-
<Stack screenOptions={{ ...rootBackground, statusBarStyle, ...REPLACE_AS_BACK, ...backdropOptions, ...packOptions }}>
|
|
120
|
-
<Stack.Screen name='index' />
|
|
121
|
-
<Stack.Screen name='play/[game]' options={playOptions} />
|
|
122
|
-
</Stack>
|
|
123
|
-
</NavigationThemeProvider>
|
|
124
|
-
)
|
|
125
|
-
if (!Backdrop) return stack
|
|
126
168
|
return (
|
|
127
|
-
<View style={styles.root}>
|
|
128
|
-
<Backdrop />
|
|
129
|
-
{
|
|
169
|
+
<View style={styles.root} onLayout={onFirstLayout}>
|
|
170
|
+
{Backdrop && <Backdrop />}
|
|
171
|
+
<NavigationThemeProvider value={navigationTheme}>
|
|
172
|
+
<Stack screenListeners={screenListeners} screenOptions={{ ...rootBackground, statusBarStyle, ...REPLACE_AS_BACK, ...backdropOptions, ...packOptions }}>
|
|
173
|
+
<Stack.Screen name='index' />
|
|
174
|
+
<Stack.Screen name={PLAY_ROUTE} options={playOptions} />
|
|
175
|
+
</Stack>
|
|
176
|
+
</NavigationThemeProvider>
|
|
130
177
|
</View>
|
|
131
178
|
)
|
|
132
179
|
}
|
|
@@ -20,10 +20,13 @@ interface Props {
|
|
|
20
20
|
|
|
21
21
|
// Generic UI feedback sounds, wired into every Button/IconButton/etc. in the package (see
|
|
22
22
|
// useFeedbackHandlers' `fire`, which already gates these on the sound-enabled setting itself -
|
|
23
|
-
// no need to re-check it here).
|
|
23
|
+
// no need to re-check it here). With sound off the pools make no players at all (`enabled`): each one
|
|
24
|
+
// costs a slow Android phone about 0.1 s of its launch. Read from the store, since this runs above the
|
|
25
|
+
// FeedbackPressProvider it feeds.
|
|
24
26
|
function useShellFeedbackSounds(): FeedbackSounds {
|
|
25
|
-
const
|
|
26
|
-
const
|
|
27
|
+
const enabled = useSelector((state: ShellState) => state.sound.enabled)
|
|
28
|
+
const selection = useAudioPool(require('../../assets/sounds/select.wav'), { enabled })
|
|
29
|
+
const notification = useAudioPool(require('../../assets/sounds/notification.wav'), { enabled })
|
|
27
30
|
return { selection, notification }
|
|
28
31
|
}
|
|
29
32
|
|
|
@@ -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,8 +3,8 @@ 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 { type ReactNode, useCallback, useDeferredValue, useEffect, useMemo, useRef, useState } from 'react'
|
|
7
|
-
import { AppState, type AppStateStatus, type LayoutChangeEvent, type NativeScrollEvent, type NativeSyntheticEvent, type ScrollView, StyleSheet, View } from 'react-native'
|
|
6
|
+
import { createContext, memo, type ReactNode, startTransition, useCallback, useContext, useDeferredValue, useEffect, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from 'react'
|
|
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
|
|
|
10
10
|
import { useGameGuide } from '../components/GuideHost'
|
|
@@ -17,7 +17,7 @@ import { useProfiles } from '../hooks/useProfiles'
|
|
|
17
17
|
import { useSeatColors } from '../hooks/useSeatColors'
|
|
18
18
|
import { usePack } from '../PackContext'
|
|
19
19
|
import { loadoutHref, playHref, profilesHref, STATS_HREF } from '../routes'
|
|
20
|
-
import type {
|
|
20
|
+
import type { PackGameDefinition } from '../types'
|
|
21
21
|
import { HOME_GRID_GAP, HOME_LEFT_PANE_PICKER_GAP, HOME_TILE_PADDING, HOME_TOP_BAND, HOME_WIDE_PANE_GAP, PREVIEW_ASPECT, ROW_PREVIEW_WIDTH, useHomeLayout } from './homeLayout'
|
|
22
22
|
|
|
23
23
|
// Home: who's playing (seat 1, the same seat 1 every loadout starts with), then every game in the
|
|
@@ -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
|
|
@@ -146,14 +167,19 @@ function HomeMenu() {
|
|
|
146
167
|
const triggerStyle = useMemo(() => (pack.Backdrop ? [styles.pill, { backgroundColor: colors.surface }] : undefined), [pack.Backdrop, colors.surface])
|
|
147
168
|
|
|
148
169
|
// The pack's tabs (PackDefinition.homeTabs): one tab's games at a time, the same switch as the stats
|
|
149
|
-
// screen's tabs (on the theme's surface over a backdrop)
|
|
150
|
-
//
|
|
151
|
-
// Home is covered, since Home stays mounted under every screen it opens.
|
|
170
|
+
// screen's tabs (on the theme's surface over a backdrop), each in its own pane (TabPane). The tab is
|
|
171
|
+
// Home's own state, kept while Home is covered, since Home stays mounted under every screen it opens.
|
|
152
172
|
const tabs = pack.homeTabs && pack.homeTabs.length > 1 ? pack.homeTabs : null
|
|
153
173
|
const [tabLabel, setTabLabel] = useState(() => tabs?.[0].label ?? null)
|
|
154
174
|
const tab = tabs ? (tabs.find((t) => t.label === tabLabel) ?? tabs[0]) : null
|
|
155
175
|
const tabButtons = useMemo(() => tabs?.map(({ label }) => ({ value: label, label, labelStyle: pack.labelStyle })) ?? [], [tabs, pack.labelStyle])
|
|
156
176
|
const tabBar = tab && <SegmentedButtons value={tab.label} onValueChange={setTabLabel} buttons={tabButtons} theme={SEGMENT_THEME} style={[styles.tabs, pack.Backdrop && { backgroundColor: colors.surface }]} />
|
|
177
|
+
const panes = useMemo(() => (tabs ? tabs.map((t) => ({ key: t.label, games: pack.games.filter(t.includes) })) : [{ key: ALL_GAMES, games: pack.games }]), [tabs, pack.games])
|
|
178
|
+
const shownPane = tab?.label ?? ALL_GAMES
|
|
179
|
+
// One element for as long as nothing it shows changes: a hero is animated art (Solitaire's a fan of five
|
|
180
|
+
// cards), and Home's own state (a tab, a menu, a sheet) is never its business.
|
|
181
|
+
const { width: fitWidth, height: fitHeight } = layout.heroFit ?? NO_FIT
|
|
182
|
+
const hero = useMemo(() => <pack.HeroTitle words={pack.wordmark} color={fg} p1Color={p1Color} p2Color={p2Color} active={heroActive} fit={isWide && fitWidth !== undefined ? { width: fitWidth, height: fitHeight } : undefined} />, [pack, fg, p1Color, p2Color, heroActive, isWide, fitWidth, fitHeight])
|
|
157
183
|
const columnClamp = useClampOnShrink()
|
|
158
184
|
const gridClamp = useClampOnShrink()
|
|
159
185
|
|
|
@@ -188,47 +214,49 @@ function HomeMenu() {
|
|
|
188
214
|
sheet renders inside it instead (see RulesHost). */}
|
|
189
215
|
<View style={styles.frame}>
|
|
190
216
|
<RulesHost enabled={pack.games.some((game) => game.Rules)}>
|
|
191
|
-
{
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
217
|
+
<PreviewsRevealed value={previewsRevealed}>
|
|
218
|
+
{isWide ? (
|
|
219
|
+
<>
|
|
220
|
+
{pressAway}
|
|
221
|
+
{/* Right pane: the game grid, scrolling on its own beside the left pane. The scroller runs
|
|
195
222
|
to the frame's right edge and the cog's gutter is its content's padding, so a web scrollbar
|
|
196
223
|
sits at the window's edge. Both scrollers fade out at an edge while there is more past it
|
|
197
224
|
(auto-paper's FadingScrollView, a mask, so whatever is behind shows through). */}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
225
|
+
<FadingScrollView {...(tab && gridClamp)} style={[styles.wideRightPane, { left: layout.paddingLeft + layout.leftPaneWidth + HOME_WIDE_PANE_GAP }]} contentContainerStyle={{ paddingTop: 16 + insets.top, paddingBottom: 16 + insets.bottom, paddingRight: layout.paddingRight }}>
|
|
226
|
+
{tabBar && <View style={[styles.wideTabs, { width: layout.rightPaneWidth }]}>{tabBar}</View>}
|
|
227
|
+
<View style={{ width: layout.rightPaneWidth }}>
|
|
228
|
+
<TabPanes panes={panes} shown={shownPane} buildOthers={isFocused} style={styles.grid}>
|
|
229
|
+
{(games, built) => <GameGrid games={games} built={built} width={layout.tileWidth} previewWidth={layout.previewWidth} dark={dark} p1Color={p1Color} p2Color={p2Color} onOpen={openGame} onRules={openRules} />}
|
|
230
|
+
</TabPanes>
|
|
231
|
+
</View>
|
|
232
|
+
</FadingScrollView>
|
|
233
|
+
{/* Left pane: the hero, then seat 1's button, centred as one group under the corner
|
|
207
234
|
buttons' band. A later sibling of the grid, lifted while seat 1's menu is open so the menu
|
|
208
235
|
paints over the tiles. box-none: only its controls claim taps. */}
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
236
|
+
<View style={[styles.wideLeftPane, { left: layout.paddingLeft, width: layout.leftPaneWidth, paddingTop: HOME_TOP_BAND + insets.top, paddingBottom: 16 + insets.bottom }, pickerHost.openId !== null && styles.pickerOpen]}>
|
|
237
|
+
{hero}
|
|
238
|
+
{showPicker && <View style={styles.widePicker}>{picker}</View>}
|
|
239
|
+
</View>
|
|
240
|
+
</>
|
|
241
|
+
) : (
|
|
242
|
+
<FadingScrollView {...(tab && columnClamp)} style={styles.scroll} contentContainerStyle={[styles.content, { paddingTop: 56 + insets.top, paddingBottom: 24 + insets.bottom, paddingLeft: 16 + insets.left, paddingRight: 16 + insets.right }]}>
|
|
243
|
+
{pressAway}
|
|
244
|
+
{hero}
|
|
245
|
+
|
|
246
|
+
{/* Who's playing: seat 1's button, the same one each loadout starts with. Lifted above the
|
|
220
247
|
tiles while its menu is open, so the menu paints over them. */}
|
|
221
|
-
|
|
248
|
+
{showPicker && <View style={[styles.picker, pickerHost.openId !== null && styles.pickerOpen]}>{picker}</View>}
|
|
222
249
|
|
|
223
|
-
|
|
250
|
+
{tabBar && <View style={styles.listWidth}>{tabBar}</View>}
|
|
224
251
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
252
|
+
<View style={styles.listWidth}>
|
|
253
|
+
<TabPanes panes={panes} shown={shownPane} buildOthers={isFocused} style={styles.list}>
|
|
254
|
+
{(games, built) => <GameList games={games} built={built} dark={dark} p1Color={p1Color} p2Color={p2Color} onOpen={openGame} onRules={openRules} />}
|
|
255
|
+
</TabPanes>
|
|
256
|
+
</View>
|
|
257
|
+
</FadingScrollView>
|
|
258
|
+
)}
|
|
259
|
+
</PreviewsRevealed>
|
|
232
260
|
|
|
233
261
|
<IconButton icon='trophy' iconColor={fg} size={24} style={[styles.corner, { top: 8 + insets.top, left: 8 + insets.left }]} onPress={() => router.push(STATS_HREF)} accessibilityLabel='Stats & Achievements' />
|
|
234
262
|
<IconButton icon='cog' iconColor={fg} size={24} style={[styles.corner, { top: 8 + insets.top, right: 8 + insets.right }]} onPress={() => setSettingsOpen(true)} accessibilityLabel='Settings' />
|
|
@@ -249,11 +277,83 @@ const SEAT_ONE_PICKER = 'home-p1'
|
|
|
249
277
|
// No placement of the pack's own: hud places the menu itself.
|
|
250
278
|
const noPickerAlign = () => undefined
|
|
251
279
|
|
|
252
|
-
//
|
|
253
|
-
|
|
254
|
-
|
|
280
|
+
// The upright layout's hero has no box to fit.
|
|
281
|
+
const NO_FIT: { width?: number; height: number } = { height: 0 }
|
|
282
|
+
|
|
283
|
+
// The one pane's key in a pack without tabs.
|
|
284
|
+
const ALL_GAMES = '__all__'
|
|
285
|
+
|
|
286
|
+
interface TabPanesProps {
|
|
287
|
+
panes: readonly { key: string; games: readonly PackGameDefinition[] }[]
|
|
288
|
+
// The key of the one shown.
|
|
289
|
+
shown: string
|
|
290
|
+
// Home is on screen, so the others may be built.
|
|
291
|
+
buildOthers: boolean
|
|
292
|
+
// Each pane's own style: a list or a grid.
|
|
293
|
+
style: StyleProp<ViewStyle>
|
|
294
|
+
children: (games: readonly PackGameDefinition[], built: number) => ReactNode
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
// Every tab's games, one pane shown (a pack without tabs has the one pane). Its own component, so building
|
|
298
|
+
// the others game by game renders nothing else of Home.
|
|
299
|
+
function TabPanes({ panes, shown, buildOthers, style, children }: TabPanesProps) {
|
|
300
|
+
const mostGames = Math.max(...panes.map(({ games }) => games.length))
|
|
301
|
+
const builtGames = useBuiltGames(shown, mostGames, buildOthers && panes.length > 1)
|
|
302
|
+
return panes.map(({ key, games }) => {
|
|
303
|
+
const built = builtGames(key)
|
|
304
|
+
if (built === 0) return null
|
|
305
|
+
return (
|
|
306
|
+
<TabPane key={key} shown={key === shown} style={style}>
|
|
307
|
+
{children(games, built)}
|
|
308
|
+
</TabPane>
|
|
309
|
+
)
|
|
310
|
+
})
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
// How many of each tab's games are built: all of the one shown, and of every other none until Home has been
|
|
314
|
+
// on screen for OTHER_PANES_DELAY_MS, then one more every OTHER_PANES_STEP_MS, each in a transition behind
|
|
315
|
+
// anything the player does. Building every game at once held a launch up by a second and a half on a slow
|
|
316
|
+
// phone (Solitaire's two-player tiles, on an LG Stylo 6), for games nobody had asked to see yet, and building
|
|
317
|
+
// the other tab in one go froze Home for half a second just as it came up. A tab picked sooner is built there
|
|
318
|
+
// and then, and stays built. The web builds them all at once, so a static export's page still names every game.
|
|
319
|
+
function useBuiltGames(shown: string, total: number, buildOthers: boolean): (pane: string) => number {
|
|
320
|
+
const [picked, setPicked] = useState<readonly string[]>([shown])
|
|
321
|
+
if (!picked.includes(shown)) setPicked([...picked, shown])
|
|
322
|
+
const [others, setOthers] = useState(Platform.OS === 'web' ? total : 0)
|
|
323
|
+
const building = buildOthers && others < total
|
|
324
|
+
useEffect(() => {
|
|
325
|
+
if (!building) return
|
|
326
|
+
const id = setTimeout(() => startTransition(() => setOthers(others + 1)), others === 0 ? OTHER_PANES_DELAY_MS : OTHER_PANES_STEP_MS)
|
|
327
|
+
return () => clearTimeout(id)
|
|
328
|
+
}, [building, others])
|
|
329
|
+
return (pane) => (pane === shown || picked.includes(pane) ? total : others)
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// How long Home is on screen before the other tabs are built: past a launch's own work (previews, the
|
|
333
|
+
// hero's entrance), and before most players reach for another tab.
|
|
334
|
+
export const OTHER_PANES_DELAY_MS = 1200
|
|
335
|
+
// Between one game of the other tabs and the next, which leaves the phone more time idle than building.
|
|
336
|
+
export const OTHER_PANES_STEP_MS = 150
|
|
337
|
+
|
|
338
|
+
// One tab's games. A pane that isn't shown stays mounted, off the layout and out of a screen reader's way.
|
|
339
|
+
// On a phone it's drawn at opacity 0 over the shown pane's place, never display: none: React Native doesn't
|
|
340
|
+
// mount a display: none view's children at all, so every switch made one tab's native views afresh and
|
|
341
|
+
// deleted the other's (a frame of 0.4 to 0.5 s on a slow phone). The web has no such cost, and display: none
|
|
342
|
+
// also takes the hidden games out of the Tab key's way there. collapsable={false} keeps the pane one native
|
|
343
|
+
// view whichever way it's styled; otherwise the change of opacity would flatten and rebuild what's in it.
|
|
344
|
+
function TabPane({ shown, style, children }: { shown: boolean; style: StyleProp<ViewStyle>; children: ReactNode }) {
|
|
345
|
+
return (
|
|
346
|
+
<View collapsable={false} aria-hidden={!shown} style={[style, !shown && styles.paneHidden]}>
|
|
347
|
+
{children}
|
|
348
|
+
</View>
|
|
349
|
+
)
|
|
255
350
|
}
|
|
256
351
|
|
|
352
|
+
// Whether a game's preview may draw yet (see previewsRevealed). A context rather than a prop, so revealing
|
|
353
|
+
// them draws the previews and nothing else of every row.
|
|
354
|
+
const PreviewsRevealedContext = createContext(false)
|
|
355
|
+
const PreviewsRevealed = PreviewsRevealedContext.Provider
|
|
356
|
+
|
|
257
357
|
// iOS leaves a scroller's offset past the end when its content shrinks (React Native's own TODO, T190695447
|
|
258
358
|
// in RCTScrollViewComponentView.mm), so a switch to a shorter tab while scrolled down would leave blank space
|
|
259
359
|
// under the last game until the next drag. This pulls it back in, as Android and the web do by themselves.
|
|
@@ -297,18 +397,31 @@ function RulesHost({ enabled, children }: { enabled: boolean; children: ReactNod
|
|
|
297
397
|
return enabled ? <Portal.Host>{children}</Portal.Host> : <>{children}</>
|
|
298
398
|
}
|
|
299
399
|
|
|
300
|
-
interface
|
|
301
|
-
|
|
302
|
-
//
|
|
303
|
-
|
|
400
|
+
interface GamesProps {
|
|
401
|
+
games: readonly PackGameDefinition[]
|
|
402
|
+
// How many of them are built so far (useBuiltGames).
|
|
403
|
+
built: number
|
|
304
404
|
dark: boolean
|
|
305
405
|
p1Color: string
|
|
306
406
|
p2Color: string
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
407
|
+
onOpen: (game: PackGameDefinition) => void
|
|
408
|
+
onRules: (game: PackGameDefinition) => void
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
// A pane's games as rows, or as tiles in the wide layout's grid. Memoized, and each row and tile too, so
|
|
412
|
+
// switching tabs, opening the player menu, building one more game or anything else Home's own state holds
|
|
413
|
+
// renders no other game: Home is every game in the pack, about a thousand components in Solitaire, and a
|
|
414
|
+
// switch that rendered them all took 0.3 s of a slow phone's JS.
|
|
415
|
+
const GameList = memo(function GameList({ games, built, ...rest }: GamesProps) {
|
|
416
|
+
return games.slice(0, built).map((game) => <GameRow key={game.id} game={game} {...rest} />)
|
|
417
|
+
})
|
|
418
|
+
|
|
419
|
+
const GameGrid = memo(function GameGrid({ games, built, ...rest }: GamesProps & { width: number; previewWidth: number }) {
|
|
420
|
+
return games.slice(0, built).map((game) => <GameTile key={game.id} game={game} {...rest} />)
|
|
421
|
+
})
|
|
422
|
+
|
|
423
|
+
interface GameRowProps extends Omit<GamesProps, 'games' | 'built'> {
|
|
424
|
+
game: PackGameDefinition
|
|
312
425
|
}
|
|
313
426
|
|
|
314
427
|
// One game on its own well: its icon at app-icon size (the art was drawn as an app icon), or its
|
|
@@ -317,16 +430,16 @@ interface GameRowProps {
|
|
|
317
430
|
// How many lines a row's blurb may wrap to before it's cut off.
|
|
318
431
|
export const ROW_BLURB_LINES = 3
|
|
319
432
|
|
|
320
|
-
function GameRow({ game,
|
|
433
|
+
const GameRow = memo(function GameRow({ game, dark, p1Color, p2Color, onOpen, onRules }: GameRowProps) {
|
|
321
434
|
const { titleStyle } = usePack()
|
|
322
435
|
const well = useWellColors()
|
|
323
436
|
const GameIcon = game.icon
|
|
324
437
|
return (
|
|
325
438
|
// The rules button sits beside the row's own button, laid over its end, not inside it: a button
|
|
326
439
|
// inside a button is invalid on the web.
|
|
327
|
-
<View
|
|
328
|
-
<Pressable onPress={
|
|
329
|
-
{game.Preview ? <PreviewBox game={game} width={ROW_PREVIEW_WIDTH}
|
|
440
|
+
<View>
|
|
441
|
+
<Pressable onPress={() => onOpen(game)} style={[styles.row, { backgroundColor: well.bg }]} accessibilityRole='button' accessibilityLabel={game.title}>
|
|
442
|
+
{game.Preview ? <PreviewBox game={game} width={ROW_PREVIEW_WIDTH} dark={dark} p1Color={p1Color} p2Color={p2Color} /> : <View style={[styles.rowIcon, { backgroundColor: dark ? ICON_DARK_BG : ICON_LIGHT_BG }]}>{GameIcon && <GameIcon size={ROW_ICON_SIZE} p1Color={p1Color} p2Color={p2Color} dark={dark} />}</View>}
|
|
330
443
|
<View style={styles.rowText}>
|
|
331
444
|
<Text variant='titleLarge' style={[styles.rowTitle, { color: well.fg }, titleStyle]} numberOfLines={1}>
|
|
332
445
|
{game.title}
|
|
@@ -338,14 +451,14 @@ function GameRow({ game, hidden, dark, p1Color, p2Color, previewRevealed, onPres
|
|
|
338
451
|
</Text>
|
|
339
452
|
</View>
|
|
340
453
|
</Pressable>
|
|
341
|
-
{
|
|
342
|
-
<Pressable onPress={onRules} style={styles.rulesButton} hitSlop={12} accessibilityRole='button' accessibilityLabel={`${game.title} rules`}>
|
|
454
|
+
{hasRules(game) && (
|
|
455
|
+
<Pressable onPress={() => onRules(game)} style={styles.rulesButton} hitSlop={12} accessibilityRole='button' accessibilityLabel={`${game.title} rules`}>
|
|
343
456
|
<Icon source='information-outline' size={22} color={well.fgMuted} />
|
|
344
457
|
</Pressable>
|
|
345
458
|
)}
|
|
346
459
|
</View>
|
|
347
460
|
)
|
|
348
|
-
}
|
|
461
|
+
})
|
|
349
462
|
|
|
350
463
|
interface GameTileProps extends GameRowProps {
|
|
351
464
|
width: number
|
|
@@ -355,13 +468,13 @@ interface GameTileProps extends GameRowProps {
|
|
|
355
468
|
// One game in the wide layout's grid: the row turned on its side, its preview (or icon) on top and its
|
|
356
469
|
// name and blurb under it, since a row needs ~290pt, more than a grid column beside the hero has. The
|
|
357
470
|
// rules button floats over the preview's corner, beside the tile's button rather than inside it.
|
|
358
|
-
function GameTile({ game,
|
|
471
|
+
const GameTile = memo(function GameTile({ game, width, previewWidth, dark, p1Color, p2Color, onOpen, onRules }: GameTileProps) {
|
|
359
472
|
const { titleStyle } = usePack()
|
|
360
473
|
const well = useWellColors()
|
|
361
474
|
return (
|
|
362
|
-
<View style={
|
|
363
|
-
<Pressable onPress={
|
|
364
|
-
<PreviewBox game={game} width={previewWidth}
|
|
475
|
+
<View style={{ width }}>
|
|
476
|
+
<Pressable onPress={() => onOpen(game)} style={[styles.tile, { backgroundColor: well.bg }]} accessibilityRole='button' accessibilityLabel={game.title}>
|
|
477
|
+
<PreviewBox game={game} width={previewWidth} dark={dark} p1Color={p1Color} p2Color={p2Color} />
|
|
365
478
|
<Text variant='titleMedium' style={[styles.rowTitle, { color: well.fg }, titleStyle]} numberOfLines={1}>
|
|
366
479
|
{game.title}
|
|
367
480
|
</Text>
|
|
@@ -369,19 +482,18 @@ function GameTile({ game, hidden, width, previewWidth, dark, p1Color, p2Color, p
|
|
|
369
482
|
{game.blurb}
|
|
370
483
|
</Text>
|
|
371
484
|
</Pressable>
|
|
372
|
-
{
|
|
373
|
-
<Pressable onPress={onRules} style={styles.tileRulesButton} hitSlop={12} accessibilityRole='button' accessibilityLabel={`${game.title} rules`}>
|
|
485
|
+
{hasRules(game) && (
|
|
486
|
+
<Pressable onPress={() => onRules(game)} style={styles.tileRulesButton} hitSlop={12} accessibilityRole='button' accessibilityLabel={`${game.title} rules`}>
|
|
374
487
|
<Icon source='information-outline' size={20} color='#FFFFFF' />
|
|
375
488
|
</Pressable>
|
|
376
489
|
)}
|
|
377
490
|
</View>
|
|
378
491
|
)
|
|
379
|
-
}
|
|
492
|
+
})
|
|
380
493
|
|
|
381
494
|
interface PreviewBoxProps {
|
|
382
495
|
game: PackGameDefinition
|
|
383
496
|
width: number
|
|
384
|
-
revealed: boolean
|
|
385
497
|
dark: boolean
|
|
386
498
|
p1Color: string
|
|
387
499
|
p2Color: string
|
|
@@ -389,7 +501,8 @@ interface PreviewBoxProps {
|
|
|
389
501
|
|
|
390
502
|
// A box of the preview's shape (PREVIEW_ASPECT) holding the game's preview, once Home has painted, or
|
|
391
503
|
// its icon centred where it has none (a tile in a pack where only some games have one).
|
|
392
|
-
function PreviewBox({ game, width,
|
|
504
|
+
function PreviewBox({ game, width, dark, p1Color, p2Color }: PreviewBoxProps) {
|
|
505
|
+
const revealed = useContext(PreviewsRevealedContext)
|
|
393
506
|
const height = Math.round(width / PREVIEW_ASPECT)
|
|
394
507
|
const { Preview, icon: GameIcon } = game
|
|
395
508
|
const iconSize = Math.min(height, ROW_ICON_SIZE)
|
|
@@ -434,21 +547,21 @@ const styles = StyleSheet.create({
|
|
|
434
547
|
flexWrap: 'wrap',
|
|
435
548
|
gap: HOME_GRID_GAP
|
|
436
549
|
},
|
|
437
|
-
//
|
|
438
|
-
hidden: {
|
|
439
|
-
display: 'none'
|
|
440
|
-
},
|
|
441
|
-
// Solitaire's list: one column, never wider than a phone's, centred on a wide screen.
|
|
550
|
+
// Solitaire's list: one column.
|
|
442
551
|
list: {
|
|
443
|
-
gap: 14
|
|
444
|
-
maxWidth: 480,
|
|
445
|
-
width: '100%'
|
|
552
|
+
gap: 14
|
|
446
553
|
},
|
|
447
|
-
// The list's width,
|
|
554
|
+
// The list's width, and the tabs' over it: never wider than a phone's, centred on a wide screen.
|
|
448
555
|
listWidth: {
|
|
449
556
|
maxWidth: 480,
|
|
450
557
|
width: '100%'
|
|
451
558
|
},
|
|
559
|
+
// A tab's pane that isn't shown (TabPane): out of the layout, over the shown pane's place, drawing
|
|
560
|
+
// nothing.
|
|
561
|
+
paneHidden: Platform.select<ViewStyle>({
|
|
562
|
+
web: { display: 'none' },
|
|
563
|
+
default: { left: 0, opacity: 0, pointerEvents: 'none', position: 'absolute', right: 0, top: 0 }
|
|
564
|
+
})!,
|
|
452
565
|
picker: {
|
|
453
566
|
alignItems: 'center'
|
|
454
567
|
},
|