diff --git a/mobile/src/session/__mocks__/mobile-prompt-render-mocks.ts b/mobile/src/session/__mocks__/mobile-prompt-render-mocks.ts index 234399fd0b4..c7c71f6d94d 100644 --- a/mobile/src/session/__mocks__/mobile-prompt-render-mocks.ts +++ b/mobile/src/session/__mocks__/mobile-prompt-render-mocks.ts @@ -28,8 +28,14 @@ vi.mock('react-native-gesture-handler', () => { runOnJS: () => GestureChain onStart: () => GestureChain onUpdate: () => GestureChain + onFinalize: () => GestureChain + } + const chain: GestureChain = { + runOnJS: () => chain, + onStart: () => chain, + onUpdate: () => chain, + onFinalize: () => chain } - const chain: GestureChain = { runOnJS: () => chain, onStart: () => chain, onUpdate: () => chain } return { Gesture: { Simultaneous: () => ({}), Native: () => ({}), Pinch: () => chain }, GestureDetector: 'GestureDetector', diff --git a/mobile/src/session/native-chat/preferences/native-chat-text-settings.ts b/mobile/src/session/native-chat/preferences/native-chat-text-settings.ts index 3dffecb52a8..ea32b57f425 100644 --- a/mobile/src/session/native-chat/preferences/native-chat-text-settings.ts +++ b/mobile/src/session/native-chat/preferences/native-chat-text-settings.ts @@ -77,10 +77,15 @@ function parseSettings(raw: string | null): NativeChatTextSettings | null { type Snapshot = { settings: NativeChatTextSettings; stored: boolean } -let snapshot: Snapshot = { settings: defaultNativeChatTextSettings(), stored: false } +// The phone default until the first storage read, which measures the screen; importing never does. +let snapshot: Snapshot = { + settings: { size: BASE_TEXT_SIZE, font: 'system', lineSpacing: 'default' }, + stored: false +} // A change made while a read is in flight wins over that older read. let changeCount = 0 let writes: Promise = Promise.resolve() +let watchingScreen = false const listeners = new Set<() => void>() function adopt(settings: NativeChatTextSettings | null): void { @@ -101,12 +106,26 @@ function adopt(settings: NativeChatTextSettings | null): void { } } +// A foldable's default follows the screen it is on, until a size is saved. +function watchScreen(): void { + if (watchingScreen) { + return + } + watchingScreen = true + Dimensions.addEventListener('change', () => { + if (!snapshot.stored) { + adopt(null) + } + }) +} + /** Rereads storage; the page calls it when the app republishes storage after a Settings change. */ export function reloadNativeChatTextSettings(): Promise { const readAt = changeCount return Promise.resolve() .then(() => AsyncStorage.getItem(NATIVE_CHAT_TEXT_KEY)) .then((raw) => { + watchScreen() if (changeCount === readAt) { adopt(parseSettings(raw)) } @@ -127,12 +146,6 @@ let hydrated = false const hydration = reloadNativeChatTextSettings().then(() => { hydrated = true }) -// A foldable's default follows the screen it is on, until a size is saved. -Dimensions.addEventListener('change', () => { - if (!snapshot.stored) { - adopt(null) - } -}) function persist(settings: NativeChatTextSettings | null): Promise { changeCount += 1 diff --git a/mobile/src/session/native-chat/transcript/viewport/mobile-native-chat-pinch-zoom.tsx b/mobile/src/session/native-chat/transcript/viewport/mobile-native-chat-pinch-zoom.tsx index e9c2817a593..21d645bec6c 100644 --- a/mobile/src/session/native-chat/transcript/viewport/mobile-native-chat-pinch-zoom.tsx +++ b/mobile/src/session/native-chat/transcript/viewport/mobile-native-chat-pinch-zoom.tsx @@ -1,4 +1,4 @@ -import { useMemo, useRef, useState, type ComponentProps, type ReactNode } from 'react' +import { useEffect, useMemo, useRef, useState, type ComponentProps, type ReactNode } from 'react' import { Gesture, GestureDetector } from 'react-native-gesture-handler' import type { LegacyComposedGesture } from 'react-native-gesture-handler' import { @@ -17,7 +17,9 @@ export function useMobileNativeChatPinchGesture(): { const { size } = useNativeChatTextSettingsFollowingShell() const [pinched, setPinched] = useState(null) const saved = useRef(size) - saved.current = size + useEffect(() => { + saved.current = size + }, [size]) const live = useRef(null) const pinchBase = useRef(size) // Run callbacks on JS to access React state safely; simultaneous native scrolling keeps active lists from stealing pinch recognition.