Index of every page on this site: llms.txt
All skills
kimeur avatar

/duo-continuity

@cffd95d
by Gazouzi Marouanekimeur/duology46 stars
2
Run it yourself

Keeps app state alive when iPhone Duo, Apple's foldable, folds, unfolds, rotates or resizes between the outer display and the inner display. Use when scroll position, video or audio playback, typed text, keyboard focus, selection, form input, the selected item, the navigation stack, an upload or sign-in resets or reloads on fold or unfold, and when writing or reviewing @Observable models, @SceneStorage, NavigationPath, NavigationSplitView, ScrollPosition, AnyLayout, .id, onAppear, .task, registerForTraitChanges or viewWillTransition(to:with:).

Use this Skill: https://skilld.dev/gh/kimeur/duology/duo-continuity

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencestesting.md

≈3.7k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Testing continuity on the iPhone Duo simulator

Three layers, from cheapest to closest to a real fold:

  1. a UI test that flips the size class from inside the app;
  2. a UI test that waits while you press the pose buttons and rotate in Device Hub;
  3. a manual pass in Device Hub through the matrix below.

What Xcode 27.1 can and can't do from code

Action From code? How
Rotate Not on the closed Duo Device Hub's rotate button. Measured: on the closed Duo simulator, setting XCUIDevice.shared.orientation to landscape changed the device orientation but not the app's 466 × 678 pt window (this skill's run and duo-testing's). Open: unverified. From inside the app, measured: requestGeometryUpdate(_:errorHandler:) on the open inner display failed with "The current windowing mode does not allow for programmatic changes to interface orientation."
Close, open, partially open Not from a test Device Hub buttons only. XCUIDevice has no fold or hinge property, and simctl and devicectl have no pose command (checked in Xcode 27.1). A Mac tool outside the test can press the buttons through the Accessibility API, with the user's Accessibility permission (see duo-setup).
Any hinge angle No Hold Option and drag the slider under the bezel
Split View No Drag the app by its home indicator to one side (Tech Talk 111461)
Size class change Yes, inside your app The debug flip below
Two-finger gestures No Device Hub can't send them (Xcode 27 known issue); test on a device

Manual pass in Device Hub

Run the app on the iPhone Duo simulator from Xcode; it opens in Device Hub. The three pose buttons (Closed, Partially Open, Open) sit under the bezel, to the right of the rotate controls. Click the rotate button to rotate left and Option-click it to rotate right (Interacting with your app in Device Hub). Device > Slow Animations helps you watch each step.

Set up this state first, then run each sequence and check every column after each step:

Set up Check after each step
Scroll a long list or grid halfway The same item is at the top
Select an item and push one screen in the detail Same item, same pushed screen; Back still works
Type in a field, select a word, keep the keyboard up Same text, same selection; note what the keyboard does
Fill half a form Every field kept
Start video or audio Still playing, same time, no restart
Start an upload Still running, finishes once
Open a sheet Still open, same content
Sign in Still signed in, no second sign-in screen

Sequences (each arrow is one button press or rotation):

  1. Open → Closed → Open
  2. Open → Partially Open → Open
  3. Closed portrait → rotate → Open → Closed
  4. Open → rotate → Closed → rotate → Open
  5. Open → Split View on one side → Closed → Open
  6. Open → Closed → Open → Closed → Open, quickly, while scrolling
  7. Open → Closed while typing, then Open while typing

Android's large-screen quality tests call these state and combination checks (adaptive app quality, T-Config_State and T-Config_Combinations). The idea carries over; the rules are Android's.

The debug flip: app side

A launch switch, ignored in release builds, adds two things at the window root:

  • a button that overrides the horizontal size class, so your own size-class code and NavigationSplitView take the same path a fold takes;
  • hidden labels: a one-line summary of the state that must survive, the current size class, and the window's size in points.
import SwiftUI

enum ContinuityTesting {
    #if DEBUG
    static let isOn = ProcessInfo.processInfo.arguments.contains("-continuityTesting")
    #else
    static let isOn = false
    #endif
}

struct ContinuityHarness: ViewModifier {
    let summary: String                                 // built from your model
    @State private var override: UserInterfaceSizeClass?
    @State private var size = CGSize.zero
    @Environment(\.horizontalSizeClass) private var real

    func body(content: Content) -> some View {
        if ContinuityTesting.isOn {
            content
                .environment(\.horizontalSizeClass, override ?? real)
                .frame(maxWidth: .infinity, maxHeight: .infinity)   // fill the window, however small the content
                .background {
                    Color.clear
                        .onGeometryChange(for: CGSize.self) { $0.size } action: { size = $0 }
                        .ignoresSafeArea()                          // keep this last: the reader then sees the whole window
                }
                .overlay(alignment: .bottomLeading) {
                    VStack(alignment: .leading) {
                        Button("Flip size class") {
                            override = (override ?? real) == .compact ? .regular : .compact
                        }
                        .accessibilityIdentifier("continuity.flip")
                        Text((override ?? real) == .compact ? "compact" : "regular")
                            .accessibilityIdentifier("continuity.sizeClass")
                        Text("\(Int(size.width))x\(Int(size.height))")
                            .accessibilityIdentifier("continuity.windowSize")
                        Text(summary)
                            .accessibilityIdentifier("continuity.summary")
                    }
                    .font(.caption2)
                    .opacity(0.02)                      // present for tests, invisible to people
                }
        } else {
            content
        }
    }
}

extension View {
    func continuityHarness(summary: String) -> some View {
        modifier(ContinuityHarness(summary: summary))
    }
}

Use it on the window root, with a summary built from the model:

import SwiftUI
import Observation

@MainActor @Observable
final class ReaderModel {
    var selection: Int?
    var topItem: Int?
    var draft = ""
    var isPlaying = false

    var summary: String {
        "sel=\(selection.map(String.init) ?? "-") top=\(topItem.map(String.init) ?? "-") "
            + "draft=\(draft.count) playing=\(isPlaying)"
    }
}

struct ReaderRoot: View {
    @State private var model = ReaderModel()
    var body: some View {
        Text("Your root view")
            .environment(model)
            .continuityHarness(summary: model.summary)
    }
}
  • The if in the harness reads a launch switch that never changes while the app runs, so it never changes identity.
  • The size label must show the window, not your content or the safe area. Measured on the closed Duo simulator: the window was 466 × 678 pt with 84 pt right and 34 pt bottom safe-area insets. A reader on the content saw the text's own 108 × 20 pt; a reader placed after .ignoresSafeArea() saw 382 × 644 pt; the reader above, inside .ignoresSafeArea(), saw 466 × 678 pt.
  • Measured: this kind of override made NavigationSplitView collapse and expand, and switched if/else branches, on the iOS 27.1 simulator (evidence.md).
  • The override changes the size class only. It doesn't move the window to the other display, resize it, or touch the keyboard. Keep the Device Hub pass.
  • UIKit: set traitOverrides.horizontalSizeClass on the root view controller instead (traitOverrides, iOS 17). Measured: it ran registerForTraitChanges handlers and changed a compositional layout's column count.

The UI tests

The first test runs on its own. It doesn't rotate, because rotation from a UI test doesn't resize the app on the closed Duo (see the table above). The second test waits for you to fold and rotate in Device Hub, so it is skipped unless you ask for it.

import XCTest

// `nonisolated` keeps XCTestCase's initializers valid when the target defaults to MainActor isolation.
nonisolated final class ContinuityUITests: XCTestCase {
    @MainActor
    private func launch() -> XCUIApplication {
        let app = XCUIApplication()
        app.launchArguments += ["-continuityTesting"]
        app.launch()
        return app
    }

    @MainActor
    private func waitForChange(of element: XCUIElement, from old: String, timeout: TimeInterval) -> Bool {
        let changed = XCTNSPredicateExpectation(predicate: NSPredicate(format: "label != %@", old), object: element)
        return XCTWaiter().wait(for: [changed], timeout: timeout) == .completed
    }

    /// Flip the size class there and back, and check the summary never changes.
    @MainActor
    func testStateSurvivesSizeClassFlip() throws {
        let app = launch()
        let summary = app.staticTexts["continuity.summary"]
        let sizeClass = app.staticTexts["continuity.sizeClass"]
        XCTAssertTrue(summary.waitForExistence(timeout: 10))

        // Build up state here: scroll, select, type, start playback.
        let before = summary.label
        let start = sizeClass.label
        let flipped = start == "compact" ? "regular" : "compact"

        app.buttons["continuity.flip"].tap()
        XCTAssertTrue(sizeClass.wait(for: \.label, toEqual: flipped, timeout: 5))
        XCTAssertEqual(summary.label, before, "state changed on a size-class flip")

        app.buttons["continuity.flip"].tap()
        XCTAssertTrue(sizeClass.wait(for: \.label, toEqual: start, timeout: 5))
        XCTAssertEqual(summary.label, before, "state changed on the flip back")
    }

    /// Real fold and rotation. Run with TEST_RUNNER_DUO_MANUAL_FOLD=1 and use Device Hub when asked.
    /// Works from either pose: it asks for the other pose first, then a rotation, then the first pose again.
    @MainActor
    func testStateSurvivesRealFold() throws {
        try XCTSkipUnless(ProcessInfo.processInfo.environment["DUO_MANUAL_FOLD"] == "1",
                          "Manual test: needs someone to press the pose buttons in Device Hub.")
        let app = launch()
        let summary = app.staticTexts["continuity.summary"]
        let sizeClass = app.staticTexts["continuity.sizeClass"]
        let windowSize = app.staticTexts["continuity.windowSize"]
        XCTAssertTrue(summary.waitForExistence(timeout: 10))
        let before = summary.label
        let start = sizeClass.label                      // "compact" when closed, "regular" when open
        let other = start == "compact" ? "regular" : "compact"
        var size = windowSize.label

        XCTContext.runActivity(named: start == "compact" ? "Press Open in Device Hub" : "Press Closed in Device Hub") { _ in
            XCTAssertTrue(sizeClass.wait(for: \.label, toEqual: other, timeout: 60))
            XCTAssertTrue(waitForChange(of: windowSize, from: size, timeout: 5), "the fold did not resize the window")
            XCTAssertEqual(summary.label, before, "state changed on the first fold")
        }
        size = windowSize.label
        XCTContext.runActivity(named: "Click the rotate button in Device Hub") { _ in
            XCTAssertTrue(waitForChange(of: windowSize, from: size, timeout: 60), "rotation did not resize the window")
            XCTAssertEqual(summary.label, before, "state changed on rotation")
        }
        XCTContext.runActivity(named: start == "compact" ? "Press Closed in Device Hub" : "Press Open in Device Hub") { _ in
            XCTAssertTrue(sizeClass.wait(for: \.label, toEqual: start, timeout: 60))
            XCTAssertEqual(summary.label, before, "state changed on the second fold")
        }
    }
}

Run them:

# Automatic test
DEVELOPER_DIR=/Applications/Xcode-27.1.app/Contents/Developer xcodebuild test \
  -scheme YourApp -destination 'platform=iOS Simulator,name=iPhone Duo,OS=27.1' \
  -parallel-testing-enabled NO \
  -only-testing:YourAppUITests/ContinuityUITests/testStateSurvivesSizeClassFlip

# Manual fold test: keep Device Hub visible; fold and rotate when the test asks
TEST_RUNNER_DUO_MANUAL_FOLD=1 DEVELOPER_DIR=/Applications/Xcode-27.1.app/Contents/Developer xcodebuild test \
  -scheme YourApp -destination 'platform=iOS Simulator,name=iPhone Duo,OS=27.1' \
  -parallel-testing-enabled NO \
  -only-testing:YourAppUITests/ContinuityUITests/testStateSurvivesRealFold
  • -parallel-testing-enabled NO keeps the run on the simulator you see in Device Hub. With parallel testing on, xcodebuild may run the tests on a clone: one more simulator on disk, in its own pose, where the manual test waits for a fold nobody can make.
  • xcodebuild passes any TEST_RUNNER_ variable to the test runner with the prefix removed (man xcodebuild, Xcode 27.1).
  • wait(for:toEqual:timeout:) polls a key path until it matches. XCTSkipUnless keeps the manual test out of normal runs.
  • The summary should hold only what must not change. Leave the size class out of it.
  • Measured: the automatic test passed on a closed iPhone Duo simulator (iOS 27.1), in an app target with Swift 6 and MainActor default isolation. It found the labels at 2% opacity. The manual test skipped itself when the variable was unset.
  • Unverified: the manual test's fold and rotate steps, because they need a person at Device Hub. Whether Device Hub's rotate button resizes your app depends on the display and your supported orientations (Tech Talk 111461). Delete the rotate step if your app doesn't rotate in that pose.
  • duo-testing has general tips for UI tests on the Duo simulator.

Quick checks without a test target

  • Print the state summary from onChange(of: sizeClass) and watch the console while you press the Device Hub buttons.
  • Add let _ = Self._printChanges() to a view body while debugging. It prints why the body ran. @identity in that line means the view got a new identity. Measured: after a flip, a view inside an if/else printed @self, @identity, __count changed., and the same view inside AnyLayout printed @self changed. The underscore marks it as not public API: use it in debug builds only, and don't parse its output.

Source: SKILL.md on GitHub

No rule matched.

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts1mo3 checks · Risk SAFE
  • Gen Agent Trust Hub1mo

    This skill provides technical guidance and code patterns for managing application state on the iPhone Duo (foldable) platform. It contains documentation and code snippets for SwiftUI and UIKit developers.

  • Socket1mo

    No alerts

  • Snyk1mo

    Risk: LOW · No issues

Signed by skilld at cffd95d. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 2 weeks ago.

Activeupdated last month
Other metadata
metadata
{
  "verified": "Xcode 27.1 (27A9275), iOS 27.1 simulator, device: no",
  "sources": "https://github.com/Kimeur/duology/blob/main/reference/sources.md"
}

README badge

README badge for kimeur/duology/duo-continuity