Skip to content

Commit d7723c5

Browse files
committed
RealmInputScreen [nfc]: Inline SmartUrlInput
1 parent b5424b0 commit d7723c5

File tree

2 files changed

+58
-89
lines changed

2 files changed

+58
-89
lines changed

src/common/SmartUrlInput.js

Lines changed: 0 additions & 80 deletions
This file was deleted.

src/start/RealmInputScreen.js

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
/* @flow strict-local */
22
import React, { useCallback } from 'react';
33
import type { Node } from 'react';
4-
import { Keyboard } from 'react-native';
4+
import { Keyboard, View, TextInput } from 'react-native';
5+
import { useFocusEffect } from '@react-navigation/native';
56

67
import type { RouteProp } from '../react-navigation';
78
import type { AppNavigationProp } from '../nav/AppNavigator';
89
import type { ApiResponseServerSettings } from '../api/settings/getServerSettings';
910
import ErrorMsg from '../common/ErrorMsg';
1011
import ZulipTextIntl from '../common/ZulipTextIntl';
11-
import SmartUrlInput from '../common/SmartUrlInput';
1212
import Screen from '../common/Screen';
1313
import ZulipButton from '../common/ZulipButton';
1414
import { tryParseUrl } from '../utils/url';
1515
import * as api from '../api';
16-
import { createStyleSheet } from '../styles';
16+
import { ThemeContext } from '../styles/theme';
17+
import { createStyleSheet, HALF_COLOR } from '../styles';
1718

1819
type Props = $ReadOnly<{|
1920
navigation: AppNavigationProp<'realm-input'>,
@@ -31,10 +32,32 @@ const urlFromInputValue = (realmInputValue: string): URL | void => {
3132
export default function RealmInputScreen(props: Props): Node {
3233
const { navigation, route } = props;
3334

35+
const themeContext = React.useContext(ThemeContext);
36+
3437
const [progress, setProgress] = React.useState(false);
3538
const [realmInputValue, setRealmInputValue] = React.useState('');
3639
const [error, setError] = React.useState(null);
3740

41+
const textInputRef = React.useRef<React$ElementRef<typeof TextInput> | null>(null);
42+
43+
// When the route is focused in the navigation, focus the input.
44+
// Otherwise, if you go back to this screen from the auth screen, the
45+
// input won't be focused.
46+
useFocusEffect(
47+
useCallback(() => {
48+
if (textInputRef.current) {
49+
// Sometimes the effect of this `.focus()` is immediately undone
50+
// (the keyboard is closed) by a Keyboard.dismiss() from React
51+
// Navigation's internals. Seems like a complex bug, but the symptom
52+
// isn't terrible, it just means that on back-navigating to this
53+
// screen, sometimes the keyboard flicks open then closed, instead
54+
// of just opening. Shrug. See
55+
// https://chat.zulip.org/#narrow/stream/243-mobile-team/topic/realm-input/near/1346690
56+
textInputRef.current.focus();
57+
}
58+
}, []),
59+
);
60+
3861
const tryRealm = React.useCallback(async () => {
3962
const parsedRealm = urlFromInputValue(realmInputValue);
4063
if (!parsedRealm) {
@@ -71,10 +94,22 @@ export default function RealmInputScreen(props: Props): Node {
7194
const styles = React.useMemo(
7295
() =>
7396
createStyleSheet({
97+
inputWrapper: {
98+
flexDirection: 'row',
99+
opacity: 0.8,
100+
marginTop: 16,
101+
marginBottom: 8,
102+
},
103+
input: {
104+
flex: 1,
105+
padding: 0,
106+
fontSize: 20,
107+
color: themeContext.color,
108+
},
74109
hintText: { paddingLeft: 2, fontSize: 12 },
75110
button: { marginTop: 8 },
76111
}),
77-
[],
112+
[themeContext],
78113
);
79114

80115
return (
@@ -87,11 +122,25 @@ export default function RealmInputScreen(props: Props): Node {
87122
shouldShowLoadingBanner={false}
88123
>
89124
<ZulipTextIntl text="Enter your Zulip server URL:" />
90-
<SmartUrlInput
91-
onChangeText={handleRealmChange}
92-
value={realmInputValue}
93-
onSubmitEditing={tryRealm}
94-
/>
125+
<View style={styles.inputWrapper}>
126+
<TextInput
127+
value={realmInputValue}
128+
placeholder="your-org.zulipchat.com"
129+
placeholderTextColor={HALF_COLOR}
130+
style={styles.input}
131+
autoFocus
132+
autoCorrect={false}
133+
autoCapitalize="none"
134+
returnKeyType="go"
135+
onChangeText={handleRealmChange}
136+
blurOnSubmit={false}
137+
keyboardType="url"
138+
underlineColorAndroid="transparent"
139+
onSubmitEditing={tryRealm}
140+
enablesReturnKeyAutomatically
141+
ref={textInputRef}
142+
/>
143+
</View>
95144
{error !== null ? (
96145
<ErrorMsg error={error} />
97146
) : (

0 commit comments

Comments
 (0)