fix(mac): size context bar to menu

This commit is contained in:
Peter Steinberger
2025-12-13 00:23:00 +00:00
parent 3bb33bdeed
commit 5e51107711
4 changed files with 54 additions and 11 deletions

View File

@@ -0,0 +1,20 @@
import SwiftUI
private struct ViewWidthPreferenceKey: PreferenceKey {
static let defaultValue: CGFloat = 0
static func reduce(value: inout CGFloat, nextValue: () -> CGFloat) {
value = max(value, nextValue())
}
}
extension View {
func onWidthChange(_ onChange: @escaping (CGFloat) -> Void) -> some View {
self.background(
GeometryReader { proxy in
Color.clear.preference(key: ViewWidthPreferenceKey.self, value: proxy.size.width)
})
.onPreferenceChange(ViewWidthPreferenceKey.self, perform: onChange)
}
}