In a SwiftUI three split navigation view on iPad, how to check if the primary is folded?

In UIKit, I believe we can check if the split view controller primary view is in collapsed state...but can't figure out a way to check if the primary view is collapsed in SwiftUI

I tried using the horizontalSizeClass == .regular check in the secondary view...but it is always .regular for the secondary view on an iPad.

Any pointers will be deeply appreciated
You can use the onAppear and onDisappear modifiers on the primary view in the NavigationView.

For example:
Code Block Swift
NavigationView {
Text("Primary")
.onAppear { print("Unfolded") }
.onDisappear { print("Folded") }
       
Text("Supplementary")
Text("Secondary")
}

The primary view is folded by default, so you can toggle an @State boolean variable when the primary view appears (unfolds) and disappears (folds).
Thanks @BabyJ for the response. Though I try to avoid using .onAppear and .onDisappear callbacks unless really I have to ... in this case this might do the trick. I will give it a spin.

I was so fixated that this check wasn't provided explicit in the framework api... now I have to confess I am a bit embarrassed that I didn't think of this myself :)

Thanks again for taking time. Appreciate your suggestion.
I did try out your suggestion and I don't think it works completely the way we imagined. At launch, The primary view's onAppear is invoked even when the primary view is in collapsed state ... so that kind of complicates things for initial scenarios.

Just thought I give an update
I think that might be the only quirk with that particular solution. I’m sure there’s a workaround to this, or just an entirely different solution, but I’m confident you can solve this - maybe another boolean that is true on app launch and then toggled to false afterwards.

Hopefully, Apple can introduce better APIs for these features at WWDC21.
Actually I did try the boolean on app launch (apparently developers think alike :)). It is still messy and unreliable. We do not have control over .onAppear and .onDisappear invocations by the framework in the context of an entire complexity of a view hierarcy. That is precisely why I hesitate to rely on them unless I really have to.

I am also hoping that gaps between SwiftUI and UIKit with be narrowed down in the upcoming WWDC. Thanks again for taking time out to respond.
In a SwiftUI three split navigation view on iPad, how to check if the primary is folded?
 
 
Q