2. View #

Created Tue Nov 14, 2023 at 11:25 PM

View #

import { View } from 'react-native';

function MyComponent() {
  return <View></View>;
}

SafeAreaView (ios only) #

Ready to use component

ScrollView #

By default View takes full width, but just content height. i.e. “align stretch” and “justify start”.

Even if content is too large, the View does not get a scroll bar, i.e. the extra content is just inaccessible.

ScrollView is a core component that solves this problem.

Props:

Major quirk and workaround:

Events

Methods (via ref):

  1. ref.current.scrollTo({ x, y, animated: true })
  2. ref.current.scrollToEnd({animated}) - helpful since don’t have to calculate ScrollView size manually. For start scrollTo({ x: 0 }) would do.

FIXME: for scroll in both directions, a normal (vertical) ScrollView with each child being a horizontal a ScrollView works.

ScrollView is quite powerful, and has snapping capabilities too, see docs- the most essential being snapToOffsets