Merge "Stop the snapping animation when we are there." into androidx-main
diff --git a/wear/compose/compose-material/src/androidAndroidTest/kotlin/androidx/wear/compose/material/PickerTest.kt b/wear/compose/compose-material/src/androidAndroidTest/kotlin/androidx/wear/compose/material/PickerTest.kt
index cc02ec8..373391a 100644
--- a/wear/compose/compose-material/src/androidAndroidTest/kotlin/androidx/wear/compose/material/PickerTest.kt
+++ b/wear/compose/compose-material/src/androidAndroidTest/kotlin/androidx/wear/compose/material/PickerTest.kt
@@ -130,7 +130,7 @@
swipeWithVelocity(
start = Offset(centerX, bottom),
end = Offset(centerX, bottom - itemSizePx * 16), // 3 loops + 1 element
- endVelocity = 1f, // Ensure it's not a fling.
+ endVelocity = NOT_A_FLING_SPEED
)
}
@@ -159,7 +159,7 @@
swipeWithVelocity(
start = Offset(centerX, top),
end = Offset(centerX, top + itemSizePx * 16), // 3 loops + 1 element
- endVelocity = 1f, // Ensure it's not a fling.
+ endVelocity = NOT_A_FLING_SPEED
)
}
@@ -198,7 +198,7 @@
start = Offset(centerX, bottom),
end = Offset(centerX, bottom -
(itemSizePx + separationPx * separationSign) * itemsToScroll),
- endVelocity = 1f, // Ensure it's not a fling.
+ endVelocity = NOT_A_FLING_SPEED
)
}
@@ -350,7 +350,7 @@
swipeWithVelocity(
start = Offset(centerX, top),
end = Offset(centerX, top + itemSizePx / 2),
- endVelocity = 1f, // Ensure it's not a fling.
+ endVelocity = NOT_A_FLING_SPEED
)
}
@@ -359,7 +359,7 @@
swipeWithVelocity(
start = Offset(centerX, bottom),
end = Offset(centerX, bottom - itemSizePx / 2),
- endVelocity = 1f, // Ensure it's not a fling.
+ endVelocity = NOT_A_FLING_SPEED
)
}
@@ -368,7 +368,7 @@
swipeWithVelocity(
start = Offset(centerX, top),
end = Offset(centerX, top + itemSizePx / 2),
- endVelocity = 1f, // Ensure it's not a fling.
+ endVelocity = NOT_A_FLING_SPEED
)
}
@@ -377,7 +377,7 @@
swipeWithVelocity(
start = Offset(centerX, top),
end = Offset(centerX, top + 300),
- endVelocity = 10000f, // Ensure it IS a fling.
+ endVelocity = DO_FLING_SPEED
)
}
@@ -386,7 +386,7 @@
swipeWithVelocity(
start = Offset(centerX, bottom),
end = Offset(centerX, bottom - 300),
- endVelocity = 10000f, // Ensure it IS a fling.
+ endVelocity = DO_FLING_SPEED
)
}
@@ -429,6 +429,10 @@
.of(pickerHeightPx / 2f - itemSizePx / 2f)
}
+ // The threshold is 1f, and the specified velocity is not exactly achieved by swipeWithVelocity
+ private val NOT_A_FLING_SPEED = 0.9f
+ private val DO_FLING_SPEED = 10000f
+
/* TODO(199476914): Add tests for non-wraparound pickers to ensure they have the correct range
* of scroll.
*/
diff --git a/wear/compose/compose-material/src/commonMain/kotlin/androidx/wear/compose/material/ScalingLazyColumnSnapFlingBehavior.kt b/wear/compose/compose-material/src/commonMain/kotlin/androidx/wear/compose/material/ScalingLazyColumnSnapFlingBehavior.kt
index a401299..3328b22 100644
--- a/wear/compose/compose-material/src/commonMain/kotlin/androidx/wear/compose/material/ScalingLazyColumnSnapFlingBehavior.kt
+++ b/wear/compose/compose-material/src/commonMain/kotlin/androidx/wear/compose/material/ScalingLazyColumnSnapFlingBehavior.kt
@@ -111,6 +111,9 @@
// avoid rounding errors and stop if anything is unconsumed
if (abs(delta - consumed) > 0.5f) this.cancelAnimation()
+
+ // Stop when we are there.
+ if (abs(lastValue * velocityAdjustment - targetValue) < 1f) this.cancelAnimation()
}
}
}
\ No newline at end of file