Skip to content

maximumPrimaryColumnWidth for NavigationSplitView always resets on iOS 18 #449

@fguerrero-e

Description

@fguerrero-e

Description

Hello,
I'm working on updating a project from using NavigationView into the new NavigationSplitView and NavigationStack since the min deployment iOS has been bumped to iOS 16. I encountered an issue when trying to change the default width of the sidebar of a NavigationSplitView in a 2 columns setup (aka the Master View). The property maximumPrimaryColumnWidth during the .instrospect block is always reseted only on iOS 18 (default value: -3.4028234663852886e+38) which forces me to set this property every time instead of just once as I had it before. Even so, when showing a sheet, you can see in the back the sidebar's width changing which doesn't look good (the property being reset is happening regardless of the sheet and the ObservableObject, you can confirm this with the print, this is just a setup to see the problem visually).
Please advise if this is an issue with the library or if I should raise it to Apple (since they're always changing the SwiftUI components every release...)
Below I put the code from a new project with SwiftUIIntrospect 1.3.0 installed through Cocoapods.

Checklist

Expected behavior

NavigationSplitView.iOS.17.mov

Actual behavior

NavigationSplitView.iOS.18.mov

Steps to reproduce

import SwiftUI
import SwiftUIIntrospect

@main
struct testApp: App {
    @ObservedObject var vm = VM()
    var body: some Scene {
        WindowGroup {
            NavigationSplitView {
                Button("Side") {
                    vm.show = true
                }
            } detail: {
                Text("Detail")
            }
            .introspect(.navigationSplitView, on: .iOS(.v16, .v17, .v18)) { (splitViewController: UISplitViewController) in
                print("MAX " + splitViewController.maximumPrimaryColumnWidth.description)
                print("MIN " + splitViewController.minimumPrimaryColumnWidth.description)
                print("FRACTION " + splitViewController.preferredPrimaryColumnWidthFraction.description)
                splitViewController.preferredPrimaryColumnWidthFraction = 0.40
                let minimumWidth = min(splitViewController.view.bounds.width,splitViewController.view.bounds.height)
                splitViewController.minimumPrimaryColumnWidth = minimumWidth / 2
                splitViewController.maximumPrimaryColumnWidth = minimumWidth
            }
            .sheet(isPresented: $vm.show) {
                Text("sheet")
            }
        }
    }
}

class VM: ObservableObject {
    @Published var show = false
}

Version information

1.3.0

Destination operating system

iOS 18

Xcode version information

16.2

Swift Compiler version information

swift-driver version: 1.115.1 Apple Swift version 6.0.3 (swiftlang-6.0.3.1.10 clang-1600.0.30.1)
Target: x86_64-apple-macosx15.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions