Skip to content

Commit 92c79ff

Browse files
committed
SmartUrlInput [nfc]: Make controlled by caller
1 parent acd4ea0 commit 92c79ff

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
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, useRef, useCallback, useContext } from 'react';
2+
import React, { useRef, useCallback, useContext } from 'react';
33
import type { Node } from 'react';
44
import { TextInput, View } from 'react-native';
55
import { useFocusEffect } from '@react-navigation/native';
@@ -28,21 +28,20 @@ type Props = $ReadOnly<{|
2828

2929
style?: ViewStyleProp,
3030
onChangeText: (value: string) => void,
31+
value: string,
3132
onSubmitEditing: () => Promise<void>,
3233
enablesReturnKeyAutomatically: boolean,
3334
|}>;
3435

3536
export default function SmartUrlInput(props: Props): Node {
36-
const { style, onChangeText, onSubmitEditing, enablesReturnKeyAutomatically } = props;
37+
const { style, onChangeText, value, onSubmitEditing, enablesReturnKeyAutomatically } = props;
3738

3839
// We should replace the fixme with
3940
// `React$ElementRef<typeof TextInput>` when we can. Currently, that
4041
// would make `.current` be `any(implicit)`, which we don't want;
4142
// this is probably down to bugs in Flow's special support for React.
4243
const textInputRef = useRef<$FlowFixMe>();
4344

44-
const [value, setValue] = useState<string>('');
45-
4645
const themeContext = useContext(ThemeContext);
4746

4847
// When the route is focused in the navigation, focus the input.
@@ -65,14 +64,6 @@ export default function SmartUrlInput(props: Props): Node {
6564
}, []),
6665
);
6766

68-
const handleChange = useCallback(
69-
(_value: string) => {
70-
setValue(_value);
71-
onChangeText(_value);
72-
},
73-
[defaultDomain, defaultProtocol, onChangeText],
74-
);
75-
7667
return (
7768
<View style={[styles.wrapper, style]}>
7869
<TextInput
@@ -84,7 +75,7 @@ export default function SmartUrlInput(props: Props): Node {
8475
autoCorrect={false}
8576
autoCapitalize="none"
8677
returnKeyType="go"
87-
onChangeText={handleChange}
78+
onChangeText={onChangeText}
8879
blurOnSubmit={false}
8980
keyboardType="url"
9081
underlineColorAndroid="transparent"

src/start/RealmInputScreen.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ export default function RealmInputScreen(props: Props): Node {
3333
const { navigation } = props;
3434

3535
const [progress, setProgress] = useState<boolean>(false);
36+
37+
// Prepopulate with "https://"; not everyone has memorized that sequence
38+
// of characters.
3639
const [realmInputValue, setRealmInputValue] = useState<string>('');
40+
3741
const [error, setError] = useState<string | null>(null);
3842

3943
const tryRealm = useCallback(async () => {
@@ -83,6 +87,7 @@ export default function RealmInputScreen(props: Props): Node {
8387
style={styles.input}
8488
navigation={navigation}
8589
onChangeText={setRealmInputValue}
90+
value={realmInputValue}
8691
onSubmitEditing={tryRealm}
8792
enablesReturnKeyAutomatically
8893
/>

0 commit comments

Comments
 (0)