Skip to content
Tutorials Center
My learning

Topics

Lesson 11 of 38 ยท Components and Styling

Core Components: View, Text, Image, ScrollView

Learn the building blocks of every Expo screen: View, Text, Image and expo-image, ScrollView, SafeAreaView and safe area insets, ActivityIndicator, and how they map to native views.

On the web you write div, p, img. In React Native there are no HTML tags: you use a small set of core components that map to real native views. Learn about ten of them and you can build most screens. This lesson covers the ones you will use constantly and the rules that trip up newcomers.

Component code is read-only (it needs a device or simulator). The live stand-ins model the key rules, such as text having to live inside Text.

View: the container

View is the equivalent of div: a rectangle that holds other components and can have layout, background, borders and shadows. It does not scroll and cannot hold raw text.

TSX
import { View } from 'react-native';

<View style={{ flexDirection: 'row', gap: 12, padding: 16, backgroundColor: '#f2f4f8' }}>
  {/* children */}
</View>

Text: all words live here

Every string must be inside <Text>. Text can nest, and nested text inherits the parent's style:

TSX
import { Text } from 'react-native';

<Text style={{ fontSize: 16, color: '#222' }}>
  Hike <Text style={{ fontWeight: '700' }}>responsibly</Text>, and{'\n'}
  leave no trace.
</Text>

Useful props: numberOfLines (truncate), ellipsizeMode, selectable, onPress, adjustsFontSizeToFit (iOS/Android), allowFontScaling (respect the user's system font size; keep it on for accessibility). Unlike CSS, text styles do not inherit through View: setting color on a View does nothing to the Text inside.

JS Text must live inside Text

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Image and expo-image

React Native has Image, but Expo apps usually use expo-image, which adds caching, placeholders (including BlurHash), smooth transitions and better format support (WebP, AVIF, SVG, animated images):

TSX
import { Image } from 'expo-image';

const blurhash = 'LEHV6nWB2yk8pyo0adR*.7kCMdnj';

<Image
  source={{ uri: 'https://example.com/photos/lake.jpg' }}
  placeholder={{ blurhash }}
  contentFit="cover"
  transition={300}
  style={{ width: '100%', aspectRatio: 16 / 9, borderRadius: 12 }}
  accessibilityLabel="A lake at sunrise"
/>

Rules for images:

  • Remote images need a size (width/height or aspectRatio); native views cannot guess it, so without it nothing shows.
  • Local files use require: source={require('../assets/logo.png')} and their size is known automatically. Provide @2x / @3x variants ([email protected]) for sharper screens.
  • contentFit replaces the old resizeMode: cover, contain, fill, none, scale-down.
  • Always set accessibilityLabel (or alt) for meaningful images.
JS Fit an image into a box

Press Run (or Ctrl + Enter) to see the console output here.

No output.

cover fills the box and crops; contain shows the whole image and leaves empty bands (negative offsets mean cropping).

ScrollView

ScrollView renders all its children and scrolls them. It is right for short, bounded content such as a settings page, and wrong for long lists (use FlatList, Lists and FlatList).

TSX
<ScrollView
  contentContainerStyle={{ padding: 16, gap: 12 }}
  keyboardShouldPersistTaps="handled"
  showsVerticalScrollIndicator={false}
>
  {/* sections */}
</ScrollView>

Style the scrolling content with contentContainerStyle; style styles the scroll area itself. Add horizontal for horizontal scrolling and refreshControl for pull-to-refresh.

Safe areas

Phones have notches, rounded corners, status bars and home indicators. Content must avoid them. Use the react-native-safe-area-context package (installed in Expo templates):

TSX
import { useSafeAreaInsets, SafeAreaView } from 'react-native-safe-area-context';

function Screen() {
  const insets = useSafeAreaInsets();
  return (
    <View style={{ flex: 1, paddingTop: insets.top, paddingBottom: insets.bottom }}>
      {/* content */}
    </View>
  );
}
// or: <SafeAreaView style={{ flex: 1 }} edges={['top', 'bottom']}>

Do not use React Native's own SafeAreaView (deprecated, iOS-only). Headers and tab bars from Expo Router already handle insets for you; add padding yourself only for custom screens, full-screen content and bottom-pinned buttons.

JS Compute padding from insets

Press Run (or Ctrl + Enter) to see the console output here.

No output.

Other building blocks you will meet

Component Use
ActivityIndicator spinner while loading
StatusBar (from expo-status-bar) light/dark status bar text
Modal native modal overlay (or use a route with presentation: 'modal')
Switch on/off toggle
FlatList, SectionList long, virtualized lists
KeyboardAvoidingView keep inputs above the keyboard (Touch and Text Input)
Pressable, TextInput interaction (Touch and Text Input)
Linking, Alert, Share system interactions

Common mistakes

  • Raw text in a View ("Text strings must be rendered within a component").
  • Remote Image without dimensions, so nothing appears.
  • Using ScrollView with hundreds of children; memory and startup time suffer.
  • Expecting CSS inheritance (colors and fonts set on View).
  • Using && with numbers: {count && <Text/>} renders 0 as raw text outside Text and crashes. Use {count > 0 && ...}.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Where must string content be placed in React Native?

    Native text rendering happens in Text; raw strings elsewhere cause an error.
  2. 2. Why does a remote image sometimes not appear?

    Native views need a size for remote images; local assets report their own size.
  3. 3. When is ScrollView the right choice?

    ScrollView renders all children at once; long lists should use FlatList.
  4. 4. Which package provides the recommended safe-area hooks?

    useSafeAreaInsets and SafeAreaView come from react-native-safe-area-context.

Summary

  • View contains, Text holds all words, Image (prefer expo-image) shows pictures and needs a size when remote.
  • ScrollView is for bounded content; use virtualized lists for long ones.
  • Respect safe areas with react-native-safe-area-context.
  • Styles do not inherit through View, and 0 && ... can crash a screen.

Next: Styling and Flexbox