I have a SwiftUI view I wrap in a NSHostingController in a mac app. This view consists of a vertical ScrollView with LazyVStack in it with various content (divided into Section). This content is long so the view is always scrollable.
I'm trying to implement better keyboard navigation, I can navigate buttons using Tab key, but I also want to support basic scrolling using up and down arrow keys.
This is something that works out-of-the-box in AppKit when e.g. using NSTextView in NSScrollView.
How do I enable scrolling up and down using arrow keys for SwiftUI.ScrollView on macOS?
I'm to looking for scrolling to an identifiable element but rather to scroll by x points up and down. Like the NSScrollView works.
Ideally, including modifier keys ALT+Up to page up and CMD+Up to scroll to the top.
struct ContentView: View {
var body: some View {
ScrollView(.vertical) {
LazyVStack {
Image(systemName: "globe")
.imageScale(.large)
.foregroundColor(.accentColor)
Text("Hello, world!")
Section("Lorem Ipsum") {
Text(Strings.longText)
}
}
.padding()
}
}
}