SwiftUI - MenuBarExtra with .window style: Layout issue with ScrollView

229 views Asked by At

I tried to create a menubar application for macOS but since it contains multiple Views in a Scroll, as you may imagine, i had to use .menuBarExtraStyle(.window).

So far so good.

The point is: the first time I open the menu the height seems to layout properly, but from the second time on, the view resizes to a certain smaller height amount. You can try with this simple snippet:

MenuBarExtra("", systemImage: "info") {
    ScrollView {
        VStack(alignment: .leading) {
            ForEach(0..<100) {
                Text("Row \($0)")
            }
        }
    }
}
.menuBarExtraStyle(.window)

Changing .menuBarExtraStyle(.window) to .menuBarExtraStyle(.menu) fixes the problem but of course you can't build your own layout, functionalities, etc... taking advantage of the .window style just display.

Even setting a maximum height - .frame(maxHeight: maxHeight) - for the ScrollView, doesn't seem to solve this behavior.

Same result setting .frame(maxHeight: .infinity) for the VStack in the example code.

Did anyone faced this issue? Maybe there's a proper way to proceed and build this kind of layout maintaining the height stable?

0

There are 0 answers