Files
orca/mobile/src/components/MobileSearchField.tsx
NeilandKelvin Amoaba 5d61e00c6d build(mobile): upgrade to Expo SDK 58 and React Native 0.88 (#37935)
* build(mobile): upgrade to Expo SDK 58 and React Native 0.88

Expo 58 drops Zod from @expo/cli, which clears the last Zod 3 advisory
(GHSA-mrhx-c7xc-m3w5) in mobile along with its local patch and override.

- Expo 55 -> 58, React Native 0.83 -> 0.88, React 19.3, gesture-handler 3,
  webview 14, reanimated 4.7, worklets 0.13 (SDK 58 bundled versions,
  pinned below today's batch to respect minimumReleaseAge).
- Port the react-native and react-native-webview patches unchanged; drop
  expo-constants, expo-notifications, @expo/cli, expo-router, zod and
  query-string patches plus the zod/query-string/xcode>uuid overrides,
  which upstream fixed or no longer need.
- iOS minimum rises to 16.4 (Expo 58 / RN 0.88 requirement).
- Migrate to RN 0.88 strict types: instance ref types, NamedStyles,
  AppState.currentState, list header/footer nulls.
- Replace removed runtime APIs: InteractionManager -> idle callback with a
  macrotask fallback; StyleSheet.absoluteFillObject -> absoluteFill;
  FileHandle.readBytes -> readBytesSync (it became async).
- Resolve react-native/asset-registry for shared assets in Metro and alias
  the old registry path for react-native-svg in the desktop mobile-web bundle.
- Reduce the iOS scene plugin to the reconnect override; Expo 58's template
  now ships the scene delegate itself.

* fix(mobile): bridge react-native-svg web imports and libsodium runtime for RN 0.88

- Share react-native-svg web shims between the mobile-web build and its render
  checks: map the old asset-registry path to react-native-web's registry and stub
  the Android-only touch-sound TurboModule.
- Patch react-native-libsodium 1.7.0 to read the JSI runtime from the bridge proxy;
  RN 0.88 removed RCTCxxBridge.runtime.

* fix(mobile): use Expo 58's legacy promise resolver for audio permissions

* fix(mobile): skip null handles in the RPC recording timer shims for RN 0.88 types

* style(mobile): format MobilePRSidebar after rebase

* fix(mobile): name RN 0.88 text input refs for declarations; allow queued back in stack render check

- Type text input refs with an exported interface so declaration emit can name hook results
  (RN 0.88 aliases TextInputInstance to an unexported class).
- Expo Router 58 drains back() after a commit; check the interrupted push's exit from the
  frame it starts, bounded to three frames of lag.

* chore(mobile): justify the text input handle interface for React Doctor

* chore(mobile): use a nameable intersection alias for text input refs

* fix(mobile): use sync expo-file-system writes, copies and moves on Expo 58

Expo 58 made File.write/copy/move and FileHandle.writeBytes return promises.
Our callers never awaited them, so failures escaped their try/catch and the
store's tmp-then-move and PDF writes could race their close or rename.

* build(mobile): raise the page bundle budget to 10 MiB for Expo 58

Expo 58 adds about 310 KB to the page: expo-router (+258 KB, now carrying
React Navigation, net about +110 KB) and Reanimated 4.7 (+152 KB). Main had
85 KB of headroom left. 10 MiB still stays within the 10 MiB per-asset contract.

* fix(mobile): drop the window-metrics seed RN 0.88 removed from Android

RN 0.88 no longer holds window metrics: DeviceInfoModule reads the activity's
WindowMetrics on demand and setWindowDisplayMetrics is gone, so MainActivity
no longer compiled. Layout scale still comes from the screen metrics we reseed.

---------

Co-authored-by: Kelvin Amoaba <97001695+AmoabaKelvin@users.noreply.github.com>
2026-11-11 23:30:02 +00:00

160 lines
4.5 KiB
TypeScript

import { useEffect, useRef } from 'react'
import {
Pressable,
View,
type StyleProp,
type TextInputProps,
type ViewStyle,
type TextInputInstance
} from 'react-native'
import { Search, X } from 'lucide-react-native'
import { useMobileTranslation } from '../i18n/use-mobile-translation'
import { colors, radii, spacing } from '../theme/mobile-theme'
import { themedStyleSheet } from '../theme/themed-styles'
import { useMobileColorScheme } from '../theme/use-mobile-color-scheme'
import { TextField } from './composer-input/TextField'
import { runAfterInteractions } from '../platform/after-interactions'
// Delay focus until opening chrome settles; native autoFocus alone often shows caret without iOS/Android keyboard.
const SEARCH_AUTO_FOCUS_DELAY_MS = 120
type MobileSearchFieldProps = {
value: string
onChangeText: (text: string) => void
placeholder: string
onClear?: () => void
/** Override clear-button visibility (default: value is non-empty). */
showClear?: boolean
clearAccessibilityLabel?: string
autoFocus?: boolean
/** Re-run delayed focus when this identity changes (e.g. each time search opens). */
focusKey?: unknown
returnKeyType?: TextInputProps['returnKeyType']
onSubmitEditing?: TextInputProps['onSubmitEditing']
onBlur?: TextInputProps['onBlur']
onFocus?: TextInputProps['onFocus']
editable?: boolean
accessibilityLabel?: string
style?: StyleProp<ViewStyle>
}
export function MobileSearchField({
value,
onChangeText,
placeholder,
onClear,
showClear,
clearAccessibilityLabel,
autoFocus = false,
focusKey,
returnKeyType = 'search',
onSubmitEditing,
onBlur,
onFocus,
editable = true,
accessibilityLabel,
style
}: MobileSearchFieldProps) {
const t = useMobileTranslation()
useMobileColorScheme()
const inputRef = useRef<TextInputInstance>(null)
const clearVisible = showClear ?? value.length > 0
useEffect(() => {
if (!autoFocus || !editable) {
return
}
let timeout: ReturnType<typeof setTimeout> | undefined
// Wait for press/layout completion before focusing so soft keyboard appears.
const task = runAfterInteractions(() => {
timeout = setTimeout(() => {
inputRef.current?.focus()
}, SEARCH_AUTO_FOCUS_DELAY_MS)
})
return () => {
task.cancel()
if (timeout) {
clearTimeout(timeout)
}
}
}, [autoFocus, editable, focusKey])
function handleClear() {
if (onClear) {
onClear()
} else {
onChangeText('')
}
// Clear chip steals focus; restore it so typing can continue without another tap.
requestAnimationFrame(() => {
inputRef.current?.focus()
})
}
return (
<TextField
inputRef={inputRef}
leading={<Search size={16} color={colors.textMuted} />}
trailing={
clearVisible ? (
<Pressable
onPress={handleClear}
hitSlop={8}
accessibilityRole="button"
accessibilityLabel={
clearAccessibilityLabel ?? t('components.searchField.clearSearch', 'Clear search')
}
style={({ pressed }) => [styles.clearButton, pressed && styles.clearButtonPressed]}
>
{/* Use chip and large hit target: bare 14px X looked decorative and was hard to tap. */}
<View style={styles.clearChip}>
<X size={12} color={colors.surfaceBright} strokeWidth={2.6} />
</View>
</Pressable>
) : undefined
}
value={value}
onChangeText={onChangeText}
placeholder={placeholder}
autoCapitalize="none"
autoCorrect={false}
// Still request native auto-focus; the delayed ref focus is the reliable path.
autoFocus={autoFocus}
showSoftInputOnFocus
editable={editable}
returnKeyType={returnKeyType}
onSubmitEditing={onSubmitEditing}
onBlur={onBlur}
onFocus={onFocus}
style={style}
clearButtonMode="never"
accessibilityLabel={accessibilityLabel ?? placeholder}
/>
)
}
const styles = themedStyleSheet(() => ({
clearButton: {
// Pull the 36pt target into the field's end padding so the chip sits near the edge.
marginRight: -spacing.sm,
minWidth: 36,
minHeight: 36,
alignItems: 'center',
justifyContent: 'center'
},
clearButtonPressed: {
opacity: 0.7
},
clearChip: {
width: 24,
height: 24,
borderRadius: radii.pill,
alignItems: 'center',
justifyContent: 'center',
// A solid textMuted chip reads as a control; borderSubtle looked decorative.
backgroundColor: colors.textMuted
}
}))