I'm using this solution from this post for my custom pager tabview and I want to give each tab padding of 16. This is the code:
struct PagerView<Content: View>: View {
let pageCount: Int
@Binding var canDrag: Bool
@Binding var currentIndex: Int
let content: Content
init(pageCount: Int, canDrag: Binding<Bool>, currentIndex: Binding<Int>, @ViewBuilder content: () -> Content) {
...
}
@GestureState private var translation: CGFloat = 0
var body: some View {
GeometryReader { geometry in
HStack(spacing: 16) {
self.content.frame(width: geometry.size.width)
// .padding(16)
}
.padding(16)
.frame(width: geometry.size.width, alignment: .leading)
.offset(x: -CGFloat(self.currentIndex) * (geometry.size.width - 16))
.offset(x: self.translation)
.animation(.interactiveSpring(), value: currentIndex)
.animation(.interactiveSpring(), value: translation)
.gesture(!canDrag ? nil : // <- here
DragGesture()
.updating(self.$translation) { value, state, _ in
state = value.translation.width
}
.onEnded { value in
let offset = value.translation.width / geometry.size.width
let newIndex = (CGFloat(self.currentIndex) - offset).rounded()
self.currentIndex = min(max(Int(newIndex), 0), self.pageCount - 1)
}
)
}
}
}
However, no matter how much I've tried, I can not give it the right padding. Please check the image.
I've tried to give content padding, Hstack spacing, or frame but none of them work.
Any suggestion would be appreciated