Mobile Layout Expert
This skill provides advanced, up-to-date guidance on how to build user interfaces that adapt gracefully to any screen size, orientation, or device type (phone, tablet, foldable).
1. Core Design Philosophies
- Responsive Layout: The UI automatically adjusts to different screen sizes and orientations fluidly using proportions. The same elements shift, resize, or wrap (e.g., a grid changing from 2 columns to 4 columns).
- Adaptive Layout: Completely different UI architectures or specific element variations are rendered depending on the device type context (e.g., a Bottom Navigation Bar on a compact phone screen vs. a persistent Navigation Rail/Sidebar on a tablet or desktop).
- Cross-platform UI: In frameworks like Flutter, React Native, or Capacitor, this implies writing core layout logic centrally but gracefully falling back to native paradigms when necessary (e.g., iOS Cupertino styling vs. Android Material Design) to preserve platform trust and feel.
2. Flutter (Modern Layouts)
Flutter uses a flexible, constraints-down, sizes-up model.
- Responsive Strategies:
LayoutBuilder: The holy grail for local responsive design. It provides a BoxConstraints object to decide what to build based on the parent's available space, NOT just the screen size.
MediaQuery / MediaQuery.sizeOf(context): Use for global screen metrics safely without full rebuilds.
Flexible / Expanded: For proportional distributions within Row and Column.
Wrap: For dynamic flow of chips or buttons that wrap to the next line when space runs out.
- Adaptive Strategies:
- Use
flutter_adaptive_scaffold for out-of-the-box adaptive patterns (Navigation Rail on wide screens, Bottom Nav on small screens).
- Check
Theme.of(context).platform or Platform.isIOS conditionally to return Cupertino widgets vs Material widgets.
- Modern Trends (Flutter 3.x+): Heavy use of
Sliver widgets for complex scrollable viewports that restructure dynamically.
3. iOS (SwiftUI & Auto Layout)
- SwiftUI (The Modern Standard):
GeometryReader: Use when you need exact sizes, but prefer ViewThatFits (iOS 16+) which automatically chooses the first layout that fits in the available space.
- Adaptive:
NavigationSplitView and NavigationStack automatically adapt between single-stack push navigation on phones and multi-column sidebars on iPads and Macs.
- Grids:
LazyVGrid and LazyHGrid using GridItem(.adaptive(minimum: ...)) allows wrapping fluidly.
- Auto Layout (UIKit):
- Uses mathematical constraints (e.g., "Button leading = View leading + 20").
- Size Classes: (Compact vs Regular width/height). The core of adaptive design in UIKit. You activate different
NSLayoutConstraint sets depending on the current UITraitCollection.
- Stack Views (
UIStackView): Configure the axis (Horizontal/Vertical) dynamically based on trait collections.
4. Android (Jetpack Compose & ConstraintLayout)
- Jetpack Compose (The Modern Standard):
BoxWithConstraints: The Compose equivalent of Flutter's LayoutBuilder. It provides maxWidth and maxHeight so your composable can redesign its internals based on the space given to it.
- Window Size Classes: The official Android guideline. Calculate
calculateWindowSizeClass():
Compact (Phones)
Medium (Foldables, small tablets)
Expanded (Tablets, desktop)
- Adaptive Architecture: Utilize
ListDetailPaneScaffold (from Material 3 adaptive libraries) for automatic two-pane layouts on foldables/tablets that collapse to one pane on phones.
- Flow Layouts:
FlowRow and FlowColumn for responsive wrapping of dynamic content.
- ConstraintLayout (XML & Compose):
- XML: Use
res/layout for phones and res/layout-sw600dp for tablets. Use Guidelines (percentage-based) and Chains to distribute space evenly.
- Compose: Use
ConstraintLayout when you have complex flat positioning that would require heavily nested Rows/Columns. Animations between states can be managed via MotionLayout (or MotionScene).
Rules & Checklists for Layouts
- Avoid Hardcoded Sizes: Rely on padding, constraints, weights, and flex values instead of explicit widths/heights.
- Design for the "In-Between": Foldable devices are becoming common. Your layout must gracefully transition during window resizing or folding.
- Respect Safe Areas: Always utilize
SafeArea (Flutter), safeAreaPadding (SwiftUI), or WindowInsets (Compose) to prevent drawing content under notches, punch-holes, or dynamic islands.
- Touch Targets: Adaptive layouts must ensure that as screens get smaller, touch targets DO NOT shrink below platform defaults (44pt iOS, 48dp Android).
1---2name: mobile-layout-expert3description: Expert in Responsive, Adaptive, and Cross-Platform Mobile Layouts. Modern techniques for Flutter, iOS Swift (Auto Layout/SwiftUI), and Android (ConstraintLayout/Compose). Triggers on layout, responsive, adaptive, constraintlayout, auto layout.4---56# Mobile Layout Expert78This skill provides advanced, up-to-date guidance on how to build user interfaces that adapt gracefully to any screen size, orientation, or device type (phone, tablet, foldable).910## 1. Core Design Philosophies1112* **Responsive Layout:** The UI automatically adjusts to different screen sizes and orientations fluidly using proportions. The same elements shift, resize, or wrap (e.g., a grid changing from 2 columns to 4 columns).13* **Adaptive Layout:** Completely different UI architectures or specific element variations are rendered depending on the device type context (e.g., a Bottom Navigation Bar on a compact phone screen vs. a persistent Navigation Rail/Sidebar on a tablet or desktop).14* **Cross-platform UI:** In frameworks like Flutter, React Native, or Capacitor, this implies writing core layout logic centrally but gracefully falling back to native paradigms when necessary (e.g., iOS Cupertino styling vs. Android Material Design) to preserve platform trust and feel.1516## 2. Flutter (Modern Layouts)1718Flutter uses a flexible, constraints-down, sizes-up model.1920* **Responsive Strategies:**21 * **`LayoutBuilder`**: The holy grail for local responsive design. It provides a `BoxConstraints` object to decide what to build based on the parent's *available space*, NOT just the screen size.22 * **`MediaQuery` / `MediaQuery.sizeOf(context)`**: Use for global screen metrics safely without full rebuilds.23 * **`Flexible` / `Expanded`**: For proportional distributions within `Row` and `Column`.24 * **`Wrap`**: For dynamic flow of chips or buttons that wrap to the next line when space runs out.25* **Adaptive Strategies:**26 * Use **`flutter_adaptive_scaffold`** for out-of-the-box adaptive patterns (Navigation Rail on wide screens, Bottom Nav on small screens).27 * Check `Theme.of(context).platform` or `Platform.isIOS` conditionally to return `Cupertino` widgets vs `Material` widgets.28* **Modern Trends (Flutter 3.x+):** Heavy use of `Sliver` widgets for complex scrollable viewports that restructure dynamically.2930## 3. iOS (SwiftUI & Auto Layout)3132* **SwiftUI (The Modern Standard):**33 * **`GeometryReader`**: Use when you need exact sizes, but prefer `ViewThatFits` (iOS 16+) which automatically chooses the first layout that fits in the available space.34 * **Adaptive:** `NavigationSplitView` and `NavigationStack` automatically adapt between single-stack push navigation on phones and multi-column sidebars on iPads and Macs.35 * **Grids:** `LazyVGrid` and `LazyHGrid` using `GridItem(.adaptive(minimum: ...))` allows wrapping fluidly.36* **Auto Layout (UIKit):**37 * Uses mathematical constraints (e.g., "Button leading = View leading + 20").38 * **Size Classes:** (Compact vs Regular width/height). The core of adaptive design in UIKit. You activate different `NSLayoutConstraint` sets depending on the current `UITraitCollection`.39 * **Stack Views (`UIStackView`):** Configure the axis (Horizontal/Vertical) dynamically based on trait collections.4041## 4. Android (Jetpack Compose & ConstraintLayout)4243* **Jetpack Compose (The Modern Standard):**44 * **`BoxWithConstraints`**: The Compose equivalent of Flutter's `LayoutBuilder`. It provides `maxWidth` and `maxHeight` so your composable can redesign its internals based on the space given to it.45 * **Window Size Classes:** The official Android guideline. Calculate `calculateWindowSizeClass()`:46 * `Compact` (Phones)47 * `Medium` (Foldables, small tablets)48 * `Expanded` (Tablets, desktop)49 * **Adaptive Architecture:** Utilize `ListDetailPaneScaffold` (from Material 3 adaptive libraries) for automatic two-pane layouts on foldables/tablets that collapse to one pane on phones.50 * **Flow Layouts:** `FlowRow` and `FlowColumn` for responsive wrapping of dynamic content.51* **ConstraintLayout (XML & Compose):**52 * XML: Use `res/layout` for phones and `res/layout-sw600dp` for tablets. Use Guidelines (percentage-based) and Chains to distribute space evenly.53 * Compose: Use `ConstraintLayout` when you have complex flat positioning that would require heavily nested Rows/Columns. Animations between states can be managed via `MotionLayout` (or `MotionScene`).5455## Rules & Checklists for Layouts56571. **Avoid Hardcoded Sizes:** Rely on padding, constraints, weights, and flex values instead of explicit widths/heights.582. **Design for the "In-Between":** Foldable devices are becoming common. Your layout must gracefully transition during window resizing or folding.593. **Respect Safe Areas:** Always utilize `SafeArea` (Flutter), `safeAreaPadding` (SwiftUI), or `WindowInsets` (Compose) to prevent drawing content under notches, punch-holes, or dynamic islands.604. **Touch Targets:** Adaptive layouts must ensure that as screens get smaller, touch targets DO NOT shrink below platform defaults (44pt iOS, 48dp Android).