I am trying to recreate Discrete scrubber in SwiftUI with haptic feedback and snap to nearest integer step. I use ScrollView and LazyHStack as follows:
struct DiscreteScrubber: View {
@State var numLines:Int = 100
var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
LazyHStack {
ForEach(0..<numLines, id: \.self) { _ in
Rectangle().frame(width: 2, height: 10, alignment: .center)
.foregroundStyle(Color.red)
Spacer().frame(width: 10)
}
}
}
}
}
Problem: I need to add content inset of half the frame width of ScrollView so that the first line in the scrubber starts at the center of the view and so does the last line, and also generate haptic feedback as it scrolls. This was easy in UIKit but not obvious in SwiftUI.