Inline Permissions Screen
Screen is created using these React Native Core Components: <SafeAreaView />, <View />, <Text />, <Switch />, <TouchableOpacity />
import React, { useState } from 'react';
import {
StyleSheet,
SafeAreaView,
View,
Text,
Switch,
TouchableOpacity,
} from 'react-native';
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view';
import FeatherIcon from 'react-native-vector-icons/Feather''@expo/vector-icons/Feather';
const INPUT_OFFSET = 160;
export default function Example() {
const [form, setForm] = useState({
location: false,
photos: false,
notifications: false,
});
return (
<SafeAreaView style={{ flex: 1, backgroundColor: '#fff' }}>
<View style={styles.header}>
<View style={styles.headerAction}>
<TouchableOpacity
onPress={() => {
// handle onPress
}}>
<FeatherIcon
color="#000"
name="arrow-left"
size={24} />
</TouchableOpacity>
</View>
<Text numberOfLines={1} style={styles.headerTitle}>
Allow access
</Text>
<View style={[styles.headerAction, { alignItems: 'flex-end' }]}>
<TouchableOpacity
onPress={() => {
// handle onPress
}}>
<FeatherIcon
color="#000"
name="more-vertical"
size={24} />
</TouchableOpacity>
</View>
</View>
<KeyboardAwareScrollView>
<View style={styles.formHeader}>
<Text style={styles.formHeaderText}>
To continue using the app, you have to allow access to your location
and photos.
</Text>
</View>
<View style={styles.formToggle}>
<View style={styles.formLabel}>
<Text style={styles.formLabelText}>Photos & videos</Text>
<Text style={styles.formLabelSubtext}>Required to use the app</Text>
</View>
<Switch
onValueChange={photos => setForm({ ...form, photos })}
trackColor={{ true: '#4C164C' }}
value={form.photos} />
</View>
<View style={styles.formToggle}>
<View style={styles.formLabel}>
<Text style={styles.formLabelText}>Location</Text>
<Text style={styles.formLabelSubtext}>Required to use the app</Text>
</View>
<Switch
onValueChange={location => setForm({ ...form, location })}
trackColor={{ true: '#4C164C' }}
value={form.location} />
</View>
<View style={styles.formToggle}>
<View style={styles.formLabel}>
<Text style={styles.formLabelText}>Camera</Text>
<Text style={styles.formLabelSubtext}>Optional</Text>
</View>
<Switch
onValueChange={camera => setForm({ ...form, camera })}
trackColor={{ true: '#4C164C' }}
value={form.camera} />
</View>
<View style={styles.formAction}>
<TouchableOpacity
onPress={() => {
// handle onPress
}}>
<View style={styles.btn}>
<Text style={styles.btnText}>Continue</Text>
</View>
</TouchableOpacity>
</View>
<Text style={styles.formFooter}>
You can adjust these permissions later.
</Text>
</KeyboardAwareScrollView>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
/** Header */
header: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
paddingVertical: 12,
paddingHorizontal: 16,
borderBottomWidth: 1,
borderColor: '#f2f2f2',
backgroundColor: '#fff',
},
headerAction: {
width: 40,
height: 40,
alignItems: 'flex-start',
justifyContent: 'center',
},
headerTitle: {
fontSize: 19,
fontWeight: '600',
color: '#000',
flexGrow: 1,
flexShrink: 1,
flexBasis: 0,
textAlign: 'center',
},
formHeader: {
backgroundColor: '#E8E8E8',
padding: 16,
marginBottom: 8,
borderTopWidth: 1,
borderBottomWidth: 1,
borderColor: '#CFCFCF',
},
formHeaderText: {
fontSize: 14,
fontWeight: '500',
color: '#54565f',
},
formToggle: {
height: 60,
paddingHorizontal: 16,
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between',
backgroundColor: '#fff',
borderBottomWidth: 1,
borderColor: '#f2f2f2',
},
formLabel: {
width: INPUT_OFFSET,
justifyContent: 'center',
},
formLabelText: {
fontSize: 13,
fontWeight: '600',
color: '#54565f',
textTransform: 'uppercase',
marginBottom: 4,
},
formLabelSubtext: {
fontSize: 13,
color: '#6b7280',
},
formAction: {
marginTop: 24,
paddingHorizontal: 16,
},
formFooter: {
paddingHorizontal: 16,
marginTop: 16,
fontSize: 14,
lineHeight: 20,
color: '#44465a',
},
/** Button */
btn: {
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'center',
borderRadius: 8,
paddingVertical: 10,
paddingHorizontal: 20,
borderWidth: 1,
backgroundColor: '#4C164C',
borderColor: '#4C164C',
},
btnText: {
fontSize: 16,
lineHeight: 26,
fontWeight: '600',
color: '#fff',
letterSpacing: 0.133,
},
});Request Permissions ✅
UI/UX implementation of the React Native Component with permission requests, error messages, and navigation to the Settings screen.
import React from 'react';
import { StyleSheet, Text, SafeAreaView, ScrollView, StatusBar } from 'react-native';
const App = () => {
return (
<SafeAreaView style={styles.container}>
<ScrollView style={styles.scrollView}>
<Text style={styles.text}>
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do
eiusmod tempor incididunt ut labore et dolore magna aliqua.
</Text>
<View>
<Text style={styles.text}>in voluptate velit esse cillum dolore eu fugiat nulla</Text>
</View>
</ScrollView>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: StatusBar.currentHeight,
},
scrollView: {
backgroundColor: 'pink',
marginHorizontal: 20,
},
text: {
fontSize: 42,
},
});
export default App;
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-keyboard-aware-scroll-view
Original instructions can be found on Github: https://github.com/APSL/react-native-keyboard-aware-scroll-view
-
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