Status Update
Comments
je...@google.com <je...@google.com> #2
Three things:
-
You're right, it's a bit brittle. I think the algorithm to derive a swipe path can be improved though if I split the path in the first
(duration - 100).ms
and the last100.ms
and relax the constraint that the last path needs to follow a function that goes through the start point. -
The error must be improved, it reports the values for a single axis only. That works fine for horizontal or vertical swipes, but won't make sense for diagonal swipes. Also the velocity is in the wrong unit (must be *1000)
-
Note that the velocity is in px/s and not in dp/s, so a 500.ms swipe across a 100.dp box will yield different velocities on different densities. If the swipe spans the same amount of pixels on each device, it should have the same behavior on each device though.
je...@google.com <je...@google.com> #4
I took a quick look at Modifier.swipeable()
and turns out that the velocityThreshold in that modifier is specified in dp as well. So I think you're right, we should follow that practice.
Coincidentally I'm currently working on an improved version of swipeWithVelocity
that loosens some of the restrictions and should make it a lot easier to generate valid swipes. I'll update that CL to include the move to dp, which will involve deprecating the px version.
je...@google.com <je...@google.com> #5
On second thought, even though it is technically possible, I'm not sure if it makes sense to have this particular bit of API accept dp while all other methods accept positions in px. What I can do, however, is let TouchInjectionScope
extend Density
, so you can always easily convert between px and dp. I think in combination with a clear explanation in the docs that will give the cleanest API. What do you think?
ap...@google.com <ap...@google.com> #6
Branch: androidx-main
commit ebf2e69f48e922f8abced7626b587bfc7745da01
Author: Jelle Fresen <jellefresen@google.com>
Date: Thu Sep 02 15:37:36 2021
Generate better swipes with velocity
This uses a new algorithm to derive a function for the path of the swipe
which results in much looser constraints. When a function can't be
created because the parameters are too strict, it will give suggestions
for adjustments in the parameters so that it becomes possible to
generate a swipe that ends with a given velocity.
Bug: 182477143
Test: ./gradlew compose:ui:ui-test:cC
Relnote: "Improved `TouchInjectionScope.swipeWithVelocity`. It now
accepts a wider range of input variables and will suggest changes to the
input if a swipe can't be created"
Change-Id: I40fbe57b6f28689bc2597b2e64ae0ef28158e593
M compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/injectionscope/touch/SwipeWithVelocityTest.kt
A compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/injectionscope/touch/VelocityPathFinderTest.kt
M compose/ui/ui-test/src/androidAndroidTest/kotlin/androidx/compose/ui/test/util/Truth.kt
M compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/TouchInjectionScope.kt
A compose/ui/ui-test/src/commonMain/kotlin/androidx/compose/ui/test/VelocityPathFinder.kt
Description
I'm using
swipeWithVelocity()
to test a scrolling layout, but I've found it difficult to find the magic combination of distance, duration and velocity to make it work.I consistently see the following error in tests:
While I can find some values which work for 1 device, it may not work for all devices, due to different sizes.