React Native Cheatsheet

React Native Core Components

Use this React Native reference while you build software engineering projects, review code, or refresh the syntax you reach for most.

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

PropTypeNotes
styleobject | arrayStyleSheet or inline
onLayoutfunction({ nativeEvent: { layout } }) => void
accessiblebooleanAccessibility group
accessibilityLabelstringScreen reader label
testIDstringE2E 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

PropTypeNotes
numberOfLinesnumberTruncate after N lines
ellipsizeMode'head' | 'middle' | 'tail' | 'clip'Where to truncate
selectablebooleanAllow text selection
onPressfunctionTap handler
onLongPressfunctionLong-press handler
allowFontScalingbooleanRespect OS font size (default true)
adjustsFontSizeToFitbooleanShrink to fit container
minimumFontScalenumberMin 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

ValueBehavior
coverScale to fill, may crop
containScale to fit, letterbox
stretchStretch to fill (distorts)
repeatTile the image
centerCenter 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

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 Pressable over TouchableOpacity/TouchableHighlight in new code — it supports style callbacks 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: ScrollView renders ALL children at once — use FlatList for 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>

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" />
barStyleDescription
defaultPlatform default
light-contentWhite text (for dark backgrounds)
dark-contentBlack text (for light backgrounds)