saket / telephoto

Building blocks for designing media experiences in Compose UI
https://saket.github.io/telephoto/
Apache License 2.0
869 stars 28 forks source link

Please provide a way to change zoom and offset programatically #67

Open MitulVarmora opened 4 months ago

MitulVarmora commented 4 months ago

I am building an app in which I would like to save user's last zoom and offset and restore it when user revisit same image. As of now lib version 0.8.0: There is no way to change zoom and offset programatically.

Please provide a way to change zoom and offset programatically. This is important to my app because that way user will continue editing image from where they left.

saket commented 4 months ago

That's a very interesting usecase!

I would like to save user's last zoom and offset

What value do you plan to save? ZoomableState#zoomFraction or ZoomableState#contentTransformation?

MitulVarmora commented 4 months ago

What value do you plan to save? ZoomableState#zoomFraction or ZoomableState#contentTransformation?

ZoomableState#contentTransformation because thats what contains offset and scale both.

Tlaster commented 1 month ago

Another application involves utilizing PredictiveBackHandler to animate zoom scale and offset, such as scaling back to the original size when the user presses the back button with predictive back functionality.

saket commented 1 month ago

@Tlaster can you use ZoomableState#resetZoom() for that?

Tlaster commented 1 month ago

@Tlaster can you use ZoomableState#resetZoom() for that?

ZoomableState#resetZoom() will reset the zoom instantly, with PredictiveBackHandler we can get a progress that indicate how many "back" user has been dragged, so we can use the progress to set the scale and offset programmatically. For more about predictive back: https://developer.android.com/guide/navigation/custom-back/predictive-back-gesture

saket commented 1 month ago

@Tlaster interesting. Is there a reason you want to change the scale/offset on every frame during the back gesture? I haven't seen any apps do that.

Tlaster commented 1 month ago

@Tlaster interesting. Is there a reason you want to change the scale/offset on every frame during the back gesture? I haven't seen any apps do that.

Just a thought, like a gallery app when user scale up a photo then want to reset the scale by back gesture, it would be nice to have an animation during back gesture.

vokilam commented 2 weeks ago

In my application I use object detection model to detect objects on a photo. Then I want to zoom an image to a specific location with detected object.