Skip to content

Commit

Permalink
Fixed: Gesture precedence in watchOS (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
fredyshox authored May 14, 2020
1 parent 32bcb64 commit 22b178e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
12 changes: 6 additions & 6 deletions Examples/PageViewDemo WatchKit Extension/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ struct ContentView: View {
var body: some View {
// Horizontal
HPageView {
CustomButtonView()
CustomButtonView()
CustomButtonView()
CustomView()
CustomListView()
CustomView()
CustomView()
CustomView()
CustomView()
}.edgesIgnoringSafeArea(.init(arrayLiteral: .leading, .trailing, .bottom))
// Vertical
// VPageView {
// CustomView()
// CustomListView()
// CustomView()
// CustomButtonView()
// CustomButtonView()
// CustomButtonView()
// CustomView()
// CustomView()
// CustomView()
Expand Down
17 changes: 17 additions & 0 deletions Examples/PageViewDemo/Views.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,23 @@ extension View {
}
}

struct CustomButtonView: View {
var body: some View {
VStack {
Button(action: {
print("Button 1 tapped")
}, label: {
Text("Button 1")
})
Button(action: {
print("Button 2 tapped")
}, label: {
Text("Button 2")
})
}
}
}

struct CustomView: View {
var body: some View {
VStack {
Expand Down
16 changes: 8 additions & 8 deletions Sources/PageView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public struct HPageView<Pages>: View where Pages: View {
compositeView: HorizontalPageStack(pages: self.pages, geometry: geometry),
pageControlBuilder: pageControlBuilder)
.contentShape(Rectangle())
.gesture(DragGesture(minimumDistance: 8.0)
.onChanged({ self.onDragChanged($0, geometry: geometry) })
.onEnded({ self.onDragEnded($0, geometry: geometry) })
)
.highPriorityGesture(DragGesture(minimumDistance: 8.0)
.onChanged({ self.onDragChanged($0, geometry: geometry) })
.onEnded({ self.onDragEnded($0, geometry: geometry) })
)
}
}

Expand Down Expand Up @@ -89,10 +89,10 @@ public struct VPageView<Pages>: View where Pages: View {
compositeView: VerticalPageStack(pages: self.pages, geometry: geometry),
pageControlBuilder: pageControlBuilder)
.contentShape(Rectangle())
.gesture(DragGesture(minimumDistance: 8.0)
.onChanged({ self.onDragChanged($0, geometry: geometry) })
.onEnded({ self.onDragEnded($0, geometry: geometry) })
)
.highPriorityGesture(DragGesture(minimumDistance: 8.0)
.onChanged({ self.onDragChanged($0, geometry: geometry) })
.onEnded({ self.onDragEnded($0, geometry: geometry) })
)
}
}

Expand Down

0 comments on commit 22b178e

Please sign in to comment.