1
1
/* @flow strict-local */
2
2
import React , { useCallback } from 'react' ;
3
3
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' ;
5
6
6
7
import type { RouteProp } from '../react-navigation' ;
7
8
import type { AppNavigationProp } from '../nav/AppNavigator' ;
8
9
import type { ApiResponseServerSettings } from '../api/settings/getServerSettings' ;
9
10
import ErrorMsg from '../common/ErrorMsg' ;
10
11
import ZulipTextIntl from '../common/ZulipTextIntl' ;
11
- import SmartUrlInput from '../common/SmartUrlInput' ;
12
12
import Screen from '../common/Screen' ;
13
13
import ZulipButton from '../common/ZulipButton' ;
14
14
import { tryParseUrl } from '../utils/url' ;
15
15
import * as api from '../api' ;
16
- import { createStyleSheet } from '../styles' ;
16
+ import { ThemeContext } from '../styles/theme' ;
17
+ import { createStyleSheet , HALF_COLOR } from '../styles' ;
17
18
18
19
type Props = $ReadOnly < { |
19
20
navigation : AppNavigationProp < 'realm-input' > ,
@@ -31,10 +32,32 @@ const urlFromInputValue = (realmInputValue: string): URL | void => {
31
32
export default function RealmInputScreen ( props : Props ) : Node {
32
33
const { navigation, route } = props ;
33
34
35
+ const themeContext = React . useContext ( ThemeContext ) ;
36
+
34
37
const [ progress , setProgress ] = React . useState ( false ) ;
35
38
const [ realmInputValue , setRealmInputValue ] = React . useState ( '' ) ;
36
39
const [ error , setError ] = React . useState ( null ) ;
37
40
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
+
38
61
const tryRealm = React . useCallback ( async ( ) => {
39
62
const parsedRealm = urlFromInputValue ( realmInputValue ) ;
40
63
if ( ! parsedRealm ) {
@@ -71,10 +94,22 @@ export default function RealmInputScreen(props: Props): Node {
71
94
const styles = React . useMemo (
72
95
( ) =>
73
96
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
+ } ,
74
109
hintText : { paddingLeft : 2 , fontSize : 12 } ,
75
110
button : { marginTop : 8 } ,
76
111
} ) ,
77
- [ ] ,
112
+ [ themeContext ] ,
78
113
) ;
79
114
80
115
return (
@@ -87,11 +122,25 @@ export default function RealmInputScreen(props: Props): Node {
87
122
shouldShowLoadingBanner = { false }
88
123
>
89
124
< 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 >
95
144
{ error !== null ? (
96
145
< ErrorMsg error = { error } />
97
146
) : (
0 commit comments