saket / telephoto

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

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

Closed MitulVarmora closed 4 months ago

MitulVarmora commented 9 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 9 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 9 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 6 months 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 6 months ago

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

Tlaster commented 6 months 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 6 months 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 6 months 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 5 months 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.

saket commented 4 months ago

The next release will introduce new APIs for controlling an image's pan and zoom:

https://github.com/saket/telephoto/blob/f0201b80d627ba1950ee460db14c132b3406e553/zoomable/src/commonMain/kotlin/me/saket/telephoto/zoomable/ZoomableState.kt#L146-L190