Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support overlaying content that zooms with the image. #54

Closed
evant opened this issue Nov 9, 2023 · 7 comments
Closed

Support overlaying content that zooms with the image. #54

evant opened this issue Nov 9, 2023 · 7 comments

Comments

@evant
Copy link

evant commented Nov 9, 2023

I'm trying to overlay the image with an aspect ratio box and I'd like it to follow any zooms & translates the user makes. Unfortunately the accessed zoomFraction includes the initial scale of the image to scale to fit so I don't know what zoom factor to apply to my overlay to match. I think either of the below that would be sufficient:

  1. A user-zoom factor that goes from 1 when all the way 'zoomed out' to whatever the max zoom is.
  2. An initial image scale factor I could subtract from zoomFraction to get the value to scale my ui with.
ui screenshot
@saket
Copy link
Owner

saket commented Nov 10, 2023

A user-zoom factor that goes from 1 when all the way 'zoomed out' to whatever the max zoom is.

ZoomableState maintains this state internally but only exposes the final zoom factor. Will it be sufficient to expose these two values in some fashion?

internal data class ContentZoom(
/**
* The initial scale needed to fit [Modifier.zoomable]'s content with
* respect to [ZoomableState.contentScale].
* */
val baseZoom: ScaleFactor,
/** Zoom applied by user using gestures. */
val userZoom: Float,
) {
fun finalZoom(): ScaleFactor {
return baseZoom * userZoom
}

I'd like it to follow any zooms & translates the user makes.

Do you have a video of an app that does this by any chance? I think I mostly understand your usecase but it'd be nice to confirm my assumptions by seeing something in action.

@evant
Copy link
Author

evant commented Nov 10, 2023

Ah yep that should! Reading from userZoom is exactly what I'm looking for.

I think you can see a good example of what I'm looking to do by editing a photo and google photos and using the markup tool to mark on it.

@saket
Copy link
Owner

saket commented Nov 10, 2023

Got it. I'll try coming up something. 👍

I think you can see a good example of what I'm looking to do by editing a photo and google photos and using the markup tool to mark on it.

This screen?

Screenshot_20231110-005843

Or were you referring to this cropping tool? It has an overlay but it does not follow the image. It stays centered.

screen-20231110-005723.3.mp4

@evant
Copy link
Author

evant commented Nov 10, 2023

The first one, note that when you draw on the image it tracks when you zoom/pan around.

@saket
Copy link
Owner

saket commented Nov 10, 2023

Gotcha!

@saket saket closed this as completed in bf16e41 Nov 13, 2023
@saket
Copy link
Owner

saket commented Nov 13, 2023

@evant Wanna try out 0.7.0-SNAPSHOT to see if you're able to use this?

interface ScaleMetadata {
/**
* The default scale needed to position the content within its layout bounds with
* respect to [ZoomableState.contentScale].
*/
val initialScale: ScaleFactor
/**
* Scale applied by the user using zoom gestures. The final scale of the content
* is calculated using [initialScale] x [userZoom].
*/
val userZoom: Float
}

@saket
Copy link
Owner

saket commented Nov 18, 2023

Released as part of 0.7.1.

slack-oss-bot added a commit to slackhq/circuit that referenced this issue Nov 20, 2023
…1002)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
|
[me.saket.telephoto:zoomable-image-coil](https://togithub.com/saket/telephoto)
| dependencies | minor | `0.6.2` -> `0.7.1` |

---

> [!WARNING]
> Some dependencies could not be looked up. Check the Dependency
Dashboard for more information.

---

### Release Notes

<details>
<summary>saket/telephoto
(me.saket.telephoto:zoomable-image-coil)</summary>

### [`v0.7.1`](https://togithub.com/saket/telephoto/releases/tag/0.7.1)

- Migrated all usages of `Modifier.composed()` to the new
[`Modifier.Node`
architecture](https://www.youtube.com/watch?v=BjGX2RftXsU). This should
help with performance, especially if your app uses multiple zoomable
content on the same screen.
-
[saket/telephoto#54:
`ZoomableContentTransformation` now includes additional information
about the content's scale:
[`ScaleMetadata`](https://togithub.com/saket/telephoto/blob/9bf0937333e240832d5ecaad57bf31825f0d76b7/zoomable/src/commonMain/kotlin/me/saket/telephoto/zoomable/ZoomableContentTransformation.kt#L78-L90),

Breaking changes

- Reduced the public API surface by replacing all `data` classes with
plain classes. These classes still implement `equals` and `hashCode`
(thanks to [poko](https://togithub.com/drewhamilton/poko/)), but they no
longer offer any `componentN()` or `copy()` functions.

Bug fixes

-
[saket/telephoto#53:
Prevent crashes when Compose UI reports the velocity of a gesture to be
infinite.
-
[saket/telephoto#41:
Fixed a crash where touch events received after the UI was restored
would cause a division by zero error if the layout wasn't measured yet.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Enabled.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Renovate
Bot](https://togithub.com/renovatebot/renovate).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy41OS44IiwidXBkYXRlZEluVmVyIjoiMzcuNTkuOCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->
ZacSweers pushed a commit to ZacSweers/CatchUp that referenced this issue Nov 20, 2023
[![Mend Renovate logo
banner](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
|
[me.saket.telephoto:zoomable-image-coil](https://togithub.com/saket/telephoto)
| `0.6.2` -> `0.7.1` |
[![age](https://developer.mend.io/api/mc/badges/age/maven/me.saket.telephoto:zoomable-image-coil/0.7.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/me.saket.telephoto:zoomable-image-coil/0.7.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/me.saket.telephoto:zoomable-image-coil/0.6.2/0.7.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/me.saket.telephoto:zoomable-image-coil/0.6.2/0.7.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
|
[me.saket.telephoto:zoomable-image](https://togithub.com/saket/telephoto)
| `0.6.2` -> `0.7.1` |
[![age](https://developer.mend.io/api/mc/badges/age/maven/me.saket.telephoto:zoomable-image/0.7.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/me.saket.telephoto:zoomable-image/0.7.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/me.saket.telephoto:zoomable-image/0.6.2/0.7.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/me.saket.telephoto:zoomable-image/0.6.2/0.7.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
| [me.saket.telephoto:zoomable](https://togithub.com/saket/telephoto) |
`0.6.2` -> `0.7.1` |
[![age](https://developer.mend.io/api/mc/badges/age/maven/me.saket.telephoto:zoomable/0.7.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/maven/me.saket.telephoto:zoomable/0.7.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/maven/me.saket.telephoto:zoomable/0.6.2/0.7.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/maven/me.saket.telephoto:zoomable/0.6.2/0.7.1?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>saket/telephoto
(me.saket.telephoto:zoomable-image-coil)</summary>

### [`v0.7.1`](https://togithub.com/saket/telephoto/releases/tag/0.7.1)

- Migrated all usages of `Modifier.composed()` to the new
[`Modifier.Node`
architecture](https://www.youtube.com/watch?v=BjGX2RftXsU). This should
help with performance, especially if your app uses multiple zoomable
content on the same screen.
-
[saket/telephoto#54:
`ZoomableContentTransformation` now includes additional information
about the content's scale:
[`ScaleMetadata`](https://togithub.com/saket/telephoto/blob/9bf0937333e240832d5ecaad57bf31825f0d76b7/zoomable/src/commonMain/kotlin/me/saket/telephoto/zoomable/ZoomableContentTransformation.kt#L78-L90),

Breaking changes

- Reduced the public API surface by replacing all `data` classes with
plain classes. These classes still implement `equals` and `hashCode`
(thanks to [poko](https://togithub.com/drewhamilton/poko/)), but they no
longer offer any `componentN()` or `copy()` functions.

Bug fixes

-
[saket/telephoto#53:
Prevent crashes when Compose UI reports the velocity of a gesture to be
infinite.
-
[saket/telephoto#41:
Fixed a crash where touch events received after the UI was restored
would cause a division by zero error if the layout wasn't measured yet.

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined),
Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these
updates again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/ZacSweers/CatchUp).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy41OS44IiwidXBkYXRlZEluVmVyIjoiMzcuNTkuOCIsInRhcmdldEJyYW5jaCI6Im1haW4ifQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants