SwipeUI
DocsHooks & utilities

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

components/gallery.tsx
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 widthSizeGutterMost columns
Under 600compact161
600 to 899medium242
900 and overexpanded243

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 onSupported
Expo SDK 57Yes
Expo SDK 58Yes
React Native CLI (with Expo modules)Yes
Expo GoYes
iOSYes
AndroidYes

This table describes API support and static bundle checks. Native runtime, device accessibility and bare Uniwind compatibility remain pending.

On this page