Responsive layout
Measure a container and pick a compact, medium or expanded composition for phones and tablets.
Container measurement and adaptive composition policy for phones and tablets.
Free (MIT)Version 1.0.0Released 29 Oct 2026iOS and Android
When to use it
- Measure available container width for adaptive compositions.
When not to use it
- Use intrinsic flex layout for simple controls.
Installation
Run this from your app's root. If SwipeUI isn't set up yet, run npx @swipeui/cli init first; it sets up Uniwind, the theme tokens and the cn helper.
npx @swipeui/cli add responsive-layout- Adds
components/swipeui/lib/responsive-layout.ts.
Usage
import { View } from 'react-native';
import { useResponsiveLayout } from '@/components/swipeui/lib/responsive-layout';
export function Gallery() {
const layout = useResponsiveLayout();
// layout.size is 'compact', 'medium' or 'expanded'; layout.columns is 1 to 3.
return <View onLayout={layout.onLayout} style={{ paddingHorizontal: layout.gutter }} />;
}useResponsiveLayout measures the view you attach onLayout to, not the screen, so the same composition works in a split view, a sheet or a sidebar. Until the first measurement arrives the width is zero, so the first render is compact.
resolveLayout(width, fontScale) is the pure policy behind the hook, for when you already know the width:
| Available width | Size | Gutter | Most columns |
|---|---|---|---|
| Under 600 | compact | 16 | 1 |
| 600 to 899 | medium | 24 | 2 |
| 900 and over | expanded | 24 | 3 |
Columns also need about 280 points each, scaled by the font scale, so large Dynamic Type sizes fall back to fewer columns. readingWidth caps long text at 672 points.
See the responsive layouts guide for how SwipeUI items use it.
Accessibility
- This helper adds no accessibility behavior; the rendered component owns its semantics.
Motion
- Static on its own; any movement comes from the parent that animates it.
- No custom movement is configured by this item.
Performance
- One measurement state update per changed container width.
Notes for AI
- Attach onLayout to the containing View; do not substitute device width for nested container width.
Compatibility
| Runs on | Supported |
|---|---|
| Expo SDK 57 | Yes |
| Expo SDK 58 | Yes |
| React Native CLI (with Expo modules) | Yes |
| Expo Go | Yes |
| iOS | Yes |
| Android | Yes |
This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.