roosterboy, indeed you are right. I am playing with a basic application draft, and after removing some unnecessary constraints I was able to get a behaviour that did not maximise the window, but kept it within the set boundaries.
However, I could still use your advice. Right now, I am using a fixed value for my minimum root size, say 300-300, and it correctly switches between the minimum window size and the frame size for the child view. But if I remove all .frame
s, it gets back to maximising the window, without taking the child view size into account (let's say it's a Text
and on paper it only takes the amount of space it needs.
My question is, what is the best practice to make the zoomed size always the size of the child view? I used GeometryReader
on the child view (geo.size.width
, geo.size.height
) but to no avail. How to make the window resize to the minimum size of the Text
view?
Sample code below:
@main
struct MyApp: App {
var body: some Scene {
WindowGroup {
RootView()
.background(Color(.windowBackgroundColor))
.onReceive(NotificationCenter.default.publisher(
for: NSApplication.willUpdateNotification), perform: { _ in
for window in NSApplication.shared.windows {
window.collectionBehavior = .fullScreenAuxiliary
}
})
}
}
}
struct RootView: View {
var body: some View {
GeometryReader { geo in
Text("Hello, world!")
.frame(minWidth: geo.size.height, maxWidth: 500, minHeight: geo.size.height, maxHeight: 500)
.toolbar {
ToolbarItemGroup(placement: .status) {
Spacer()
StatusView()
Spacer()
}
}
}
}
}
Above code crashes, BTW. :D