agentleFS
danielsamotysdanielsamotys/claude-skills-iphone-duo/skills/iphone-duo-adaptive-layout/SKILL.md

iphone-duo-adaptive-layout

Skill1 starsChanged 24 days agoMITView on GitHub

Use when a React Native screen, style, safe-area padding, modal, bottom sheet, carousel, drawer or AppState handler must work on iPhone Duo (Apple's foldable), in Split View, or in any window that resizes at runtime. Typical asks are "X looks stretched/clipped/cut off on the foldable", "make X work on iPhone Duo", "replace Dimensions.get", "drawer on the big inner screen", "app is letterboxed / black bars on the unfolded screen", a file flagged by iphone-duo-readiness, or questions about hinge, posture or reserved-region APIs in React Native.

1 other project uses a version of this.

Adopted by

Most recently taken up by

  • Other versions1 project uses a version of this.

    Word for word · 0

    None found.

    Edited · 0

    None found.

    Wrote their own version · 1

    1. mirzaaghazadeh/iphone-duo-skills★ 302same name

    How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.

  • In this repository2 other files it gives its agents.

The file

We split this skill into the rules it gives an agent

10 rules. About 0 are common, 1 is distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Search for an existing window/breakpoint hook first (useWindowLayout, useBreakpoint, useResponsive).

    line 14
  2. Very specific:

    Put one test beside it. Drive the real hook through Dimensions.set: on RN 0.83 (where this was verified), jest.spyOn(RN, …

    line 29
  3. Very specific:

    Never use Dimensions.addEventListener.

    line 50
  4. Very specific:

    Do not build master-detail or two-pane screens, sidebars or tab rails without a design.

    line 60
  5. Very specific:

    Use useSafeAreaInsets() and apply top, bottom, left and right separately.

    line 64
  6. Very specific:

    Custom absolute headers: add paddingLeft: insets.left and paddingRight: insets.right next to the paddingTop.

    line 67
  7. Very specific:

    Edge-to-edge scroll content: put side insets on contentContainerStyle.

    line 68
  8. Very specific:

    Bare React Native: follow references/native-ios.md: (1) pod deployment-target clamp, (2) UIScene adoption (an iOS 27 SDK build traps at …

    line 80
  9. Distinctive:

    No orientation library and no JS orientation code.

    line 83
  10. Very specific:

    Don't name Dimensions.get or isIphoneX in new comments: the audit greps tokens.

    line 95

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Adaptive layout for iPhone Duo (React Native)

Core rule: the window is a live value, never a constant. On the Duo it changes width on fold, unfold, rotate and Split View, with no relaunch. Anything computed once from Dimensions.get() is wrong after the first fold. Read references/iphone-duo-facts.md (sizes, insets, SDK, sources) before touching code.

Assumes react-native-safe-area-context (a SafeAreaProvider at the root) and works with React Navigation or expo-router. Paths below are examples. Look for your app's equivalent first.

The one shared primitive

Search for an existing window/breakpoint hook first (useWindowLayout, useBreakpoint, useResponsive). If none exists, create one in your hooks folder (in a monorepo, in the shared UI package so every feature package can use it). Never add a second breakpoint anywhere else.

import { useWindowDimensions } from 'react-native'

// RN's stand-in for Apple's "regular" horizontal size class: Duo's inner display (≈669pt) is wide,
// every closed phone (≤466pt) and half a Split View is not.
export const WIDE_BREAKPOINT = 600

export const useWindowLayout = () => {
  const { width, height } = useWindowDimensions()
  return { width, height, isWide: width >= WIDE_BREAKPOINT }
}

Put one test beside it. Drive the real hook through Dimensions.set: on RN 0.83 (where this was verified), jest.spyOn(RN, 'useWindowDimensions') does not intercept the getter export.

const setWidth = (width: number) =>
  act(() => Dimensions.set({ window: { width, height: 800, scale: 3, fontScale: 1 } }))
const { result } = renderHook(() => useWindowLayout())
setWidth(390); expect(result.current.isWide).toBe(false)
setWidth(669); expect(result.current.isWide).toBe(true)   // same mount: proves the live re-render

Fixing a stale size read: decide in this order

#If the value…Do thisExample
1can be expressed by layoutflex: 1, '100%', aspectRatio, alignSelf: 'stretch', StyleSheet.absoluteFillObject, a flex ratio for "N% of the window", or onLayout of the parent. For the flex ratio, marginTop: height * 0.45 becomes a spacer with flex: 45 plus a sheet with flex: 55. Yoga resolves % margin and padding against width, so never use thosefull-screen photo, modal backdrop, camera preview, bottom-sheet height
2is really fixed (sized against a fixed-height row or a design constant)a named constantthumbnail inside an 80 pt card
3genuinely tracks the window and no layout can express it (carousel page width, paging or parallax offsets, snap points passed to a library)const { width, height } = useWindowLayout() inside the component; derive with useMemo; pass as an inline style or a library propITEM_WIDTH, PARALLAX_OFFSET, snapPoints
4is used by several keys of a styles.tsturn the file into a style hook memoized on the size: export const useStyles = () => { const { width } = useWindowDimensions(); return useMemo(() => StyleSheet.create({ … }), [width]) }. Consumers call useStyles() inside the component. Size from width; for a wide/compact branch use useWindowLayout().isWide, never a new thresholda bottom sheet's styles.ts

Paged lists keep their old offset after a resize. useWindowDimensions fixes the page width, but a paged FlatList or ScrollView lands between pages after a fold. Re-snap on width change: useEffect(() => { listRef.current?.scrollToIndex({ index, animated: false }) }, [width]).

Never use Dimensions.addEventListener; the hook already re-renders. Never use Dimensions.get('screen'): that is the display, not your window, and in Split View they differ.

Resize regression test (one per pattern, not one per file): render the style hook with renderHook, run act(() => Dimensions.set({ window: d, screen: d })) going from 466×678 to 669×951, and assert the sized value follows. Check that the test fails when the memo deps are frozen.

Wide layout (isWide): only these, unless a design says otherwise

  • Reading content (anything that reads as one vertical stack of text, cards, form fields or list rows: chat, forms, articles, settings, card dashboards): wrap the content and its input toolbar in one column with { width: '100%', maxWidth: WIDE_BREAKPOINT, alignSelf: 'center' }, adding flex: 1 on a View or flexGrow: 1 on a ScrollView's contentContainerStyle only when the content must fill the height (flex: 1 there stops scrolling). Put the column on the node that carries the horizontal padding, so the 600 cap includes it. If the app has a shared screen wrapper, put the column there once, then grep for screens that bypass the wrapper (raw SafeAreaView) and give each its own column. Maps, full-bleed media, camera views and immersive single-purpose screens (a timer, a counter, a player) stay full width. Full-screen overlays, modals and loaders stay outside the column so they still cover the window. A modal's own reading content goes in a column inside the modal.
  • Drawer (React Navigation): set drawerType: isWide ? 'permanent' : undefined in the drawer's screenOptions. undefined keeps the library default. This is usually the highest-leverage single change.
  • Tile grids only (photo thumbnails, square cards): numColumns={isWide ? 2 : 1} with a key that includes the column count, because FlatList can't change numColumns in place. Full-width table rows stay single-column; they read fine at 669 pt. Grids that already lay out in fixed columns stay as they are.
  • Tabs (React Navigation, expo-router, native tabs): leave them alone. Whether iOS 27.1 stacks a native tab bar vertically on its own is not verified here.
  • Do not build master-detail or two-pane screens, sidebars or tab rails without a design. Do not branch on Platform.isPad (false on the Duo), on orientation, or on device model.

Safe area: each edge on its own

Use useSafeAreaInsets() and apply top, bottom, left and right separately. Closed portrait measures { top: 0, right: 84, bottom: 34, left: 0 }, so 382 of the 466 pt are usable. Screens inside SafeAreaView edges={[…'right']} and stack headers already handle this. The usual misses:

  • Shared screen wrapper (Screen, Container) whose default edges omit 'right': add 'left', 'right' to the default once. Side insets are 0 on every other iPhone, so nothing else changes. In a monorepo, every app using the wrapper gets the fix; list the sibling apps in the PR.
  • Custom absolute headers: add paddingLeft: insets.left and paddingRight: insets.right next to the paddingTop.
  • Edge-to-edge scroll content: put side insets on contentContainerStyle. Horizontal carousels inside it still scroll.
  • A shared modal wrapper: pad the side insets there once, for every caller. Trap (react-native-modal ≤ 13 with avoidKeyboard): the library applies style to two nested views, so padding passed in style counts twice. Give each view half the inset (paddingRight: right / 2) and pin the total in a test that sums paddingRight over the rendered host nodes. In a modal:
    • top and bottom insets go in the content container or on a view inside the content (applied once), never in style;
    • on a full-screen modal the side insets show the backdrop; paint the strip with style={{ backgroundColor: <sheet colour> }} (a colour can't double; not yet checked on the sim) and keep content out of it;
    • a scrolling body needs propagateSwipe to keep swipe-to-close, or no swipeDirection at all. Otherwise the swipe gesture competes with the scroll.
  • "Has a home indicator" helpers (isIphoneX, hasNotch, height >= 812): fix the definition, not every consumer: Platform.OS === 'ios' && (initialWindowMetrics?.insets.bottom ?? 0) > 0, from react-native-safe-area-context. That keeps every phone identical and makes the closed Duo (678 pt tall) correct. The library's jest mock reports zero insets, so give the mocked initialWindowMetrics a bottom inset of 34, or every footer snapshot flips.
  • Replacing an isIphoneX ? N : M in a shared component → Math.max(insets.bottom, M). That stays within a few points of today and doesn't double-pad under a parent SafeAreaView. In new code or a single screen, use insets.bottom + M (M = the design's padding, 16 if none). Never mirror one side onto the other, and never import SafeAreaView from 'react-native'.

Native orientation: delete UIRequiresFullScreen, keep phones portrait

Measured: an app that supports multitasking fills the unfolded display even with a portrait-only orientation list, and the closed display keeps the portrait lock. UIRequiresFullScreen = true is what letterboxes the Open pose into a phone-shaped window with black bars. An app built with an SDK older than iOS 27.1 is letterboxed regardless (Apple).

  • Bare React Native: follow references/native-ios.md: (1) pod deployment-target clamp, (2) UIScene adoption (an iOS 27 SDK build traps at launch without it), (3) delete UIRequiresFullScreen from Info.plist. A size-class gate in AppDelegate is needed only if your base orientation list already includes landscape.
  • Expo: upgrade to SDK 58+ (its template already adopts UIScene) and leave ios.requireFullScreen unset or false. Keep "orientation": "portrait". No config plugin is needed. Staying on SDK ≤ 57 means no iOS 27 SDK build, so the inner display stays letterboxed; the JS fixes still help the closed display and Split View.

No orientation library and no JS orientation code.

AppState: inactive is not hidden

In Split View the app without focus is visible and inactive. Pause cameras, timers, polling and media on 'background' only, and resume on 'active'. Fix shared hooks (foreground/interval/polling helpers) once. React Query: focusManager.setFocused(state !== 'background'), not state === 'active', or refetchInterval polling stops in a visible Split View app. A per-screen nextAppState === 'active' gate for resuming is fine; a !== 'active' gate for pausing is the bug.

Done when

  • The readiness audit (iphone-duo-readiness) no longer lists the touched files.
  • Type-check, lint and the touched tests pass.
  • Then hand off to iphone-duo-verify for the simulator pass.

Don't name Dimensions.get or isIphoneX in new comments: the audit greps tokens.

Common mistakes

MistakeFix
Hardcoding 466 / 669 / 951 anywhereOnly WIDE_BREAKPOINT; everything else comes from the hook at render time
A new maxWidth: 480 / 520 / … per screenWIDE_BREAKPOINT. Existing caps on a fixed-column grid or design element are design constants (rung 2); leave them
StyleSheet.create inside the component body, rebuilt every renderA style hook with useMemo(…, [width]) (rung 4)
A long list as ScrollView + .mapHundreds of rows block JS for tens of seconds, so a fold looks "missed". Use FlatList (measured: 360 rows, 35 s → 1.5 s)
Padding a react-native-modal through style and expecting it onceWith avoidKeyboard it is applied twice; see the modal trap above
useWindowDimensions at module scopeHooks run in components. Module scope is frozen
"Fixing" it with UIRequiresFullScreen or a stronger orientation lockFull screen is what letterboxes the inner display. Delete the key; branch on width in JS
Treating iPad support (TARGETED_DEVICE_FAMILY, supportsTablet) as Duo supportThe Duo is an iPhone; the iPad flag changes nothing for it

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.