Skip to content

Commit e7152e2

Browse files
author
Trent Guillory
committed
Make cells tappable by removing scrollview
1 parent d086360 commit e7152e2

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

SnapToScrollDemo/Sources/ContentView.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ struct ContentView: View {
1919
.font(.largeTitle)
2020
.padding(16)
2121
.overlay(GeometryReaderOverlay(id: item.1))
22+
.onTapGesture {
23+
24+
print(item.0)
25+
}
2226
}
2327
}
2428
// HStackSnap(snapLocation: .center) {

Sources/HStackSnap.swift

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,16 @@ public struct HStackSnap<Content: View>: View {
2222

2323
GeometryReader { geometry in
2424

25-
ScrollView(.horizontal) {
26-
25+
HStack {
26+
2727
HStack(content: content)
28-
.frame(maxWidth: .infinity)
2928
.offset(x: scrollOffset, y: .zero)
3029
.animation(.easeOut(duration: 0.2))
30+
31+
Spacer()
3132
}
33+
// TODO: Make this less... janky.
34+
.frame(width: 10000)
3235
.onPreferenceChange(ContentPreferenceKey.self, perform: { preferences in
3336

3437
// Calculate all values once, on render. On-the-fly calculations with GeometryReader
@@ -85,7 +88,6 @@ public struct HStackSnap<Content: View>: View {
8588
}
8689

8790
})
88-
.disabled(true)
8991
.gesture(snapDrag)
9092
}
9193
.coordinateSpace(name: coordinateSpace)

0 commit comments

Comments
 (0)