tangled
alpha
login
or
join now
robinwobin.dev
/
witchsky.app
forked from
jollywhoppers.com/witchsky.app
0
fork
atom
Bluesky app fork with some witchin' additions 💫
0
fork
atom
overview
issues
pulls
pipelines
fix collapsed input issue
samuel.fm
2 years ago
8316f97e
a06f6ada
+157
-148
1 changed file
expand all
collapse all
unified
split
src
screens
Login
LoginForm.tsx
+157
-148
src/screens/Login/LoginForm.tsx
···
2
2
import {
3
3
ActivityIndicator,
4
4
Keyboard,
5
5
+
ScrollView,
5
6
TextInput,
6
7
TouchableOpacity,
7
8
View,
···
21
22
import {useLingui} from '@lingui/react'
22
23
import {useDialogControl} from '#/components/Dialog'
23
24
import {ServerInputDialog} from '../../view/com/auth/server-input'
24
24
-
import {Button} from '#/components/Button'
25
25
+
import {Button, ButtonText} from '#/components/Button'
25
26
import {isAndroid} from '#/platform/detection'
26
27
import {atoms as a, useBreakpoints, useTheme} from '#/alf'
27
28
import {Text} from '#/components/Typography'
···
43
44
setServiceUrl,
44
45
onPressRetryConnect,
45
46
onPressBack,
47
47
+
onPressForgotPassword,
46
48
}: {
47
49
error: string
48
50
serviceUrl: string
···
129
131
130
132
const isReady = !!serviceDescription && !!identifier && !!password
131
133
return (
132
132
-
<View testID="loginForm" style={[a.gap_lg, !gtMobile && a.px_lg]}>
133
133
-
<ServerInputDialog
134
134
-
control={serverInputControl}
135
135
-
onSelect={setServiceUrl}
136
136
-
/>
134
134
+
<ScrollView testID="loginForm" style={a.h_full}>
135
135
+
<View style={[a.gap_lg, !gtMobile && a.px_lg, a.flex_1]}>
136
136
+
<ServerInputDialog
137
137
+
control={serverInputControl}
138
138
+
onSelect={setServiceUrl}
139
139
+
/>
137
140
138
138
-
<View>
139
139
-
<TextField.Label>
140
140
-
<Trans>Hosting provider</Trans>
141
141
-
</TextField.Label>
142
142
-
<TouchableOpacity
143
143
-
accessibilityRole="button"
144
144
-
style={[
145
145
-
a.w_full,
146
146
-
a.flex_row,
147
147
-
a.align_center,
148
148
-
a.rounded_sm,
149
149
-
a.px_md,
150
150
-
a.gap_xs,
151
151
-
{paddingVertical: isAndroid ? 14 : 9},
152
152
-
t.atoms.bg_contrast_25,
153
153
-
]}
154
154
-
onPress={onPressSelectService}>
155
155
-
<TextField.Icon icon={Globe} />
156
156
-
<Text style={[a.text_md]}>{toNiceDomain(serviceUrl)}</Text>
157
157
-
<View
141
141
+
<View>
142
142
+
<TextField.Label>
143
143
+
<Trans>Hosting provider</Trans>
144
144
+
</TextField.Label>
145
145
+
<TouchableOpacity
146
146
+
accessibilityRole="button"
158
147
style={[
148
148
+
a.w_full,
149
149
+
a.flex_row,
150
150
+
a.align_center,
159
151
a.rounded_sm,
160
160
-
t.atoms.bg_contrast_100,
161
161
-
{marginLeft: 'auto', left: 6, padding: 6},
162
162
-
]}>
163
163
-
<Pencil
164
164
-
style={{color: t.palette.contrast_500}}
165
165
-
height={18}
166
166
-
width={18}
152
152
+
a.px_md,
153
153
+
a.gap_xs,
154
154
+
{paddingVertical: isAndroid ? 14 : 9},
155
155
+
t.atoms.bg_contrast_25,
156
156
+
]}
157
157
+
onPress={onPressSelectService}>
158
158
+
<TextField.Icon icon={Globe} />
159
159
+
<Text style={[a.text_md]}>{toNiceDomain(serviceUrl)}</Text>
160
160
+
<View
161
161
+
style={[
162
162
+
a.rounded_sm,
163
163
+
t.atoms.bg_contrast_100,
164
164
+
{marginLeft: 'auto', left: 6, padding: 6},
165
165
+
]}>
166
166
+
<Pencil
167
167
+
style={{color: t.palette.contrast_500}}
168
168
+
height={18}
169
169
+
width={18}
170
170
+
/>
171
171
+
</View>
172
172
+
</TouchableOpacity>
173
173
+
</View>
174
174
+
<View>
175
175
+
<TextField.Label>
176
176
+
<Trans>Account</Trans>
177
177
+
</TextField.Label>
178
178
+
<TextField.Root>
179
179
+
<TextField.Icon icon={At} />
180
180
+
<TextField.Input
181
181
+
testID="loginUsernameInput"
182
182
+
label={_(msg`Username or email address`)}
183
183
+
autoCapitalize="none"
184
184
+
autoFocus
185
185
+
autoCorrect={false}
186
186
+
autoComplete="username"
187
187
+
returnKeyType="next"
188
188
+
textContentType="username"
189
189
+
onSubmitEditing={() => {
190
190
+
passwordInputRef.current?.focus()
191
191
+
}}
192
192
+
blurOnSubmit={false} // prevents flickering due to onSubmitEditing going to next field
193
193
+
value={identifier}
194
194
+
onChangeText={str =>
195
195
+
setIdentifier((str || '').toLowerCase().trim())
196
196
+
}
197
197
+
editable={!isProcessing}
198
198
+
accessibilityHint={_(
199
199
+
msg`Input the username or email address you used at signup`,
200
200
+
)}
167
201
/>
202
202
+
</TextField.Root>
203
203
+
</View>
204
204
+
<View>
205
205
+
<TextField.Root>
206
206
+
<TextField.Icon icon={Lock} />
207
207
+
<TextField.Input
208
208
+
testID="loginPasswordInput"
209
209
+
inputRef={passwordInputRef}
210
210
+
label={_(msg`Password`)}
211
211
+
autoCapitalize="none"
212
212
+
autoCorrect={false}
213
213
+
autoComplete="password"
214
214
+
returnKeyType="done"
215
215
+
enablesReturnKeyAutomatically={true}
216
216
+
secureTextEntry={true}
217
217
+
textContentType="password"
218
218
+
clearButtonMode="while-editing"
219
219
+
value={password}
220
220
+
onChangeText={setPassword}
221
221
+
onSubmitEditing={onPressNext}
222
222
+
blurOnSubmit={false} // HACK: https://github.com/facebook/react-native/issues/21911#issuecomment-558343069 Keyboard blur behavior is now handled in onSubmitEditing
223
223
+
editable={!isProcessing}
224
224
+
accessibilityHint={
225
225
+
identifier === ''
226
226
+
? _(msg`Input your password`)
227
227
+
: _(msg`Input the password tied to ${identifier}`)
228
228
+
}
229
229
+
/>
230
230
+
<TouchableOpacity
231
231
+
testID="forgotPasswordButton"
232
232
+
onPress={onPressForgotPassword}
233
233
+
accessibilityRole="button"
234
234
+
accessibilityLabel={_(msg`Forgot password`)}
235
235
+
accessibilityHint={_(msg`Opens password reset form`)}
236
236
+
style={[
237
237
+
a.rounded_sm,
238
238
+
t.atoms.bg_contrast_100,
239
239
+
{marginLeft: 'auto', left: 6, padding: 6},
240
240
+
a.z_10,
241
241
+
]}>
242
242
+
<ButtonText style={t.atoms.text_contrast_medium}>
243
243
+
<Trans>Forgot?</Trans>
244
244
+
</ButtonText>
245
245
+
</TouchableOpacity>
246
246
+
</TextField.Root>
247
247
+
</View>
248
248
+
{error ? (
249
249
+
<View style={[styles.error, {marginHorizontal: 0}]}>
250
250
+
<Warning style={s.white} size="sm" />
251
251
+
<View style={(a.flex_1, a.ml_sm)}>
252
252
+
<Text style={[s.white, s.bold]}>{error}</Text>
253
253
+
</View>
168
254
</View>
169
169
-
</TouchableOpacity>
170
170
-
</View>
171
171
-
<View>
172
172
-
<TextField.Label>
173
173
-
<Trans>Account</Trans>
174
174
-
</TextField.Label>
175
175
-
<TextField.Root>
176
176
-
<TextField.Icon icon={At} />
177
177
-
<TextField.Input
178
178
-
testID="loginUsernameInput"
179
179
-
label={_(msg`Username or email address`)}
180
180
-
autoCapitalize="none"
181
181
-
autoFocus
182
182
-
autoCorrect={false}
183
183
-
autoComplete="username"
184
184
-
returnKeyType="next"
185
185
-
textContentType="username"
186
186
-
onSubmitEditing={() => {
187
187
-
passwordInputRef.current?.focus()
188
188
-
}}
189
189
-
blurOnSubmit={false} // prevents flickering due to onSubmitEditing going to next field
190
190
-
value={identifier}
191
191
-
onChangeText={str =>
192
192
-
setIdentifier((str || '').toLowerCase().trim())
193
193
-
}
194
194
-
editable={!isProcessing}
195
195
-
accessibilityHint={_(
196
196
-
msg`Input the username or email address you used at signup`,
197
197
-
)}
198
198
-
/>
199
199
-
</TextField.Root>
200
200
-
</View>
201
201
-
<View>
202
202
-
<TextField.Root>
203
203
-
<TextField.Icon icon={Lock} />
204
204
-
<TextField.Input
205
205
-
testID="loginPasswordInput"
206
206
-
inputRef={passwordInputRef}
207
207
-
label={_(msg`Password`)}
208
208
-
autoCapitalize="none"
209
209
-
autoCorrect={false}
210
210
-
autoComplete="password"
211
211
-
returnKeyType="done"
212
212
-
enablesReturnKeyAutomatically={true}
213
213
-
secureTextEntry={true}
214
214
-
textContentType="password"
215
215
-
clearButtonMode="while-editing"
216
216
-
value={password}
217
217
-
onChangeText={setPassword}
218
218
-
onSubmitEditing={onPressNext}
219
219
-
blurOnSubmit={false} // HACK: https://github.com/facebook/react-native/issues/21911#issuecomment-558343069 Keyboard blur behavior is now handled in onSubmitEditing
220
220
-
editable={!isProcessing}
221
221
-
accessibilityHint={
222
222
-
identifier === ''
223
223
-
? _(msg`Input your password`)
224
224
-
: _(msg`Input the password tied to ${identifier}`)
225
225
-
}
226
226
-
/>
227
227
-
{/* <TouchableOpacity
228
228
-
testID="forgotPasswordButton"
229
229
-
style={styles.textInputInnerBtn}
230
230
-
onPress={onPressForgotPassword}
231
231
-
accessibilityRole="button"
232
232
-
accessibilityLabel={_(msg`Forgot password`)}
233
233
-
accessibilityHint={_(msg`Opens password reset form`)}>
234
234
-
<Text style={pal.link}>
235
235
-
<Trans>Forgot</Trans>
236
236
-
</Text>
237
237
-
</TouchableOpacity> */}
238
238
-
</TextField.Root>
239
239
-
</View>
240
240
-
{error ? (
241
241
-
<View style={[styles.error, {marginHorizontal: 0}]}>
242
242
-
<Warning style={s.white} size="sm" />
243
243
-
<View style={(a.flex_1, a.ml_sm)}>
244
244
-
<Text style={[s.white, s.bold]}>{error}</Text>
245
245
-
</View>
246
246
-
</View>
247
247
-
) : undefined}
248
248
-
<View style={[a.flex_row, a.align_center]}>
249
249
-
<Button
250
250
-
label={_(msg`Back`)}
251
251
-
variant="solid"
252
252
-
color="secondary"
253
253
-
size="small"
254
254
-
onPress={onPressBack}>
255
255
-
{_(msg`Back`)}
256
256
-
</Button>
257
257
-
<View style={s.flex1} />
258
258
-
{!serviceDescription && error ? (
255
255
+
) : undefined}
256
256
+
<View style={[a.flex_row, a.align_center]}>
259
257
<Button
260
260
-
testID="loginRetryButton"
261
261
-
label={_(msg`Retry`)}
262
262
-
accessibilityHint={_(msg`Retries login`)}
258
258
+
label={_(msg`Back`)}
263
259
variant="solid"
264
260
color="secondary"
265
261
size="small"
266
266
-
onPress={onPressRetryConnect}>
267
267
-
{_(msg`Retry`)}
262
262
+
onPress={onPressBack}>
263
263
+
{_(msg`Back`)}
268
264
</Button>
269
269
-
) : !serviceDescription ? (
270
270
-
<>
265
265
+
<View style={s.flex1} />
266
266
+
{!serviceDescription && error ? (
267
267
+
<Button
268
268
+
testID="loginRetryButton"
269
269
+
label={_(msg`Retry`)}
270
270
+
accessibilityHint={_(msg`Retries login`)}
271
271
+
variant="solid"
272
272
+
color="secondary"
273
273
+
size="small"
274
274
+
onPress={onPressRetryConnect}>
275
275
+
{_(msg`Retry`)}
276
276
+
</Button>
277
277
+
) : !serviceDescription ? (
278
278
+
<>
279
279
+
<ActivityIndicator />
280
280
+
<Text style={[t.atoms.text_contrast_high, a.pl_md]}>
281
281
+
<Trans>Connecting...</Trans>
282
282
+
</Text>
283
283
+
</>
284
284
+
) : isProcessing ? (
271
285
<ActivityIndicator />
272
272
-
<Text style={[t.atoms.text_contrast_high, a.pl_md]}>
273
273
-
<Trans>Connecting...</Trans>
274
274
-
</Text>
275
275
-
</>
276
276
-
) : isProcessing ? (
277
277
-
<ActivityIndicator />
278
278
-
) : isReady ? (
279
279
-
<Button
280
280
-
label={_(msg`Next`)}
281
281
-
accessibilityHint={_(msg`Navigates to the next screen`)}
282
282
-
variant="solid"
283
283
-
color="primary"
284
284
-
size="small"
285
285
-
onPress={onPressNext}>
286
286
-
{_(msg`Next`)}
287
287
-
</Button>
288
288
-
) : undefined}
286
286
+
) : isReady ? (
287
287
+
<Button
288
288
+
label={_(msg`Next`)}
289
289
+
accessibilityHint={_(msg`Navigates to the next screen`)}
290
290
+
variant="solid"
291
291
+
color="primary"
292
292
+
size="small"
293
293
+
onPress={onPressNext}>
294
294
+
{_(msg`Next`)}
295
295
+
</Button>
296
296
+
) : undefined}
297
297
+
</View>
289
298
</View>
290
290
-
</View>
299
299
+
</ScrollView>
291
300
)
292
301
}