Loading source
Pulling the file list, source metadata, and syntax-aware rendering for this listing.
Source from repo
Build performant React Native and Expo apps with best practices for lists, animations, and navigation
Files
Skill
Size
Entrypoint
Format
Open file
Syntax-highlighted preview of this file as included in the skill package.
rules/ui-safe-area-scroll.md
1---2title: Use contentInsetAdjustmentBehavior for Safe Areas3impact: MEDIUM4impactDescription: native safe area handling, no layout shifts5tags: safe-area, scrollview, layout6---78## Use contentInsetAdjustmentBehavior for Safe Areas910Use `contentInsetAdjustmentBehavior="automatic"` on the root ScrollView instead of wrapping content in SafeAreaView or manual padding. This lets iOS handle safe area insets natively with proper scroll behavior.1112**Incorrect (SafeAreaView wrapper):**1314```tsx15import { SafeAreaView, ScrollView, View, Text } from 'react-native'1617function MyScreen() {18return (19<SafeAreaView style={{ flex: 1 }}>20<ScrollView>21<View>22<Text>Content</Text>23</View>24</ScrollView>25</SafeAreaView>26)27}28```2930**Incorrect (manual safe area padding):**3132```tsx33import { ScrollView, View, Text } from 'react-native'34import { useSafeAreaInsets } from 'react-native-safe-area-context'3536function MyScreen() {37const insets = useSafeAreaInsets()3839return (40<ScrollView contentContainerStyle={{ paddingTop: insets.top }}>41<View>42<Text>Content</Text>43</View>44</ScrollView>45)46}47```4849**Correct (native content inset adjustment):**5051```tsx52import { ScrollView, View, Text } from 'react-native'5354function MyScreen() {55return (56<ScrollView contentInsetAdjustmentBehavior='automatic'>57<View>58<Text>Content</Text>59</View>60</ScrollView>61)62}63```6465The native approach handles dynamic safe areas (keyboard, toolbars) and allows content to scroll behind the status bar naturally.66