diff --git a/docs/improvingux.md b/docs/improvingux.md index 892fe3ae5bf..a461d08a11e 100644 --- a/docs/improvingux.md +++ b/docs/improvingux.md @@ -15,33 +15,361 @@ Entering text on touch phone is a challenge - small screen, software keyboard. B Check out [`TextInput` docs](textinput.md) for more configuration options. - +```SnackPlayer name=TextInput%20form%20example +import React, { useState, useRef } from 'react'; +import { Text, StatusBar, TextInput, View, StyleSheet } from 'react-native'; +import { Constants } from 'expo'; -[Try it on your phone](https://snack.expo.io/H1iGt2vSW) +const App = () => { + const emailInput = useRef(null); + const [name, setName] = useState(''); + const [email, setEmail] = useState(''); + + const submit = () => { + alert(`Welcome, ${name}! Confirmation email has been sent to ${email}`); + }; + + return ( + + + + + This demo shows how using available TextInput customizations can make + forms much easier to use. Try completing the form and notice that + different fields have specific optimizations and the return key + changes from focusing next input to submitting the form. + + + setName(name)} + placeholder="Full Name" + autoFocus={true} + autoCapitalize="words" + autoCorrect={true} + keyboardType="default" + returnKeyType="next" + onSubmitEditing={() => emailInput.current.focus()} + blurOnSubmit={false} + /> + setEmail(email)} + ref={emailInput} + placeholder="email@example.com" + autoCapitalize="none" + autoCorrect={false} + keyboardType="email-address" + returnKeyType="send" + onSubmitEditing={submit} + blurOnSubmit={true} + /> + + ); +}; + +const styles = StyleSheet.create({ + container: { + flex: 1, + }, + header: { + paddingTop: 64, + padding: 20, + backgroundColor: '#282c34', + }, + description: { + fontSize: 14, + color: 'white', + }, + input: { + margin: 20, + marginBottom: 0, + height: 34, + paddingHorizontal: 10, + borderRadius: 4, + borderColor: '#ccc', + borderWidth: 1, + fontSize: 16, + }, +}); + +export default App; +``` ## Manage layout when keyboard is visible Software keyboard takes almost half of the screen. If you have interactive elements that can get covered by the keyboard, make sure they are still accessible by using the [`KeyboardAvoidingView` component](keyboardavoidingview.md). - +```SnackPlayer name=KeyboardAvoidingView%20example +import React, { useState, useRef } from 'react'; +import { + Text, + Button, + StatusBar, + TextInput, + KeyboardAvoidingView, + View, + StyleSheet, +} from 'react-native'; + +const App = () => { + const emailInput = useRef(null); + const [email, setEmail] = useState(''); + + const submit = () => { + emailInput.current.blur(); + alert(`Confirmation email has been sent to ${email}`); + }; + + return ( + + + + + This demo shows how to avoid covering important UI elements with the + software keyboard. Focus the email input below and notice that the + Sign Up button and the text adjusted positions to make sure they are + not hidden under the keyboard. + + + + setEmail(email)} + ref={emailInput} + placeholder="email@example.com" + autoCapitalize="none" + autoCorrect={false} + keyboardType="email-address" + returnKeyType="send" + onSubmitEditing={submit} + blurOnSubmit={true} + /> + +