Modern Confirmation Code Form
Screen is created using these React Native Core Components: <SafeAreaView />, <View />, <TouchableOpacity />, <Text />, <TextInput />
import React, { useState } from 'react';
import {
StyleSheet,
SafeAreaView,
View,
TouchableOpacity,
Text,
TextInput,
} from 'react-native';
import FeatherIcon from 'react-native-vector-icons/Feather''@expo/vector-icons/Feather';
export default function Example() {
const [code, setCode] = useState('');
return (
<SafeAreaView style={{ flex: 1, backgroundColor: '#F4EFF3' }}>
<View style={styles.header}>
<TouchableOpacity
onPress={() => {
// handle onPress
}}
style={styles.headerAction}>
<FeatherIcon
color="#F82E08"
name="arrow-left"
size={24} />
</TouchableOpacity>
<Text style={styles.title}>Enter Code</Text>
<Text style={styles.subtitle}>
We emailed a code to{' '}
<Text style={{ color: '#222' }}>john@example.com</Text>, please enter
the code to continue.
</Text>
</View>
<View style={styles.form}>
<View style={styles.formInput}>
<TextInput
autoCapitalize="none"
autoCorrect={false}
autoFocus={true}
caretHidden={true}
keyboardType="number-pad"
onChangeText={value => setCode(value.slice(0, 6))}
returnKeyType="done"
style={styles.formInputControl}
value={code} />
<View style={styles.formInputOverflow}>
{Array.from({ length: 6 }).map((_, index) => {
return (
<Text key={index} style={styles.formInputChar}>
{code[index] || (
<Text style={styles.formInputCharEmpty}>-</Text>
)}
</Text>
);
})}
</View>
</View>
<View style={styles.formAction}>
<TouchableOpacity
onPress={() => {
// handle onPress
}}>
<View style={styles.btn}>
<Text style={styles.btnText}>Submit</Text>
</View>
</TouchableOpacity>
</View>
</View>
<TouchableOpacity
onPress={() => {
// handle onPress
}}>
<Text style={styles.formFooter}>
Didn't get the email? <Text style={styles.formLink}>Resend code</Text>
</Text>
</TouchableOpacity>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
title: {
fontSize: 34,
fontWeight: 'bold',
color: '#181818',
marginBottom: 12,
},
subtitle: {
fontSize: 15,
lineHeight: 20,
fontWeight: '500',
color: '#889797',
},
/** Header */
header: {
paddingHorizontal: 24,
marginBottom: 28,
},
headerAction: {
width: 40,
height: 40,
borderRadius: 9999,
alignItems: 'center',
justifyContent: 'center',
backgroundColor: '#ffdada',
marginBottom: 16,
},
/** Form */
form: {
flexGrow: 1,
flexShrink: 1,
flexBasis: 0,
paddingHorizontal: 24,
},
formInput: {
position: 'relative',
backgroundColor: '#fff',
borderRadius: 12,
},
formInputControl: {
height: 60,
color: 'transparent',
paddingHorizontal: 16,
zIndex: 2,
},
formInputOverflow: {
zIndex: 1,
position: 'absolute',
top: 0,
right: 0,
left: 0,
bottom: 0,
width: '100%',
flexDirection: 'row',
justifyContent: 'space-around',
paddingHorizontal: 16,
},
formInputChar: {
flexGrow: 1,
flexShrink: 1,
flexBasis: 0,
lineHeight: 60,
fontSize: 34,
textAlign: 'center',
fontWeight: '600',
},
formInputCharEmpty: {
color: '#BBB9BC',
fontWeight: '400',
},
formAction: {
marginVertical: 24,
},
formFooter: {
marginTop: 'auto',
marginBottom: 24,
paddingHorizontal: 24,
fontSize: 15,
lineHeight: 20,
fontWeight: '400',
color: '#9fa5af',
textAlign: 'center',
},
formLink: {
textAlign: 'right',
fontWeight: '600',
color: '#F82E08',
textDecorationLine: 'underline',
textDecorationColor: '#F82E08',
textDecorationStyle: 'solid',
},
/** Button */
btn: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
borderRadius: 8,
paddingVertical: 16,
paddingHorizontal: 24,
borderWidth: 1,
backgroundColor: '#F82E08',
borderColor: '#F82E08',
},
btnText: {
fontSize: 17,
lineHeight: 22,
fontWeight: 'bold',
color: '#fff',
},
});Dependencies
Before getting started, make sure you have all the necessary dependencies for this component. Follow the steps below to install any missing dependencies.
-
Install the package.
npm install --save react-native-vector-icons
-
Link the native packages for iOS.
npx pod-install
In React Native 0.60+ the CLI autolink feature links the module while building the app.
-
Add Fonts to the
Info.plistfile.
Open your XCode project, right click on the Info.plist, and select Open As -> Source Code.
Next, copy the fonts below into your Info.plist.
<key>UIAppFonts</key>
<array>
<string>AntDesign.ttf</string>
<string>Entypo.ttf</string>
<string>EvilIcons.ttf</string>
<string>Feather.ttf</string>
<string>FontAwesome.ttf</string>
<string>FontAwesome5_Brands.ttf</string>
<string>FontAwesome5_Regular.ttf</string>
<string>FontAwesome5_Solid.ttf</string>
<string>FontAwesome6_Brands.ttf</string>
<string>FontAwesome6_Regular.ttf</string>
<string>FontAwesome6_Solid.ttf</string>
<string>Foundation.ttf</string>
<string>Ionicons.ttf</string>
<string>MaterialIcons.ttf</string>
<string>MaterialCommunityIcons.ttf</string>
<string>SimpleLineIcons.ttf</string>
<string>Octicons.ttf</string>
<string>Zocial.ttf</string>
<string>Fontisto.ttf</string>
</array>
Note: You can only select the fonts you would like to use in your React Native Application.
After you added these fonts the Info.plist file should look like this:
![]()
-
Add
fonts.gradlefor Android.
Open android/app/build.gradle (NOT android/build.gradle) and add the following code to the bottom:
apply from: file("../../node_modules/react-native-vector-icons/fonts.gradle")
If you want to customize fonts, use:
project.ext.vectoricons = [
iconFontNames: [ 'MaterialIcons.ttf', 'EvilIcons.ttf' ]
]
apply from: file("../../node_modules/react-native-vector-icons/fonts.gradle")
Original instructions can be found on Github: https://github.com/oblador/react-native-vector-icons