mirror of
https://github.com/yattee/yattee.git
synced 2025-04-27 23:40:35 +05:30
Fix scrolling of favorites on macOS Big Sur
This commit is contained in:
parent
cc2bf90218
commit
c4b5c7ce41
@ -29,6 +29,9 @@ struct FavoritesView: View {
|
|||||||
#else
|
#else
|
||||||
ForEach(favorites) { item in
|
ForEach(favorites) { item in
|
||||||
FavoriteItemView(item: item, dragging: $dragging)
|
FavoriteItemView(item: item, dragging: $dragging)
|
||||||
|
#if os(macOS)
|
||||||
|
.workaroundForVerticalScrollingBug()
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
42
macOS/VerticalScrollingFix.swift
Normal file
42
macOS/VerticalScrollingFix.swift
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// source: https://stackoverflow.com/a/65002837
|
||||||
|
|
||||||
|
import SwiftUI
|
||||||
|
|
||||||
|
// we need this workaround only for macOS
|
||||||
|
// this is the NSView that implements proper `wantsForwardedScrollEvents` method
|
||||||
|
final class VerticalScrollingFixHostingView<Content>: NSHostingView<Content> where Content: View {
|
||||||
|
override func wantsForwardedScrollEvents(for axis: NSEvent.GestureAxis) -> Bool {
|
||||||
|
axis == .vertical
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is the SwiftUI wrapper for our NSView
|
||||||
|
struct VerticalScrollingFixViewRepresentable<Content>: NSViewRepresentable where Content: View {
|
||||||
|
let content: Content
|
||||||
|
|
||||||
|
func makeNSView(context _: Context) -> NSHostingView<Content> {
|
||||||
|
VerticalScrollingFixHostingView<Content>(rootView: content)
|
||||||
|
}
|
||||||
|
|
||||||
|
func updateNSView(_: NSHostingView<Content>, context _: Context) {}
|
||||||
|
}
|
||||||
|
|
||||||
|
// this is the SwiftUI wrapper that makes it easy to insert the view
|
||||||
|
// into the existing SwiftUI view builders structure
|
||||||
|
struct VerticalScrollingFixWrapper<Content>: View where Content: View {
|
||||||
|
let content: () -> Content
|
||||||
|
|
||||||
|
init(@ViewBuilder content: @escaping () -> Content) {
|
||||||
|
self.content = content
|
||||||
|
}
|
||||||
|
|
||||||
|
var body: some View {
|
||||||
|
VerticalScrollingFixViewRepresentable(content: self.content())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
extension View {
|
||||||
|
@ViewBuilder func workaroundForVerticalScrollingBug() -> some View {
|
||||||
|
VerticalScrollingFixWrapper { self }
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user