@tastic/shell 0.8.2 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +32 -2
- package/dist/index.d.mts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +192 -161
- package/dist/index.mjs +147 -117
- package/package.json +3 -2
- package/src/RootLayout.tsx +38 -35
- package/src/components/GuideHost.tsx +3 -2
- package/src/components/WindowControlsInsets.tsx +19 -0
- package/src/hooks/useActiveRound.ts +7 -5
- package/src/hooks/useBackBlock.ts +38 -0
- package/src/index.ts +1 -0
- package/src/redux/opponentSlice.ts +2 -2
- package/src/types.ts +8 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tastic/shell",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
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",
|
|
@@ -102,6 +102,7 @@
|
|
|
102
102
|
"expo-font": "~58.0.10",
|
|
103
103
|
"expo-haptics": "~58.0.7",
|
|
104
104
|
"expo-keep-awake": "~58.0.3",
|
|
105
|
+
"expo-linking": "~58.0.17",
|
|
105
106
|
"expo-router": "~58.0.30",
|
|
106
107
|
"expo-splash-screen": "~58.0.13",
|
|
107
108
|
"expo-system-ui": "~58.0.6",
|
|
@@ -152,7 +153,7 @@
|
|
|
152
153
|
"react-native-gesture-handler": ">=3.3.0",
|
|
153
154
|
"react-native-paper": ">=5.15.3",
|
|
154
155
|
"react-native-reanimated": ">=4.7.1",
|
|
155
|
-
"react-native-safe-area-context": ">=5.
|
|
156
|
+
"react-native-safe-area-context": ">=5.11.0",
|
|
156
157
|
"react-redux": ">=9.3.0",
|
|
157
158
|
"redux": ">=5.0.1",
|
|
158
159
|
"redux-persist": ">=6.0.0"
|
package/src/RootLayout.tsx
CHANGED
|
@@ -18,6 +18,7 @@ import { GuideHost } from './components/GuideHost'
|
|
|
18
18
|
import { Providers } from './components/Providers'
|
|
19
19
|
import { Theme } from './components/Theme'
|
|
20
20
|
import { UpdateDialog } from './components/UpdateDialog'
|
|
21
|
+
import { WindowControlsInsets } from './components/WindowControlsInsets'
|
|
21
22
|
import { LastActiveGameProvider } from './hooks/useLastActiveGame'
|
|
22
23
|
import { ProfilesProvider, useProfiles } from './hooks/useProfiles'
|
|
23
24
|
import { PackProvider, usePack } from './PackContext'
|
|
@@ -196,41 +197,43 @@ export function RootLayout({ pack, store, persistor }: RootLayoutProps) {
|
|
|
196
197
|
return (
|
|
197
198
|
<GestureHandlerRootView style={styles.root}>
|
|
198
199
|
<SafeAreaProvider>
|
|
199
|
-
<
|
|
200
|
-
<
|
|
201
|
-
<
|
|
202
|
-
<
|
|
203
|
-
<
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
<
|
|
208
|
-
<
|
|
209
|
-
<
|
|
210
|
-
<
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
<
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
200
|
+
<WindowControlsInsets>
|
|
201
|
+
<PackProvider pack={pack}>
|
|
202
|
+
<Fonts>
|
|
203
|
+
<Providers store={store} persistor={persistor}>
|
|
204
|
+
<Theme>
|
|
205
|
+
<ProfilesProvider>
|
|
206
|
+
{/* Inside Providers' PersistGate, so the game a cold launch resumes (read once, as
|
|
207
|
+
it mounts) is the saved one. */}
|
|
208
|
+
<LastActiveGameProvider>
|
|
209
|
+
<GameProviders games={pack.games}>
|
|
210
|
+
<PackRoot pack={pack}>
|
|
211
|
+
<GatedApp>
|
|
212
|
+
<HapticGatedToastProvider>
|
|
213
|
+
{/* Wraps the stack (rather than sitting beside it like UpdateDialog)
|
|
214
|
+
because Home's tiles and the loadout's How to Play row reach it through
|
|
215
|
+
context (see GuideHost). Inside the toast provider because the card renders
|
|
216
|
+
through a Portal, and inside the gate so it mounts together with Home rather
|
|
217
|
+
than before it. */}
|
|
218
|
+
<GuideHost>
|
|
219
|
+
<AppStack />
|
|
220
|
+
</GuideHost>
|
|
221
|
+
{/* historyButton/clearButton off: there's no toast history to open, and a
|
|
222
|
+
control row for it above the toast stack would go nowhere. limit pins the
|
|
223
|
+
package's current default (3) so a future toaster release can't change it. */}
|
|
224
|
+
{pack.Toaster ? <PackToaster Toaster={pack.Toaster} /> : <RotatingToaster />}
|
|
225
|
+
<UpdateDialog />
|
|
226
|
+
</HapticGatedToastProvider>
|
|
227
|
+
</GatedApp>
|
|
228
|
+
</PackRoot>
|
|
229
|
+
</GameProviders>
|
|
230
|
+
</LastActiveGameProvider>
|
|
231
|
+
</ProfilesProvider>
|
|
232
|
+
</Theme>
|
|
233
|
+
</Providers>
|
|
234
|
+
</Fonts>
|
|
235
|
+
</PackProvider>
|
|
236
|
+
</WindowControlsInsets>
|
|
234
237
|
</SafeAreaProvider>
|
|
235
238
|
</GestureHandlerRootView>
|
|
236
239
|
)
|
|
@@ -53,8 +53,9 @@ export function GuideHost({ children }: Props) {
|
|
|
53
53
|
const seenVersion = useSelector((state: ShellState) => (packGuide ?? gameGuide)?.selectVersionSeen(state) ?? 0)
|
|
54
54
|
const dispatch = useDispatch()
|
|
55
55
|
|
|
56
|
-
// The seat-2 choice the cards describe: the one the player last picked,
|
|
57
|
-
//
|
|
56
|
+
// The seat-2 choice the cards describe: the one the player last picked, or where the game doesn't
|
|
57
|
+
// offer it the CPU (a saved 'nobody' in a game without a solo mode) or, in a game with no CPU, its
|
|
58
|
+
// first choice; nobody in a game for one.
|
|
58
59
|
const mode = roundModeFor(seatTwoFor(seatTwo, game?.seatTwo))
|
|
59
60
|
const steps = useMemo(() => (packGuide ? packGuide.getSteps({ touch }) : gameGuide ? gameGuide.getSteps(input, { touch, mode }) : []), [packGuide, gameGuide, input, touch, mode])
|
|
60
61
|
const onSeen = useCallback(
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { ReactNode } from 'react'
|
|
2
|
+
import { Platform } from 'react-native'
|
|
3
|
+
import { SafeAreaInsetsContext, useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
4
|
+
|
|
5
|
+
// iPadOS 26 draws a window's controls (close, minimize, tile) over the app's top-left corner whenever the app runs
|
|
6
|
+
// in a window (resized, tiled beside another app, Slide Over), and the regular safe area makes no room for them, so
|
|
7
|
+
// every screen's top-left button (a game's Home, Home's trophy, a Back) sat under them and a tap opened the controls
|
|
8
|
+
// instead. UIKit's corner-adapted safe area does make room: the vertical one is the regular insets with the top
|
|
9
|
+
// lowered below the controls in a window, and the same as the regular ones in full screen. Measured on the iPad 13"
|
|
10
|
+
// simulator: top 32 both ways full screen, in portrait and landscape; in a 375x667 window, top 10 regular and 53
|
|
11
|
+
// vertical. So on iPad every screen below gets the vertical insets, and in a window the whole app sits below the
|
|
12
|
+
// controls, like under a title bar. Not on iPhone: it has no window controls, and its vertical inset grows by 18pt in
|
|
13
|
+
// landscape for the rounded corners, which would push every landscape screen down.
|
|
14
|
+
/** Inside the SafeAreaProvider: on iPad, hands every screen the safe area with room for the window controls. */
|
|
15
|
+
export function WindowControlsInsets({ children }: { children: ReactNode }) {
|
|
16
|
+
const vertical = useSafeAreaInsets({ cornerAdaptation: 'vertical' })
|
|
17
|
+
if (Platform.OS !== 'ios' || !Platform.isPad) return <>{children}</>
|
|
18
|
+
return <SafeAreaInsetsContext.Provider value={vertical}>{children}</SafeAreaInsetsContext.Provider>
|
|
19
|
+
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { useSelector } from 'react-redux'
|
|
2
2
|
|
|
3
3
|
import { usePackGame } from '../PackContext'
|
|
4
|
+
import { DEFAULT_OPPONENT } from '../redux/opponentSlice'
|
|
4
5
|
import type { ShellState } from '../redux/shellState'
|
|
5
|
-
import type
|
|
6
|
+
import { type RoundMode, roundModeFor, seatTwoFor } from '../types'
|
|
6
7
|
|
|
7
8
|
// The round a play screen is playing: committed by the loadout when every human player readied up
|
|
8
9
|
// (see liveplaySlice.ts). A play screen reached without one (a direct link, a web reload, or a game
|
|
9
|
-
// with no loadout, which Home opens straight away) plays its game's defaults:
|
|
10
|
-
// solo in a game with no seat 2
|
|
10
|
+
// with no loadout, which Home opens straight away) plays its game's defaults: a fresh install's seat
|
|
11
|
+
// 2 as that game reads it (seatTwoFor), so against the CPU, solo in a game with no seat 2
|
|
12
|
+
// (GameDefinition.seatTwo), and the game's first choice in one without a CPU.
|
|
11
13
|
export function useActiveRound<S extends object>(game: string, defaults: S): { mode: RoundMode; settings: S } {
|
|
12
14
|
const round = useSelector((state: ShellState) => state.liveplay.activeRound)
|
|
13
|
-
const
|
|
14
|
-
if (!round || round.game !== game) return { mode:
|
|
15
|
+
const choices = usePackGame(game)?.seatTwo
|
|
16
|
+
if (!round || round.game !== game) return { mode: roundModeFor(seatTwoFor(DEFAULT_OPPONENT.seatTwo, choices)), settings: defaults }
|
|
15
17
|
return { mode: round.mode, settings: { ...defaults, ...(round.settings as Partial<S>) } }
|
|
16
18
|
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { usePreventRemove } from 'expo-router'
|
|
2
|
+
import { useCallback, useRef, useState } from 'react'
|
|
3
|
+
|
|
4
|
+
import { safeBack } from '../navigation'
|
|
5
|
+
|
|
6
|
+
// Holds a play screen while `held`: every way off it but the returned `quit` (Android's hardware or
|
|
7
|
+
// gesture back, the browser's back, a link) runs `onHeld` instead, which in a game is the
|
|
8
|
+
// `requestBack` from @tastic/hud's useQuitConfirmation, so it opens the same Quit Match? the back chip
|
|
9
|
+
// does (audit F093: Android's back and the browser's back left a match at once). iOS's swipe back is
|
|
10
|
+
// already off on every screen (RootLayout's useThemedRootBackground). `held` is a plain boolean read
|
|
11
|
+
// as the screen renders, not useQuitConfirmation's lazy getter, since expo-router needs to know before
|
|
12
|
+
// a back comes in; a game whose progress comes from a state hook that needs Quit Match?'s `paused`
|
|
13
|
+
// calls this after that hook, with the same test it hands useQuitConfirmation. Off at Game Over, so
|
|
14
|
+
// a back there leaves at once, as the chip does.
|
|
15
|
+
//
|
|
16
|
+
// The block stops every navigation off the screen while it's on, Quit's own included, so `quit` marks
|
|
17
|
+
// the way out first and the block lets that one through with `repeat` (expo-router's way to carry on
|
|
18
|
+
// with a navigation it stopped). The block goes off in the same handler as `repeat`, the order
|
|
19
|
+
// expo-router documents (it warns otherwise): turned off any sooner, it can stand aside after it has
|
|
20
|
+
// stopped the navigation and no longer hand it to this callback, so Quit would do nothing. That was a
|
|
21
|
+
// real bug in DuelTastic (2026-11-06), whose copy this is.
|
|
22
|
+
//
|
|
23
|
+
// While it's on, the web also asks before the page unloads (expo-router's usePreventRemove adds a
|
|
24
|
+
// beforeunload handler with it).
|
|
25
|
+
export function useBackBlock(held: boolean, onHeld: () => void): () => void {
|
|
26
|
+
const leavingRef = useRef(false)
|
|
27
|
+
const [leaving, setLeaving] = useState(false)
|
|
28
|
+
usePreventRemove(held && !leaving, ({ repeat }) => {
|
|
29
|
+
if (leavingRef.current) {
|
|
30
|
+
setLeaving(true)
|
|
31
|
+
repeat()
|
|
32
|
+
} else onHeld()
|
|
33
|
+
})
|
|
34
|
+
return useCallback(() => {
|
|
35
|
+
leavingRef.current = true
|
|
36
|
+
safeBack()
|
|
37
|
+
}, [])
|
|
38
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -20,6 +20,7 @@ export { SettingsDialog, type SettingsDialogProps } from './components/SettingsD
|
|
|
20
20
|
export { useActiveRound } from './hooks/useActiveRound'
|
|
21
21
|
export { useAppSettings } from './hooks/useAppSettings'
|
|
22
22
|
export { useAtComputer } from './hooks/useAtComputer'
|
|
23
|
+
export { useBackBlock } from './hooks/useBackBlock'
|
|
23
24
|
export { useOpponent } from './hooks/useOpponent'
|
|
24
25
|
export { ProfilesProvider, useProfiles } from './hooks/useProfiles'
|
|
25
26
|
export { useSeatColors } from './hooks/useSeatColors'
|
|
@@ -5,8 +5,8 @@ import type { SeatTwo } from '../types'
|
|
|
5
5
|
// Who sits in seat 2, for the whole pack: picked from player 1's opponent button in any game's loadout and
|
|
6
6
|
// kept from one game to the next and across relaunches, since it's usually the same two people.
|
|
7
7
|
// A fresh install starts on the CPU, so one person (App Review included) can tap a game and play.
|
|
8
|
-
// A game
|
|
9
|
-
// types.ts' seatTwoFor).
|
|
8
|
+
// A game that doesn't offer the saved choice reads it as the CPU, or as its first choice in a game
|
|
9
|
+
// with no CPU, so a fresh install opens a CPU-less game on that (see types.ts' seatTwoFor).
|
|
10
10
|
export interface OpponentState {
|
|
11
11
|
seatTwo: SeatTwo
|
|
12
12
|
}
|
package/src/types.ts
CHANGED
|
@@ -24,12 +24,15 @@ export function roundModeFor(seatTwo: SeatTwo): RoundMode {
|
|
|
24
24
|
return seatTwo === 'person' ? 'twoPlayer' : seatTwo === 'nobody' ? 'solo' : 'vsCpu'
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
// Seat 2's saved choice in one game (GameDefinition.seatTwo)
|
|
28
|
-
// game
|
|
29
|
-
//
|
|
27
|
+
// Seat 2's saved choice in one game (GameDefinition.seatTwo). The saved choice is the whole pack's, so
|
|
28
|
+
// a game can be handed one it doesn't offer: that reads as the CPU where the game has one (a saved
|
|
29
|
+
// 'nobody' in a game without a solo mode), and as the game's first choice where it has none (a fresh
|
|
30
|
+
// install's saved CPU, in a game offering ['nobody', 'person'], is Solo). A game with no seat 2 at all
|
|
31
|
+
// (no seatTwo) is always nobody, so it plays solo.
|
|
30
32
|
export function seatTwoFor(saved: SeatTwo, choices: readonly SeatTwo[] | undefined): SeatTwo {
|
|
31
|
-
if (!choices) return 'nobody'
|
|
32
|
-
|
|
33
|
+
if (!choices?.length) return 'nobody'
|
|
34
|
+
if (choices.includes(saved)) return saved
|
|
35
|
+
return choices.includes('cpu') ? 'cpu' : choices[0]
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
// The players who take part in a round and have to press Ready: a CPU and nobody don't.
|