|
1 | 1 | /* @flow strict-local */ |
2 | 2 | import React, { useState, useRef, useCallback, useContext } from 'react'; |
3 | 3 | import type { Node } from 'react'; |
4 | | -import { Platform, TextInput, View, Keyboard } from 'react-native'; |
| 4 | +import { TextInput, View } from 'react-native'; |
5 | 5 | import { useFocusEffect } from '@react-navigation/native'; |
6 | 6 | import type { ViewStyleProp } from 'react-native/Libraries/StyleSheet/StyleSheet'; |
7 | 7 |
|
@@ -32,59 +32,6 @@ type Props = $ReadOnly<{| |
32 | 32 | enablesReturnKeyAutomatically: boolean, |
33 | 33 | |}>; |
34 | 34 |
|
35 | | -/** |
36 | | - * Work around https://github.com/facebook/react-native/issues/19366. |
37 | | - * |
38 | | - * The bug: If the keyboard is dismissed only by pressing the built-in |
39 | | - * Android back button, then the next time you call `.focus()` on the |
40 | | - * input, the keyboard won't open again. On the other hand, if you call |
41 | | - * `.blur()`, then the keyboard *will* open the next time you call |
42 | | - * `.focus()`. |
43 | | - * |
44 | | - * This workaround: Call `.blur()` on the input whenever the keyboard is |
45 | | - * closed, because it might have been closed by the built-in Android back |
46 | | - * button. Then when we call `.focus()` the next time, it will open the |
47 | | - * keyboard, as expected. (We only maintain that keyboard-closed listener |
48 | | - * when this SmartUrlInput is on the screen that's focused in the |
49 | | - * navigation.) |
50 | | - * |
51 | | - * Other workarounds that didn't work: |
52 | | - * - When it comes time to do a `.focus()`, do a sneaky `.blur()` first, |
53 | | - * then do the `.focus()` 100ms later. It's janky. This was #2078, |
54 | | - * probably inspired by |
55 | | - * https://github.com/facebook/react-native/issues/19366#issuecomment-400603928. |
56 | | - * - Use RN's `BackHandler` to actually listen for the built-in Android back |
57 | | - * button being used. That didn't work; the event handler wasn't firing |
58 | | - * for either `backPress` or `hardwareBackPress` events. (We never |
59 | | - * committed a version of this workaround.) |
60 | | - */ |
61 | | -function useRn19366Workaround(textInputRef) { |
62 | | - if (Platform.OS !== 'android') { |
63 | | - return; |
64 | | - } |
65 | | - |
66 | | - // (Disabling `react-hooks/rules-of-hooks` here is fine; the relevant rule |
67 | | - // is not to call Hooks conditionally. But the platform conditional won't |
68 | | - // vary in its behavior between multiple renders.) |
69 | | - |
70 | | - // eslint-disable-next-line react-hooks/rules-of-hooks |
71 | | - useFocusEffect( |
72 | | - // eslint-disable-next-line react-hooks/rules-of-hooks |
73 | | - React.useCallback(() => { |
74 | | - const handleKeyboardDidHide = () => { |
75 | | - if (textInputRef.current) { |
76 | | - // `.current` is not type-checked; see definition. |
77 | | - textInputRef.current.blur(); |
78 | | - } |
79 | | - }; |
80 | | - |
81 | | - Keyboard.addListener('keyboardDidHide', handleKeyboardDidHide); |
82 | | - |
83 | | - return () => Keyboard.removeListener('keyboardDidHide', handleKeyboardDidHide); |
84 | | - }, [textInputRef]), |
85 | | - ); |
86 | | -} |
87 | | - |
88 | 35 | export default function SmartUrlInput(props: Props): Node { |
89 | 36 | const { style, onChangeText, onSubmitEditing, enablesReturnKeyAutomatically } = props; |
90 | 37 |
|
@@ -126,8 +73,6 @@ export default function SmartUrlInput(props: Props): Node { |
126 | 73 | [onChangeText], |
127 | 74 | ); |
128 | 75 |
|
129 | | - useRn19366Workaround(textInputRef); |
130 | | - |
131 | 76 | return ( |
132 | 77 | <View style={[styles.wrapper, style]}> |
133 | 78 | <TextInput |
|
0 commit comments