Skip to content

Commit 7561f64

Browse files
add option to change nested scroll connection
1 parent 9b6085e commit 7561f64

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

Tutorial1-1Basics/src/main/java/com/smarttoolfactory/tutorial1_1basics/chapter5_gesture/Tutorital5_16DragHorizontalPager.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,10 +293,17 @@ fun DragPagerTest() {
293293
5
294294
}
295295

296+
var consumeNestedScroll by remember {
297+
mutableStateOf(false)
298+
}
299+
296300
val nestedScrollConnection = remember {
297301
object : NestedScrollConnection {
298302
override fun onPreScroll(available: Offset, source: NestedScrollSource): Offset {
299303
println("onPreScroll() available: $available")
304+
if (consumeNestedScroll) {
305+
return available
306+
}
300307
return super.onPreScroll(available, source)
301308
}
302309
}
@@ -371,8 +378,7 @@ fun DragPagerTest() {
371378
text = "onDragStart..."
372379
},
373380
onDrag = { change, dragAmount ->
374-
// text = "onDrag...$dragAmount"
375-
println("onDrag $dragAmount")
381+
text = "onDrag...$dragAmount"
376382
change.consume()
377383
},
378384
onDragCancel = {
@@ -412,6 +418,14 @@ fun DragPagerTest() {
412418

413419
Spacer(Modifier.height(16.dp))
414420

421+
CheckBoxWithTextRippleFullRow(
422+
label = "consumeNestedScroll",
423+
state = consumeNestedScroll,
424+
onStateChange = {
425+
consumeNestedScroll = it
426+
}
427+
)
428+
415429
CheckBoxWithTextRippleFullRow(
416430
label = "shouldAwaitPointerEventScope",
417431
state = shouldAwaitPointerEventScope,

Tutorial1-1Basics/src/main/java/com/smarttoolfactory/tutorial1_1basics/chapter5_gesture/gesture/DetectDragGestures.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ internal suspend fun PointerInputScope.detectDragGesture(
5757
drag = awaitTouchSlopOrCancellation(
5858
pointerId = down.id,
5959
requireUnconsumed = requireUnconsumed,
60+
pass = pass
6061
) { change, over ->
6162
change.consume()
6263
overSlop = over

0 commit comments

Comments
 (0)