11/* @flow strict-local */
22import React , { useCallback } from 'react' ;
33import 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
67import type { RouteProp } from '../react-navigation' ;
78import type { AppNavigationProp } from '../nav/AppNavigator' ;
89import type { ApiResponseServerSettings } from '../api/settings/getServerSettings' ;
910import ErrorMsg from '../common/ErrorMsg' ;
1011import ZulipTextIntl from '../common/ZulipTextIntl' ;
11- import SmartUrlInput from '../common/SmartUrlInput' ;
1212import Screen from '../common/Screen' ;
1313import ZulipButton from '../common/ZulipButton' ;
1414import { tryParseUrl } from '../utils/url' ;
1515import * as api from '../api' ;
16- import { createStyleSheet } from '../styles' ;
16+ import { ThemeContext } from '../styles/theme' ;
17+ import { createStyleSheet , HALF_COLOR } from '../styles' ;
1718
1819type Props = $ReadOnly < { |
1920 navigation : AppNavigationProp < 'realm-input' > ,
@@ -31,10 +32,32 @@ const urlFromInputValue = (realmInputValue: string): URL | void => {
3132export 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