Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

ActiveFoldDivisionReader

A lightweight SwiftUI ViewModifier that detects whether the device is in a partially folded state — specifically tracking the active fold division reserved region introduced in iOS 27.1.

Built on top of Apple's reservedRegions(kind:options:layoutDirectionBehavior:) API.

What It Does

On iPhone Duo, the system exposes reserved regions where the physical fold divides the display. ActiveFoldDivisionReader gives you a simple Bool binding that tells you whether such a fold division is currently active — so you can adapt your layout accordingly.

On older OS versions (< iOS 27.1), it gracefully falls back and sets the binding to false.

Usage

1. Copy Sources/ActiveFoldDivisionReader.swift into your Xcode project.

2. Use the .activeFoldDivisionReader(hasActiveDivision:) modifier on any view:

import SwiftUI

struct ContentView: View {
    @State private var isFolded = false

    var body: some View {
        HStack {
            SidebarView()
            if !isFolded {
                DetailView()
            }
        }
        .activeFoldDivisionReader(hasActiveDivision: $isFolded)
    }
}

When isFolded becomes true, the device has an active fold division and you can rearrange your UI — hide panels, swap layouts, show a compact mode, etc.

Example: Adaptive Two-Pane Layout

struct AdaptiveView: View {
    @State private var hasActiveDivision = false

    var body: some View {
        Group {
            if hasActiveDivision {
                // Fold is active — show each pane on its own side
                HStack(spacing: 0) {
                    LeftPane()
                    RightPane()
                }
            } else {
                // No fold — standard layout
                NavigationSplitView {
                    LeftPane()
                } detail: {
                    RightPane()
                }
            }
        }
        .activeFoldDivisionReader(hasActiveDivision: $hasActiveDivision)
    }
}

Requirements

  • iOS 27.1+ for fold detection (gracefully degrades on earlier versions)
  • Swift 6.2+
  • Xcode 27+

Installation

This is a single-file utility — just drag and drop.

  1. Download or clone this repository
  2. Copy Sources/ActiveFoldDivisionReader.swift into your Xcode project
  3. Make sure the file is added to your target

License

This project is licensed under the MIT License — see the LICENSE file for details.

You are free to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of this software. Contributions, forks, and pull requests are very welcome.

Contributing

Contributions are welcome! Feel free to:

  • Open an issue for bugs or feature requests
  • Submit a pull request
  • Fork and build on top of it

Contact

If you have questions, suggestions, or just want to say hi — open an issue or reach out.

About

A lightweight SwiftUI ViewModifier to detect active fold divisions and adapt layouts for foldable devices.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages