React Native

111 flashcards by MentisLibrary

Building real native apps in JavaScript: the core components, navigation, styling and layout, platform APIs, native modules, Expo, performance and animation, and what shipping to the two app stores involves.

How does React Native differ from a web view wrapper?
It renders real native views (UIView, Android View) driven by JavaScript, so the UI is native and only the logic runs in JS; frameworks like Cordova render HTML inside a web view instead.
Name the core building-block components
View (container), Text, Image, TextInput, ScrollView, FlatList, Pressable, Modal, Switch, ActivityIndicator, StatusBar and SafeAreaView.
Why must every string be inside <Text>?
Native platforms have no concept of loose text nodes; only a Text component can lay out and draw characters, so a raw string inside a View throws.
How does text styling inherit in React Native?
Only through nested Text: a child Text inherits the font, size and color of its parent Text. There is no CSS cascade, so a View never passes font styles down.
What is StyleSheet.create for?
It declares styles once as plain objects with numeric, unitless values; every render references the same objects instead of allocating new ones, and the create call validates property names in development.
How do Flexbox defaults differ from the web?
flexDirection defaults to column (the web uses row), alignItems to stretch, flexShrink to 0, and position to relative; display is only flex or none.
How are conditional styles combined?
Pass an array to style; later entries override earlier ones and falsy entries are ignored.
How do you position an element absolutely?
Set position: 'absolute' with top, left, right or bottom; the element is positioned relative to its parent View and removed from the flex flow.
Which units and CSS features are missing?
No em, rem, vh, vw, calc(), media queries, pseudo-classes or selectors; you get numbers, percentages for size and spacing, and the gap property.
How are shadows written per platform?
iOS uses shadowColor, shadowOffset, shadowOpacity and shadowRadius; Android uses elevation. The boxShadow style property (React Native 0.76 with the New Architecture) works on both.
How do Platform.OS and Platform.select work?
Platform.OS is 'ios', 'android', 'web' and so on; Platform.select picks a value from an object keyed by platform, with default as the fallback.
How do platform-specific files work?
Name files Button.ios.tsx and Button.android.tsx; importing ./Button resolves the matching one at bundle time. .native.tsx targets both mobile platforms when a .tsx web version also exists.
How is an image loaded?
Image takes a source: require('./logo.png') for a bundled file (size known from the file) or { uri: 'https://...' } for a remote one, which needs explicit width and height.
What does resizeMode control?
How an image fits its box: cover (fill and crop), contain (fit inside), stretch (distort), center and repeat.
When does ScrollView become the wrong choice?
When the content is long or of unknown length: ScrollView renders every child at once, so a few hundred rows means slow mounts and high memory. Use FlatList or SectionList, which virtualize.
How does FlatList render a long list?
It takes data and renderItem, mounts only the rows near the viewport, recycles them as you scroll, and needs a keyExtractor for stable identity.
Which FlatList props tune scrolling performance?
getItemLayout (skips measuring fixed-height rows), initialNumToRender, windowSize, maxToRenderPerBatch, removeClippedSubviews and keyExtractor.
What does FlashList improve over FlatList?
Shopify's list recycles row views instead of unmounting and remounting them, keeping scrolling smooth on large data sets with far fewer blank cells.
Pressable vs TouchableOpacity
Pressable is the modern, unstyled touch handler with onPress, onLongPress, hitSlop and a style function that receives pressed; TouchableOpacity is the older wrapper that dims its child.
How does TextInput handle text?
As a controlled component: value reflects state and onChangeText gives the new string; props such as keyboardType, secureTextEntry, autoCapitalize and returnKeyType configure the keyboard.
What does KeyboardAvoidingView do?
It shifts or shrinks its content when the keyboard appears so inputs stay visible; behavior is usually 'padding' on iOS and undefined or 'height' on Android.
How do you make taps on a scrollable form dismiss or pass through the keyboard?
Set keyboardShouldPersistTaps="handled" on the ScrollView so a tap on a button fires instead of only closing the keyboard, and keyboardDismissMode="on-drag" to close it while scrolling.
How do you respect the notch and home indicator?
Use SafeAreaProvider and SafeAreaView (or useSafeAreaInsets) from react-native-safe-area-context, which works on both platforms; the core SafeAreaView is iOS-only.
How does the Modal component work?
It presents its children in a new native window above everything, controlled by visible, with animationType (slide, fade, none) and onRequestClose for the Android back button.
How is the status bar controlled?
With the StatusBar component or its static methods: barStyle (light-content, dark-content), backgroundColor (Android only) and hidden.
How do you set up React Navigation?
Install @react-navigation/native plus a navigator package, wrap the app in NavigationContainer, and declare screens on a navigator such as createNativeStackNavigator.
How do you navigate and pass params?
Call navigation.navigate('Details', { id }) from a screen's navigation prop or useNavigation(), and read them on the target from route.params.
Native stack vs JavaScript stack navigator
@react-navigation/native-stack uses the platform's own navigation container (UINavigationController, Android fragments) for real native transitions; @react-navigation/stack reimplements them in JS and is fully customizable.
How are tabs and stacks combined?
Nest navigators: a bottom tab navigator whose tab screens are each a stack, so pushing inside one tab keeps the tab bar and the other tabs' history.
How do you set screen options such as the title?
Through options on Stack.Screen (static or a function of route), or dynamically from inside the screen with navigation.setOptions.