I am trying to implement a composable which allows the user to drag and zoom an image. It seems that the most natural way to implement this is by using the pointerInput
or transformable
modifiers. However, both do not seem to support fling. If I try it with scrollable
instead, then fling works but one can only drag in one orientation at the same time (even if I add scrollable
with both orientations).
I think my use case it not completely uncommon (see e.g. MapView, which needs something similar), so I am a bit confused why Jetpack Compose does not support it properly. Am I missing something?
To track the velocity of your finger and initiate an animation when the drag is released, you can use a VelocityTracker. Here is an example code:
Finally, in the callback function, start the animation using the velocity information. Here is an example of how to use rememberSplineBasedDecay and AnimationState to create the animation: