Skip to content

Commit 22b178e

Browse files
authored
Fixed: Gesture precedence in watchOS (#3)
1 parent 32bcb64 commit 22b178e

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

Examples/PageViewDemo WatchKit Extension/ContentView.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,18 @@ struct ContentView: View {
1313
var body: some View {
1414
// Horizontal
1515
HPageView {
16+
CustomButtonView()
17+
CustomButtonView()
18+
CustomButtonView()
1619
CustomView()
1720
CustomListView()
1821
CustomView()
19-
CustomView()
20-
CustomView()
21-
CustomView()
2222
}.edgesIgnoringSafeArea(.init(arrayLiteral: .leading, .trailing, .bottom))
2323
// Vertical
2424
// VPageView {
25-
// CustomView()
26-
// CustomListView()
27-
// CustomView()
25+
// CustomButtonView()
26+
// CustomButtonView()
27+
// CustomButtonView()
2828
// CustomView()
2929
// CustomView()
3030
// CustomView()

Examples/PageViewDemo/Views.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,23 @@ extension View {
1414
}
1515
}
1616

17+
struct CustomButtonView: View {
18+
var body: some View {
19+
VStack {
20+
Button(action: {
21+
print("Button 1 tapped")
22+
}, label: {
23+
Text("Button 1")
24+
})
25+
Button(action: {
26+
print("Button 2 tapped")
27+
}, label: {
28+
Text("Button 2")
29+
})
30+
}
31+
}
32+
}
33+
1734
struct CustomView: View {
1835
var body: some View {
1936
VStack {

Sources/PageView.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ public struct HPageView<Pages>: View where Pages: View {
4040
compositeView: HorizontalPageStack(pages: self.pages, geometry: geometry),
4141
pageControlBuilder: pageControlBuilder)
4242
.contentShape(Rectangle())
43-
.gesture(DragGesture(minimumDistance: 8.0)
44-
.onChanged({ self.onDragChanged($0, geometry: geometry) })
45-
.onEnded({ self.onDragEnded($0, geometry: geometry) })
46-
)
43+
.highPriorityGesture(DragGesture(minimumDistance: 8.0)
44+
.onChanged({ self.onDragChanged($0, geometry: geometry) })
45+
.onEnded({ self.onDragEnded($0, geometry: geometry) })
46+
)
4747
}
4848
}
4949

@@ -89,10 +89,10 @@ public struct VPageView<Pages>: View where Pages: View {
8989
compositeView: VerticalPageStack(pages: self.pages, geometry: geometry),
9090
pageControlBuilder: pageControlBuilder)
9191
.contentShape(Rectangle())
92-
.gesture(DragGesture(minimumDistance: 8.0)
93-
.onChanged({ self.onDragChanged($0, geometry: geometry) })
94-
.onEnded({ self.onDragEnded($0, geometry: geometry) })
95-
)
92+
.highPriorityGesture(DragGesture(minimumDistance: 8.0)
93+
.onChanged({ self.onDragChanged($0, geometry: geometry) })
94+
.onEnded({ self.onDragEnded($0, geometry: geometry) })
95+
)
9696
}
9797
}
9898

0 commit comments

Comments
 (0)