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

/duo-ergonomics

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

Puts controls where hands can reach them on iPhone Duo, Apple's foldable iPhone: one-handed on the closed phone, two hands on the open display, the book grip, and hands-free on a table. Use it when you decide where a primary action, a floating button, player controls or a custom control strip goes; when buttons sit at the top centre of the open display, on the fold or out of thumb reach; when you check thumb zones or reachability; when you design for left-handed people or right-to-left languages; or when touch targets are small. Covers why bars move to the side edge, toolbarVerticalEdge and verticalBarEdge (read them; right to left changes the name, not the side), visibilityPriority for bottom-bar actions, a ThumbCorner modifier for floating controls, an in-app hand preference, ArrangementView with the overlay style to put controls in the bottom half, reservedRegions(kind: .division) to keep targets off the fold, and 44 pt hit regions with frame(minWidth:minHeight:) and contentShape on the label.

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

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencesuikit.md

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

duo-ergonomics in UIKit

Depth for ../SKILL.md. The same rules as the SwiftUI sections, in UIKit. Every snippet typechecks against the iOS 27.1 simulator SDK.

The UIKit names, all iOS 27.1 (API index):

  • UITraitCollection.verticalBarEdge: .leading, .trailing or .unspecified. Apple's doc says it gives the system's preferred edge whether or not a bar is showing, and .unspecified where the system never places a vertical bar (doc).
  • UITraitCollection.systemTraitsAffectingVerticalBarEdge: pass it to registerForTraitChanges(_:handler:) to hear when the edge may change.
  • UIOverlayArrangement with ViewProperties.edge: the edge the view takes when the overlay goes side by side (SDK header UIOverlayArrangement.h).

Floating button near the thumb

The UIKit version of ThumbCorner. Leading and trailing anchors flip in right-to-left languages, the same way verticalBarEdge does, so the button follows the bar without extra code.

import UIKit

// requires: HandPreference (SKILL.md, section 2)

/// Pins one floating button to the bottom corner nearest the thumb.
@available(iOS 27.1, *)
final class ThumbButtonViewController: UIViewController {
    /// Your own setting for floating controls. System bars ignore it.
    var handPreference = HandPreference.automatic {
        didSet { placeButton() }
    }

    private let button = UIButton(type: .system)
    private var leadingPin: NSLayoutConstraint?
    private var trailingPin: NSLayoutConstraint?

    override func viewDidLoad() {
        super.viewDidLoad()
        var config = UIButton.Configuration.filled()
        config.image = UIImage(systemName: "location.fill")
        config.cornerStyle = .capsule
        config.buttonSize = .large
        button.configuration = config
        button.accessibilityLabel = "My Location"
        button.translatesAutoresizingMaskIntoConstraints = false
        view.addSubview(button)

        let guide = view.safeAreaLayoutGuide
        // 16 pt from the edge: next to a vertical bar the margin is 0.
        leadingPin = button.leadingAnchor.constraint(equalTo: guide.leadingAnchor, constant: 16)
        trailingPin = guide.trailingAnchor.constraint(equalTo: button.trailingAnchor, constant: 16)
        NSLayoutConstraint.activate([
            button.widthAnchor.constraint(greaterThanOrEqualToConstant: 56),
            button.heightAnchor.constraint(greaterThanOrEqualToConstant: 56),
            guide.bottomAnchor.constraint(equalTo: button.bottomAnchor, constant: 16),
        ])

        registerForTraitChanges(UITraitCollection.systemTraitsAffectingVerticalBarEdge) {
            (self: Self, _: UITraitCollection) in
            self.placeButton()
        }
        placeButton()
    }

    private func placeButton() {
        guard isViewLoaded else { return }
        let leftToRight = view.effectiveUserInterfaceLayoutDirection == .leftToRight
        let onLeading = switch handPreference {
        case .left: leftToRight
        case .right: !leftToRight
        case .automatic: traitCollection.verticalBarEdge == .leading  // .unspecified: trailing
        }
        // Turn one pin off before the other goes on, so they never conflict.
        (onLeading ? trailingPin : leadingPin)?.isActive = false
        (onLeading ? leadingPin : trailingPin)?.isActive = true
    }
}

Not run on the simulator; the SwiftUI version was (see measured.md). With right to left forced, SwiftUI's edge read .leading while the bar stayed on the right, and we expect verticalBarEdge to do the same. Unverified in UIKit.

Controls in the bottom half or on the bar's half

An overlay arrangement puts its primary in the trailing or bottom part when the phone is partly open (hub). Make the controls the primary. This version also sends them to the bar's half when the overlay goes side by side, so they stay with the bar in right-to-left languages (judgement, unverified folded).

import UIKit

/// Video behind, controls in front. Partly open, the controls move to the bottom (tabletop)
/// or to the half with the vertical bar (book).
@available(iOS 27.1, *)
final class PlayerContainerViewController: UIViewController {
    private let arrangement = UIArrangementViewController()
    private let controls: UIViewController
    private let video: UIViewController

    init(controls: UIViewController, video: UIViewController) {
        self.controls = controls
        self.video = video
        super.init(nibName: nil, bundle: nil)
    }

    required init?(coder: NSCoder) { fatalError("init(coder:) is not used") }

    override func viewDidLoad() {
        super.viewDidLoad()
        addChild(arrangement)
        arrangement.view.frame = view.bounds
        arrangement.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
        view.addSubview(arrangement.view)
        arrangement.didMove(toParent: self)

        arrangement.setViewController(controls, for: .primary)
        arrangement.setViewController(video, for: .secondary)
        applyOverlay()
        registerForTraitChanges(UITraitCollection.systemTraitsAffectingVerticalBarEdge) {
            (self: Self, _: UITraitCollection) in
            self.applyOverlay()
        }
    }

    private func applyOverlay() {
        var overlay = UIOverlayArrangement()
        var controlsProperties = overlay.defaultViewProperties
        controlsProperties.edge = traitCollection.verticalBarEdge == .leading ? .leading : .trailing
        overlay.setViewProperties(controlsProperties, for: .primary)
        arrangement.updateArrangement(overlay, animated: true)
    }
}

Inside the controls view controller, pin the control strip to the bottom of its safe area. Flat, the primary covers the whole screen; duo-patterns measured a short SwiftUI primary at the top edge, out of thumb reach.

Targets of 44 pt

import UIKit

/// An icon button whose hit region is never smaller than 44 x 44 pt.
@MainActor
func makeIconButton(title: String, systemImage: String, action: UIAction) -> UIButton {
    var config = UIButton.Configuration.plain()
    config.image = UIImage(systemName: systemImage)
    let button = UIButton(configuration: config, primaryAction: action)
    button.accessibilityLabel = title
    button.translatesAutoresizingMaskIntoConstraints = false
    NSLayoutConstraint.activate([
        button.widthAnchor.constraint(greaterThanOrEqualToConstant: 44),
        button.heightAnchor.constraint(greaterThanOrEqualToConstant: 44),
    ])
    return button
}
  • The button's bounds take the taps, so the 44 pt constraints make the hit region 44 pt even when the symbol is small.
  • For a frequent control on a phone that sits on a table, use config.buttonSize = .large as well (judgement).
  • Keep 12 pt or more between bezeled buttons (HIG, Accessibility).

Keep the bar where it is

Don't return .disabled from preferredVerticalBarBehavior to move controls for one hand. Apple names three cases for turning vertical bars off: a calculator-like screen, a full-screen video player and a sheet with a single Close item (talk 111462, 14:20, doc; details in duo-navigation). One-handed use is not one of them.

Source: SKILL.md on GitHub

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

    The duo-ergonomics skill provides design and development guidance for foldable device interfaces. It includes UI layout patterns, touch target specifications, and auditing tools for developers using SwiftUI and UIKit. No malicious patterns or security risks were identified.

  • 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-ergonomics