React Native Cheatsheet
React Native Core Components
Use this React Native reference while you build software engineering projects, review code for technical interview prep, or polish examples for a software engineer resume.
View
The fundamental building block — maps to UIView (iOS) / View (Android).
import { View } from 'react-native'; <View style={{ flex: 1, backgroundColor: '#fff' }}> <View style={{ width: 100, height: 100 }} /> </View>
View Props
| Prop | Type | Notes |
|---|---|---|
style | object | array | StyleSheet or inline |
onLayout | function | ({ nativeEvent: { layout } }) => void |
accessible | boolean | Accessibility group |
accessibilityLabel | string | Screen reader label |
testID | string | E2E testing selector |
pointerEvents | 'box-none' | 'none' | 'box-only' | 'auto' | Touch passthrough |
Text
import { Text } from 'react-native'; <Text numberOfLines={2} ellipsizeMode="tail" onPress={() => console.log('tapped')} selectable style={{ fontSize: 16, color: '#000' }} > Hello World </Text>
Text Props
| Prop | Type | Notes |
|---|---|---|
numberOfLines | number | Truncate after N lines |
ellipsizeMode | 'head' | 'middle' | 'tail' | 'clip' | Where to truncate |
selectable | boolean | Allow text selection |
onPress | function | Tap handler |
onLongPress | function | Long-press handler |
allowFontScaling | boolean | Respect OS font size (default true) |
adjustsFontSizeToFit | boolean | Shrink to fit container |
minimumFontScale | number | Min scale when adjustsFontSizeToFit |
Gotcha: Text styles do NOT inherit from View — you must explicitly style each
<Text>.
Image
import { Image } from 'react-native'; // Local asset <Image source={require('./assets/logo.png')} style={{ width: 100, height: 100 }} /> // Remote <Image source={{ uri: 'https://example.com/photo.jpg' }} style={{ width: 200, height: 200 }} resizeMode="cover" onLoad={() => console.log('loaded')} onError={({ nativeEvent }) => console.error(nativeEvent.error)} /> // With headers (remote) <Image source={{ uri: '...', headers: { Authorization: 'Bearer token' } }} />
Image resizeMode values
| Value | Behavior |
|---|---|
cover | Scale to fill, may crop |
contain | Scale to fit, letterbox |
stretch | Stretch to fill (distorts) |
repeat | Tile the image |
center | Center without scaling |
expo-image (better caching — works in any RN app)
The de facto replacement for the archived react-native-fast-image: disk +
memory caching, blurhash placeholders, priority loading.
npx expo install expo-image
import { Image } from 'expo-image'; <Image source="https://example.com/photo.jpg" style={{ width: 200, height: 200 }} contentFit="cover" // like resizeMode transition={200} // fade-in ms cachePolicy="memory-disk" // 'none' | 'disk' | 'memory' | 'memory-disk' placeholder={{ blurhash: 'L6PZfSi_.AyE_3t7t7R**0o#DgR4' }} priority="high" />
TextInput
import { TextInput } from 'react-native'; const [value, setValue] = React.useState(''); <TextInput value={value} onChangeText={setValue} placeholder="Enter text" placeholderTextColor="#999" style={{ borderWidth: 1, padding: 8, borderRadius: 4 }} autoCapitalize="none" autoCorrect={false} returnKeyType="done" onSubmitEditing={() => Keyboard.dismiss()} secureTextEntry // for passwords keyboardType="email-address" multiline numberOfLines={4} />
TextInput keyboardType values
default | number-pad | decimal-pad | numeric | email-address | phone-pad | url | ascii-capable | visible-password
Pressable (Recommended touch handler)
import { Pressable, Text } from 'react-native'; <Pressable onPress={() => console.log('pressed')} onLongPress={() => console.log('long press')} onPressIn={() => {}} onPressOut={() => {}} hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }} style={({ pressed }) => [ { backgroundColor: pressed ? '#ddd' : '#fff' }, styles.button, ]} > {({ pressed }) => <Text>{pressed ? 'Pressing' : 'Press Me'}</Text>} </Pressable>
TouchableOpacity / TouchableHighlight
import { TouchableOpacity, TouchableHighlight } from 'react-native'; // Fades on press <TouchableOpacity activeOpacity={0.7} onPress={handlePress}> <Text>Tap me</Text> </TouchableOpacity> // Darkens on press <TouchableHighlight underlayColor="#DDDDDD" onPress={handlePress}> <Text>Tap me</Text> </TouchableHighlight>
Prefer
PressableoverTouchableOpacity/TouchableHighlightin new code — it supportsstylecallbacks and is more flexible.
ScrollView
import { ScrollView } from 'react-native'; <ScrollView horizontal showsHorizontalScrollIndicator={false} showsVerticalScrollIndicator={false} bounces={false} // iOS: disable bounce onScroll={({ nativeEvent }) => console.log(nativeEvent.contentOffset.y)} scrollEventThrottle={16} // ms between onScroll events contentContainerStyle={{ padding: 16 }} keyboardShouldPersistTaps="handled" refreshControl={ <RefreshControl refreshing={refreshing} onRefresh={onRefresh} /> } > {/* children */} </ScrollView>
Gotcha:
ScrollViewrenders ALL children at once — useFlatListfor long lists.
SafeAreaView
import { SafeAreaView } from 'react-native'; // OR (preferred — handles more edge cases) import { SafeAreaView } from 'react-native-safe-area-context'; <SafeAreaView style={{ flex: 1 }}> <YourContent /> </SafeAreaView>
Modal
import { Modal, View, Text, Pressable } from 'react-native'; const [visible, setVisible] = React.useState(false); <Modal visible={visible} animationType="slide" // 'none' | 'slide' | 'fade' transparent presentationStyle="pageSheet" // iOS: 'fullScreen' | 'pageSheet' | 'formSheet' onRequestClose={() => setVisible(false)} // Android back button > <View style={{ flex: 1, justifyContent: 'center', backgroundColor: 'rgba(0,0,0,0.5)' }}> <View style={{ backgroundColor: '#fff', padding: 20, borderRadius: 12 }}> <Text>Modal Content</Text> <Pressable onPress={() => setVisible(false)}> <Text>Close</Text> </Pressable> </View> </View> </Modal>
ActivityIndicator
import { ActivityIndicator } from 'react-native'; <ActivityIndicator size="large" color="#0000ff" /> <ActivityIndicator size="small" animating={isLoading} />
Switch
import { Switch } from 'react-native'; const [enabled, setEnabled] = React.useState(false); <Switch value={enabled} onValueChange={setEnabled} trackColor={{ false: '#767577', true: '#81b0ff' }} thumbColor={enabled ? '#f5dd4b' : '#f4f3f4'} ios_backgroundColor="#3e3e3e" />
KeyboardAvoidingView
import { KeyboardAvoidingView, Platform } from 'react-native'; <KeyboardAvoidingView style={{ flex: 1 }} behavior={Platform.OS === 'ios' ? 'padding' : 'height'} keyboardVerticalOffset={Platform.OS === 'ios' ? 64 : 0} > <TextInput ... /> </KeyboardAvoidingView>
StatusBar
import { StatusBar } from 'react-native'; // OR for Expo import { StatusBar } from 'expo-status-bar'; // React Native built-in <StatusBar barStyle="dark-content" backgroundColor="#fff" translucent /> // Expo <StatusBar style="auto" />
barStyle | Description |
|---|---|
default | Platform default |
light-content | White text (for dark backgrounds) |
dark-content | Black text (for light backgrounds) |