ScreenContainer
ScreenContainer provides a consistent wrapper for screens with pre-calculated safe area padding. It uses initialWindowMetrics for immediate rendering without layout shifts.
Preview
Section titled “Preview”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> );}Edge Options
Section titled “Edge Options”Control which edges receive safe area padding:
Top only (default)
All edges
Bottom only
| Edges | Usage |
|---|---|
['top'] | Default, most screens |
['top', 'bottom'] | Screens with bottom content |
['left', 'right'] | Landscape modes |
['top', 'bottom', 'left', 'right'] | Full safe area |
How It Works
Section titled “How It Works”ScreenContainer uses a two-phase approach for safe area handling:
- Initial Render: Uses
initialWindowMetricsfor immediate padding - Live Update: Switches to
useSafeAreaInsets()once measured
This prevents the “jump” that occurs when safe area measurements arrive asynchronously.
// Use initial metrics for immediate renderingconst getInitialTopInset = () => { return initialWindowMetrics?.insets.top ?? 0;};
// Use live insets if available, otherwise fall back to initial metricsconst topInset = insets.top > 0 ? insets.top : getInitialTopInset();API Reference
Section titled “API Reference”| Prop | Type | Default | Description |
|---|---|---|---|
children | ReactNode | - | Screen content |
style | ViewStyle | - | Additional container styles |
edges | ('top' | 'bottom' | 'left' | 'right')[] | ['top'] | Edges to apply safe area padding |
Tokens Used
Section titled “Tokens Used”// Backgroundtheme.colors.background // Screen background colorUsage Guidelines
Section titled “Usage Guidelines”- 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)
Complete Example
Section titled “Complete Example”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> );}