Safe Areas
Modern phones draw your app edge to edge: the status bar, the display cutout (notch or punch hole), the Android navigation bar or gesture handle and the iOS home indicator all sit on top of your window. A button under the gesture handle cannot be tapped reliably, and text under the notch cannot be read.
PAM Native treats this as a hard rule: no content may sit under a system bar, a cutout or the home indicator. Backgrounds, images and video may reach the screen edges; text, inputs, buttons, list rows and sheet actions may not.
The good news is that you rarely have to do anything. The layout engine applies safe areas by default, and the tools on this page cover the cases where you take control yourself.
Safe Area by Default
Section titled “Safe Area by Default”Every presentation surface keeps its content out of the insets automatically: the screen root, each navigation route, each Modal and each BottomSheet. After layout, the engine:
- finds the surface’s content container (the first node in its single-child wrapper chain, for example
Screen > View > Column); - measures how close the content gets to each window edge;
- where content would end inside an inset, pads the container by the missing amount. Padding you already authored counts: the effective padding is
max(inset, authored), so a screen that already clears the bars does not move; - keeps that padding between layouts and recalculates it on rotation, navigation-mode changes, multi-window and cutout changes.
So this screen is safe on every device without any extra code:
<?php
declare(strict_types=1);
namespace App\Screens;
use Pam\Native\Component;use Pam\Native\Element;use Pam\Native\Style;use Pam\Native\UI\Button;use Pam\Native\UI\Column;use Pam\Native\UI\Screen;use Pam\Native\UI\Text;use Pam\Native\UI\View;
final class WelcomeScreen extends Component{ public function render(): Element { return Screen::make( Column::make( Text::make('Welcome, Alice')->style(new Style(fontSize: 28, fontWeight: 700)), View::make()->style(new Style(flexGrow: 1)), Button::make('Continue')->onPress($this->continue(...)), )->style(new Style(flexGrow: 1, padding: 24, gap: 16)), )->style(new Style(flexGrow: 1, backgroundColor: 0xFF0F172A)); }
public function continue(): void { // ... }}The screen background reaches the edges; the title clears the status bar and the Continue button ends above the gesture handle or the three-button bar.
Absolutely positioned content anchored to one edge (a floating action button, a toast, a close button) moves out of the inset by the covered amount: bottom: 16 becomes max(16, inset). Stretched overlays (both top and bottom set), purely decorative layers and nodes inside scrolling content keep their frames.
SafeAreaView
Section titled “SafeAreaView”Use SafeAreaView when you want explicit control of a surface. When a SafeAreaView sits in the wrapper chain, the engine treats that surface as managed by you and adds nothing on top of it.
SafeAreaView pads exactly the window edges that its own frame overlaps, at any nesting level, so a nested view that does not touch an edge gets no padding and nothing is applied twice.
use Pam\Native\SafeAreaMode;use Pam\Native\UI\SafeAreaView;
$content = SafeAreaView::make($column) ->edges(top: true, right: true, bottom: false, left: true) ->mode(SafeAreaMode::Padding);<SafeAreaView safeAreaEdgeBottom="false" safeAreaMode="padding"> <Column class="content">…</Column></SafeAreaView>| Option | Meaning |
|---|---|
edges(top:, right:, bottom:, left:) / safeAreaEdgeTop, safeAreaEdgeRight, safeAreaEdgeBottom, safeAreaEdgeLeft |
Which edges this view clears. All default to true. |
mode(SafeAreaMode::Padding) |
Apply the inset as padding (default). |
mode(SafeAreaMode::Margin) |
Apply the inset as margin. |
A Tab Bar That Owns the Bottom Edge
Section titled “A Tab Bar That Owns the Bottom Edge”Disable an edge only when a fixed sibling already owns it. A custom bottom bar clears the gesture handle; the content above it does not:
<template> <Column class="shell"> <SafeAreaView safeAreaEdgeBottom="false" class="content"> <Feed /> </SafeAreaView> <SafeAreaView safeAreaEdgeTop="false" safeAreaEdgeLeft="false" safeAreaEdgeRight="false"> <AppTabBar /> </SafeAreaView> </Column></template>
<style scoped> .shell { flex-grow: 1; } .content { flex-grow: 1; }</style>Full-Bleed Opt-Out
Section titled “Full-Bleed Opt-Out”Camera viewfinders, story viewers and video players want pixels under every bar. Turn all four edges off on the media layer, and keep the controls in a nested safe view:
<SafeAreaView safeAreaEdgeTop="false" safeAreaEdgeRight="false" safeAreaEdgeBottom="false" safeAreaEdgeLeft="false"> <Video :source="$story->url" class="fill" /> <SafeAreaView class="controls"> <Button label="Close" @press="close" /> </SafeAreaView></SafeAreaView>Reading the Insets
Section titled “Reading the Insets”Sometimes you need the numbers, for example to size a custom header. Read them from the window metrics; they are available from the very first render:
use Pam\Native\App;use Pam\Native\WindowMetrics;
$metrics = App::windowMetrics();$headerHeight = 56 + $metrics->safeAreaTop;
App::onDimensions(function (WindowMetrics $metrics): void { // Called when size, orientation or insets change; the tree re-renders afterwards.});In CSS, use env() with a fallback:
.header { padding-top: calc(env(safe-area-inset-top, 0px) + 12px);}
.fab { position: absolute; right: 16px; bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);}WindowMetrics exposes safeAreaTop, safeAreaRight, safeAreaBottom and safeAreaLeft in points.
Lists and Scroll Views
Section titled “Lists and Scroll Views”The last row of a list must be readable when the list is scrolled to its end. The engine already counts a scroll’s end as content. When you add your own footer padding, put it on the scroll content instead of wrapping the list, so no extra wrapper or row is created:
use Pam\Native\Style;use Pam\Native\UI\VirtualizedList;
$list = VirtualizedList::of($orders, fn (array $order) => OrderRow::make($order)) ->estimatedRowHeight(72) ->contentContainerStyle(new Style(paddingTop: 12, paddingBottom: 24));On Android the padding is applied with clipToPadding=false, on iOS as contentInset, so rows scroll under the bars and still finish above them.
Modals and Bottom Sheets
Section titled “Modals and Bottom Sheets”A Modal or BottomSheet is its own presentation surface. A SafeAreaView inside it receives the insets of that window, never of the activity behind it:
| Surface | Insets it receives |
|---|---|
| Android 15+ (target SDK 35+), any modal | Real insets on every edge (enforced edge to edge). |
Android 14 and older, statusBarTranslucent or navigationBarTranslucent modal |
Real insets on every edge. |
| Android 14 and older, non-translucent modal | None: the dialog window already fits inside the system bars. |
iOS Modal |
Real insets on every edge. |
BottomSheet (any platform) |
Bottom and side insets; the top inset is always zero because snap points resolve below the status bar. |
The status bar and navigation bar are therefore cleared exactly once, whichever window you use. A bottom sheet’s background reaches the bottom of the screen while its last action ends above the navigation bar:
use Pam\Native\UI\BottomSheet;
// No snap points: the sheet fits its content, plus the bottom inset it still needs.$sheet = BottomSheet::make($shareOptions, []) ->handleVisible() ->backdropDismiss() ->onDismiss(fn () => $this->sharing = false);The Keyboard
Section titled “The Keyboard”The keyboard is another inset. Wrap forms and composers in KeyboardAvoidingView; never subtract a guessed keyboard height:
<KeyboardAvoidingView behavior="padding" keyboardVerticalOffset="8" flexGrow="1"> <Column flexGrow="1"> <ScrollView flexGrow="1"> <Input p-model="$email" placeholder="Email" /> <Input p-model="$password" placeholder="Password" secureTextEntry="true" /> </ScrollView> <Button label="Sign in" @press="signIn" /> </Column></KeyboardAvoidingView>KeyboardAvoidingView takes exactly one child; wrap several in a Column.
| Behavior | Use it for |
|---|---|
resize (default) |
The viewport shrinks by the measured overlap and flexible children absorb it. |
padding |
A contained vertical ScrollView gets the overlap as inset and reveals the focused input with 16 dp of clearance. |
pan |
A chat composer that ends a vertical column is laid out directly above the keyboard while the timeline above shrinks. |
At rest, the panel sits above the navigation bar or home indicator; with the keyboard open it sits keyboardVerticalOffset above the keyboard. See Text, Input and Controls for Keyboard::metrics() and keyboard events.
Android Fallback
Section titled “Android Fallback”Some Android gesture-navigation configurations report a zero bottom inset even though system UI overlaps the screen. You can configure a fallback, in dp, used only when Android reports no bottom inset:
{ "android": { "safeAreaBottomFallback": 48 }}The value accepts 0–96 and defaults to 0 (disabled).
Linting and Inspecting
Section titled “Linting and Inspecting”The Safe-Area Lint
Section titled “The Safe-Area Lint”safe-area-lint lays out captured render frames with the real engine and exits with status 1 when text, inputs, buttons, pressables or a list’s end land inside an inset. By default it checks two configurations: a three-button navigation bar (48) and gesture navigation (24), both under a 24 pt status bar.
Capture a frame from PHP, for example in a test:
<?php
declare(strict_types=1);
use App\Screens\WelcomeScreen;use Pam\Native\Tooling\SafeAreaLint;use PHPUnit\Framework\TestCase;
final class SafeAreaTest extends TestCase{ // check() runs the pam-native CLI from the installed package (or PAM_NATIVE_CLI). public function testWelcomeScreenClearsSystemBars(): void { self::assertSame([], SafeAreaLint::check(new WelcomeScreen())); }
public function testExportFrameForTheCli(): void { file_put_contents(__DIR__.'/frames/welcome.frame', SafeAreaLint::frame(new WelcomeScreen())); self::assertFileExists(__DIR__.'/frames/welcome.frame'); }}Then check frames in CI with the CLI:
pam native safe-area-lint tests/frames/welcome.framepam native safe-area-lint tests/frames/*.frame --viewport 390x844 --insets 0,47,0,34 --json| Option | Meaning |
|---|---|
--viewport WxH |
Window size in points. |
--insets l,t,r,b |
An inset configuration to check; repeat it to check several. |
--policy edge-to-edge|system|in-window |
The modal surface policy to simulate. |
--json |
Machine-readable violations. |
--explicit-only |
Turn the automatic safe area off and verify that the app clears the insets by itself. |
On-Device Inspector
Section titled “On-Device Inspector”Debuggable Android builds inspect the real views of the activity and of every Modal and BottomSheet window after each layout and log intrusions:
adb logcat -s PamSafeAreaadb shell setprop debug.pam.safearea.overlay 1 # paint the insets and outline offending viewsadb shell setprop debug.pam.safearea 0 # turn the inspector offiOS debug builds log PamSafeArea: lines; set PAM_SAFE_AREA_OVERLAY=1 in the scheme environment to show the overlay.
Checklist
Section titled “Checklist”Before you ship a screen, sheet or overlay:
- Text, inputs and buttons clear the status bar and cutout in portrait and landscape.
- The last row of every list, scrolled to the end, sits above the gesture handle or navigation bar.
- Every bottom sheet, scrolled to its bottom, shows its last action fully above the navigation bar.
- Floating buttons, toasts and composers rest above the bottom inset and above the keyboard when it is open.
- Full-bleed media keeps its controls in a nested
SafeAreaView. - Both three-button and gesture navigation were checked (the lint does this by default).
- No hard-coded bar heights or device tables exist in the code base.