Skip to content
TypeScript

refactor(mobile): reuse shared search fields (#21946)

Julius Marmingea71a6c37d141
diff --git a/apps/mobile/src/features/settings/SettingsOpenSourceLicensesRouteScreen.tsx b/apps/mobile/src/features/settings/SettingsOpenSourceLicensesRouteScreen.tsx
index bc2442478cf..251e62565d8 100644
--- a/apps/mobile/src/features/settings/SettingsOpenSourceLicensesRouteScreen.tsx
+++ b/apps/mobile/src/features/settings/SettingsOpenSourceLicensesRouteScreen.tsx
@@ -1,3 +1,4 @@
+import { SearchField } from "../../components/ui/SearchField";
import { Toolbar } from "../../components/ui/Toolbar";
import { ScreenScrollView as ScrollView } from "../../components/ui/ScreenScrollView";
import { LegendList } from "@legendapp/list/react-native";
@@ -9,12 +10,12 @@ import {
thirdPartyLicenseEntryKey,
type ThirdPartyLicenseEntry,
} from "@t3tools/shared/thirdPartyLicenses";
-import { useCallback, useMemo, useState } from "react";
-import { Linking, Platform, Pressable, View } from "react-native";
+import { useCallback, useMemo, useRef, useState } from "react";
+import { Linking, Platform, Pressable, type TextInputInstance, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { SymbolView } from "../../components/ui/AppSymbol";
-import { AppText as Text, AppTextInput as TextInput } from "../../components/ui/AppText";
+import { AppText as Text } from "../../components/ui/AppText";
import { ListRow } from "../../components/ui/ListRow";
import { SettingsScreen } from "./components/SettingsScreen";
import { NativeStackScreenOptions } from "../../native/StackHeader";
@@ -52,6 +53,7 @@ function LicenseRow(props: {
}
export function SettingsOpenSourceLicensesRouteScreen() {
+ const searchRef = useRef<TextInputInstance>(null);
const navigation = useNavigation();
const insets = useSafeAreaInsets();
const [query, setQuery] = useState("");
@@ -153,14 +155,13 @@ export function SettingsOpenSourceLicensesRouteScreen() {
ListHeaderComponent={
Platform.OS !== "ios" ? (
<View className="px-5 pt-4 pb-5">
- <TextInput
+ <SearchField
+ inputRef={searchRef}
+ autoFocus={false}
accessibilityLabel="Search open-source licenses"
- autoCapitalize="none"
- autoCorrect={false}
- clearButtonMode="while-editing"
+ clearAccessibilityLabel="Clear package search"
onChangeText={setQuery}
placeholder="Search packages"
- returnKeyType="search"
value={query}
/>
</View>
diff --git a/apps/mobile/src/features/threads/NewTaskContextPickerScreens.tsx b/apps/mobile/src/features/threads/NewTaskContextPickerScreens.tsx
index 8ed3d96e5ba..ee055b6bec2 100644
--- a/apps/mobile/src/features/threads/NewTaskContextPickerScreens.tsx
+++ b/apps/mobile/src/features/threads/NewTaskContextPickerScreens.tsx
@@ -1,3 +1,4 @@
+import { SearchField } from "../../components/ui/SearchField";
import { Button } from "../../components/ui/Button";
import { Toolbar } from "../../components/ui/Toolbar";
import * as Dialog from "../../components/ui/Dialog";
@@ -15,7 +16,7 @@ import {
import * as Haptics from "expo-haptics";
import { useNavigation } from "@react-navigation/native";
import { useEffect, useRef, useState, type ReactNode } from "react";
-import { Platform, Pressable, ScrollView, TextInput, View } from "react-native";
+import { Platform, Pressable, ScrollView, View } from "react-native";
import { useSafeAreaInsets } from "react-native-safe-area-context";
import { AndroidScreenHeader } from "../../components/ui/AndroidScreenHeader";
@@ -397,6 +398,7 @@ export function BranchPickerScreen(props: {
readonly onChangeStartFromOrigin: (value: boolean) => void;
};
}) {
+ const searchRef = useRef<import("react-native").TextInputInstance>(null);
const navigation = useNavigation();
const insets = useSafeAreaInsets();
const usesNativeMailSearchToolbar = useNativeMailSearchToolbar();
@@ -516,17 +518,13 @@ export function BranchPickerScreen(props: {
onBack={() => navigation.goBack()}
/>
<View className="bg-header px-4 pb-3 pt-1">
- <TextInput
- autoCapitalize="none"
- autoCorrect={false}
+ <SearchField
+ inputRef={searchRef}
+ autoFocus={false}
accessibilityLabel="Find a branch"
- className="h-12 rounded-full border border-input-border bg-input px-4 font-sans text-base text-foreground"
- selectionColorClassName="accent-focus/32"
- cursorColorClassName="accent-focus"
- selectionHandleColorClassName="accent-focus"
+ clearAccessibilityLabel="Clear branch search"
onChangeText={props.onQueryChange}
placeholder="Find a branch"
- placeholderTextColorClassName="accent-placeholder"
value={props.query}
/>
</View>