Skip to content

Commit 5ab469d

Browse files
committed
SmartUrlInput [nfc]: Make value controlled by caller
1 parent d6d9731 commit 5ab469d

File tree

2 files changed

+9
-14
lines changed

2 files changed

+9
-14
lines changed

src/common/SmartUrlInput.js

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* @flow strict-local */
2-
import React, { useState, useCallback, useContext } from 'react';
2+
import React, { useCallback, useContext } from 'react';
33
import type { Node } from 'react';
44
import { TextInput, View } from 'react-native';
55
import { useFocusEffect } from '@react-navigation/native';
@@ -22,16 +22,15 @@ const styles = createStyleSheet({
2222

2323
type Props = $ReadOnly<{|
2424
onChangeText: (value: string) => void,
25+
value: string,
2526
onSubmitEditing: () => Promise<void>,
2627
|}>;
2728

2829
export default function SmartUrlInput(props: Props): Node {
29-
const { onChangeText, onSubmitEditing } = props;
30+
const { onChangeText, value, onSubmitEditing } = props;
3031

3132
const textInputRef = React.useRef<React$ElementRef<typeof TextInput> | null>(null);
3233

33-
const [value, setValue] = useState<string>('');
34-
3534
const themeContext = useContext(ThemeContext);
3635

3736
// When the route is focused in the navigation, focus the input.
@@ -52,14 +51,6 @@ export default function SmartUrlInput(props: Props): Node {
5251
}, []),
5352
);
5453

55-
const handleChange = useCallback(
56-
(_value: string) => {
57-
setValue(_value);
58-
onChangeText(_value);
59-
},
60-
[onChangeText],
61-
);
62-
6354
return (
6455
<View style={styles.wrapper}>
6556
<TextInput
@@ -71,7 +62,7 @@ export default function SmartUrlInput(props: Props): Node {
7162
autoCorrect={false}
7263
autoCapitalize="none"
7364
returnKeyType="go"
74-
onChangeText={handleChange}
65+
onChangeText={onChangeText}
7566
blurOnSubmit={false}
7667
keyboardType="url"
7768
underlineColorAndroid="transparent"

src/start/RealmInputScreen.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,11 @@ export default function RealmInputScreen(props: Props): Node {
8787
shouldShowLoadingBanner={false}
8888
>
8989
<ZulipTextIntl text="Enter your Zulip server URL:" />
90-
<SmartUrlInput onChangeText={handleRealmChange} onSubmitEditing={tryRealm} />
90+
<SmartUrlInput
91+
onChangeText={handleRealmChange}
92+
value={realmInputValue}
93+
onSubmitEditing={tryRealm}
94+
/>
9195
{error !== null ? (
9296
<ErrorMsg error={error} />
9397
) : (

0 commit comments

Comments
 (0)