about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authordan <dan.abramov@gmail.com>2024-04-28 22:52:40 +0100
committerGitHub <noreply@github.com>2024-04-28 22:52:40 +0100
commitdfce190cb68603f98fd603ca85e8b39d94f584c0 (patch)
tree811bafc11e81105bc6b0eea3b9733fffe91c9459 /src
parent361d255e954d6afbc0bbae293acf73ac8882f356 (diff)
downloadvoidsky-dfce190cb68603f98fd603ca85e8b39d94f584c0.tar.zst
[iOS] Fix selecting search input on focus (#3746)
* Select search text on focus

* Scope to iOS only
Diffstat (limited to 'src')
-rw-r--r--src/view/screens/Search/Search.tsx10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/view/screens/Search/Search.tsx b/src/view/screens/Search/Search.tsx
index ee9e69433..9c148af5b 100644
--- a/src/view/screens/Search/Search.tsx
+++ b/src/view/screens/Search/Search.tsx
@@ -25,7 +25,7 @@ import {NavigationProp} from '#/lib/routes/types'
 import {augmentSearchQuery} from '#/lib/strings/helpers'
 import {s} from '#/lib/styles'
 import {logger} from '#/logger'
-import {isNative, isWeb} from '#/platform/detection'
+import {isIOS, isNative, isWeb} from '#/platform/detection'
 import {listenSoftReset} from '#/state/events'
 import {useActorAutocompleteQuery} from '#/state/queries/actor-autocomplete'
 import {useActorSearch} from '#/state/queries/actor-search'
@@ -670,11 +670,11 @@ export function SearchScreen(
             ref={textInput}
             placeholder={_(msg`Search`)}
             placeholderTextColor={pal.colors.textLight}
-            selectTextOnFocus={isNative}
             returnKeyType="search"
             value={searchText}
             style={[pal.text, styles.headerSearchInput]}
             keyboardAppearance={theme.colorScheme}
+            selectTextOnFocus={isNative}
             onFocus={() => {
               if (isWeb) {
                 // Prevent a jump on iPad by ensuring that
@@ -684,6 +684,12 @@ export function SearchScreen(
                 })
               } else {
                 setShowAutocomplete(true)
+                if (isIOS) {
+                  // We rely on selectTextOnFocus, but it's broken on iOS:
+                  // https://github.com/facebook/react-native/issues/41988
+                  textInput.current?.setSelection(0, searchText.length)
+                  // We still rely on selectTextOnFocus for it to be instant on Android.
+                }
               }
             }}
             onChangeText={onChangeText}