-
Notifications
You must be signed in to change notification settings - Fork 17
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 custom image with context in Squoosh #1803
base: main
Are you sure you want to change the base?
Conversation
Snapshot diff report vs base branch: main |
Fixes #1785. Change the image with context customization to be a normal function instead of a composable function, and update its usages everywhere.
2df2d89
to
2520e63
Compare
@@ -184,7 +184,7 @@ internal fun stringTypeToCustomizationType(strType: String): CustomizationType { | |||
"@Composable (ComponentReplacementContext) -> Unit" -> | |||
CustomizationType.ComponentReplacement | |||
"com.android.designcompose.ListContent" -> CustomizationType.ListContent | |||
"@Composable (ImageReplacementContext) -> Bitmap?" -> CustomizationType.ImageWithContext | |||
"(ImageReplacementContext) -> Bitmap?" -> CustomizationType.ImageWithContext |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This must need a docs update, too, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly we never had a section for this customization, but I'll add one.
@@ -415,6 +420,10 @@ class MediaAdapter( | |||
|
|||
val currentlyPlaying = | |||
if (isMetadataSame(item, currentMetadata)) CurrentlyPlaying.On else CurrentlyPlaying.Off | |||
|
|||
// Unsubscribe this setter function whenever this leaves the composition | |||
DisposableEffect(setIcon) { onDispose { artRequestManager.unsubscribe(setIcon) } } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think ideally the effect would also perform the subscription (or the subscribe-unsubscribe thing would be encapsulated in a composable function) just so they can't get out of sync. I never remember if DisposableEffect
executes eagerly, or if it runs after MediaBrowseItem
finished...).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a bit messy due to the removal of @Composable
. I subscribe in the image replacement context function because that's when I know the size and color to make the image that I want. I don't have that info here. However to ensure we don't leak memory and have extra subscriptions when this composable leaves composition, I added this DisposableEffect
.
Fixes #1785. Change the image with context customization to be a normal function instead of a composable function, and update its usages everywhere.