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

/duo-transitions

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

Makes fold, unfold, partial fold and rotation on iPhone Duo, Apple's foldable, feel like one app instead of a reload. Use when a screen flashes, blinks, jumps, reloads, pops or moves its controls as the phone opens or closes, or when writing or reviewing SwiftUI or UIKit code that animates a resize: AnyLayout, stable ForEach IDs, matchedGeometryEffect, geometryGroup, .animation(_:value:), transaction, withAnimation, contentTransition, accessibilityReduceMotion, viewWillTransition(to:with:), animate(alongsideTransition:completion:), UIView.animate with a SwiftUI spring, and 120 Hz ProMotion frame budgets.

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

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencesperformance.md

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

Smooth at 120 Hz

A fold lays out the whole window in one go, and on the inner display that window is about twice as wide. This file covers the frame budget, custom per-frame motion, and how to test. The code typechecks against the iOS 27.1 simulator SDK in Swift 5 mode, Swift 6 mode, and Swift 6 with MainActor as the default isolation. Nothing here has run on a real iPhone Duo.

The numbers

  • Both displays have ProMotion with an adaptive refresh rate up to 120 Hz (iPhone Duo specs). On iPhone, ProMotion switches between 10 and 120 Hz (Optimizing ProMotion).
  • At 120 Hz a frame lasts 8.3 ms. By default your main thread gets one frame to finish its part, and the render server gets one for its own (Understanding hitches). Miss it and the frame is late: a hitch.
  • The system drops the top rates in Low Power Mode and when the phone is hot. Core Animation can also pick a rate on its own (Optimizing ProMotion).
  • Measured: the iPhone Duo simulator reports maximumFramesPerSecond = 60 (device facts). It can't show 120 Hz, and its timing says little about a device.

What you get for free

SwiftUI animations, UIKit animations and Core Animation already run at the rate the display offers. A .smooth spring, a matched geometry move or a coordinator animation needs no frame-rate code. Spend your effort on the budget instead.

Keep the resize update cheap

A fold runs body for every view that reads the size class or the size, then lays out the window.

  • Measured: on Open, a full-width view went through three new widths within 50 to 250 ms: 382 → 466 → 951 → 867 pt (the safe area insets change around the resize). Every onGeometryChange action and GeometryReader that reads the width runs for each of them. Return a small value from the transform, such as a column count, so the action runs only when that value changes.
  • No sorting, filtering, date or number formatting, or image decoding in body. Do it once when the data changes.
  • Use LazyVStack, LazyVGrid or List for long content, so a fold lays out only what is on screen.
  • Don't put a GeometryReader in every row. Read the size once, high up, and pass a value down.
import SwiftUI
import Observation

struct Order: Identifiable, Hashable, Sendable {
    let id: Int
    var title: String
    var total: Decimal
    var date: Date
}

struct OrderRow: Identifiable, Hashable, Sendable {
    let id: Int
    let title: String
    let detail: String
}

@MainActor @Observable
final class OrdersModel {
    private(set) var orders: [Order] = []
    /// Sorted and formatted once, when the data changes. A fold re-runs body; it must not redo this.
    private(set) var rows: [OrderRow] = []

    func setOrders(_ new: [Order]) {
        orders = new
        rows = new.sorted { $0.date > $1.date }.map { order in
            OrderRow(id: order.id, title: order.title, detail: order.total.formatted(.currency(code: "EUR")))
        }
    }
}

struct OrdersList: View {
    let model: OrdersModel
    var body: some View {
        List(model.rows) { row in      // no sorting, filtering or formatting here
            LabeledContent(row.title, value: row.detail)
        }
    }
}

Custom per-frame motion

Only for drawing you do yourself, such as a hinge-driven effect or a game. Use a CADisplayLink:

  • Ask for a range with preferredFrameRateRange. Request 120 Hz only for large, fast movement; small or slow changes look the same at a lower rate and cost less. An animation that asks for 120 Hz and can't keep up looks worse than one that holds a steady lower rate.
  • Drive the animation from targetTimestamp, the time the frame will appear, not from a callback count. The rate can change at any moment.
  • On iPhone, Core Animation applies rates above its default only when Info.plist has CADisableMinimumFrameDurationOnPhone set to YES.
import QuartzCore
import UIKit

/// Drives a custom effect from the display's refresh, at whatever rate the system grants.
/// Above 60 Hz on iPhone it also needs CADisableMinimumFrameDurationOnPhone = YES in Info.plist.
@MainActor
final class FrameDriver {
    private var link: CADisplayLink?
    private var start: CFTimeInterval = 0
    private let duration: CFTimeInterval
    private let update: (Double) -> Void

    init(duration: CFTimeInterval, update: @escaping (Double) -> Void) {
        self.duration = duration
        self.update = update
    }

    func run() {
        stop()
        let link = CADisplayLink(target: self, selector: #selector(step(_:)))
        // Large, fast movement may use up to 120 Hz. Small or slow changes don't need it.
        link.preferredFrameRateRange = CAFrameRateRange(minimum: 80, maximum: 120, preferred: 120)
        link.add(to: .main, forMode: .common)
        start = CACurrentMediaTime()
        self.link = link
    }

    func stop() {
        link?.invalidate()
        link = nil
    }

    @objc private func step(_ link: CADisplayLink) {
        // Pace by the time the frame will appear, not by counting callbacks:
        // the rate can drop at any moment (Low Power Mode, heat, other animations).
        let progress = min(1, (link.targetTimestamp - start) / duration)
        update(progress)
        if progress >= 1 { stop() }
    }
}
<key>CADisableMinimumFrameDurationOnPhone</key>
<true/>

The hinge stream

  • onHingeChange and UIHingeInteraction report the angle while the phone moves. Apple presents the hinge as a source of effects and interactions, and points to arrangements and reserved regions for layout (Tech Talk 111464).
  • Measured: while the simulator opened, our probe's hinge updates arrived 30 to 180 ms apart. A device may report at another rate; UIKit's header says the rate and precision can change.
  • Map the angle to a cheap property (an offset, an opacity, a rotation) on one view. Never run layout, a fetch or a model write per update.
  • Under Reduce Motion, turn hinge-driven zoom, parallax and tilt off.

Test it

  1. Simulator, for layout: Device Hub > Device > Slow Animations, then press Closed, Open and Partially Open (Device Hub). Slow motion shows a pop, a jump or a control that leaves and comes back. It says nothing about frame rate. To measure what each fold costs your main thread on the simulator, before and after a change, use duo-fold-cost (the duo-performance skill, duology-ship).
  2. Device, for smoothness: profile open and close with the Hitches instrument in Instruments. In the field, Xcode Organizer's Hitches metric reports a hitch rate in ms of pause per second; Apple calls 10 ms/s or less good, up to 25 ms/s a warning, and more than that critical (Understanding hitches).
  3. Device, under stress: repeat with Low Power Mode on. The rate drops, and pacing by targetTimestamp keeps custom motion at the right speed.

Sources

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.

1 warning3d3 checks · Risk SAFE
  • Gen Agent Trust Hub3d

    This skill provides comprehensive technical guidance and Swift code examples for implementing UI transitions on foldable devices. It includes detailed performance measurements, best practices for SwiftUI and UIKit, and checklists for code reviews. No malicious patterns or security vulnerabilities were detected.

  • Socket3d

    No alerts

  • Snyk3d

    Risk: MEDIUM · 1 issue

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-transitions