Skip to content

ScreenContainer

ScreenContainer provides a consistent wrapper for screens with pre-calculated safe area padding. It uses initialWindowMetrics for immediate rendering without layout shifts.

Safe Area Top
Screen Content
Safe Area Bottom

import { ScreenContainer } from '@synchronicity/react-native';
function MyScreen() {
return (
<ScreenContainer edges={['top', 'bottom']}>
<View style={styles.content}>
{/* Screen content */}
</View>
</ScreenContainer>
);
}

Control which edges receive safe area padding:

Top only (default)
All edges
Bottom only
EdgesUsage
['top']Default, most screens
['top', 'bottom']Screens with bottom content
['left', 'right']Landscape modes
['top', 'bottom', 'left', 'right']Full safe area

ScreenContainer uses a two-phase approach for safe area handling:

  1. Initial Render: Uses initialWindowMetrics for immediate padding
  2. Live Update: Switches to useSafeAreaInsets() once measured

This prevents the “jump” that occurs when safe area measurements arrive asynchronously.

// Use initial metrics for immediate rendering
const getInitialTopInset = () => {
return initialWindowMetrics?.insets.top ?? 0;
};
// Use live insets if available, otherwise fall back to initial metrics
const topInset = insets.top > 0 ? insets.top : getInitialTopInset();

PropTypeDefaultDescription
childrenReactNode-Screen content
styleViewStyle-Additional container styles
edges('top' | 'bottom' | 'left' | 'right')[]['top']Edges to apply safe area padding
// Background
theme.colors.background // Screen background color

  • Use ScreenContainer as the root of every screen
  • Specify only necessary edges to avoid wasted space
  • Combine with edges={['top']} for most scrollable content
  • Nest ScreenContainer inside ScreenContainer
  • Apply manual padding for safe areas (let the component handle it)
  • Use for modal content (modals have their own safe area handling)

import { ScreenContainer } from '@synchronicity/react-native';
import { ScrollView, View } from 'react-native';
function ReadingDetailScreen({ reading }) {
return (
<ScreenContainer edges={['top']}>
<ScrollView contentContainerStyle={styles.scrollContent}>
<HexagramVisual
hexagramNumber={reading.hexagramNumber}
size="large"
/>
<Text style={styles.title}>{reading.name}</Text>
<Text style={styles.description}>{reading.judgment}</Text>
</ScrollView>
</ScreenContainer>
);
}