-
-
Notifications
You must be signed in to change notification settings - Fork 661
feat(Android, Stack v5): toolbar menu item icon and icon tint color #4105
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
base: main
Are you sure you want to change the base?
Changes from all commits
5236b8b
8d51156
1e20452
2dc95ae
0e2e7d7
d02b56e
1282876
fae26af
3f0e6a9
b427ccd
b0f24af
db6fb53
ec11c6b
8105b22
77082be
6d8b112
d25f86a
2e47a32
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| package com.swmansion.rnscreens.gamma.helpers | ||
|
|
||
| import android.content.Context | ||
| import android.graphics.drawable.Drawable | ||
|
|
||
| /** | ||
| * Outcome of [IconResolver.resolve]. | ||
| * | ||
| * [Unchanged] is reported when the requested source matches the one the resolver | ||
| * last emitted, so the caller should keep whatever icon it already has (no reload | ||
| * happens). [Resolved] carries a freshly resolved drawable, or `null` when the | ||
| * source resolves to no icon (i.e. the icon should be cleared). | ||
| */ | ||
| internal sealed interface IconResolution { | ||
| object Unchanged : IconResolution | ||
|
|
||
| data class Resolved( | ||
| val drawable: Drawable?, | ||
| ) : IconResolution | ||
| } | ||
|
|
||
| internal class IconResolver { | ||
| private var lastDrawableName: String? = null | ||
| private var lastImageUri: String? = null | ||
| private var lastEmittedDrawableName: String? = null | ||
| private var lastEmittedImageUri: String? = null | ||
|
|
||
| /** | ||
| * Resolves an icon from a drawable resource name or an image uri. | ||
| * | ||
| * The result is delivered to [onResult] synchronously for drawable resources and empty sources, | ||
| * and asynchronously for image uris. For image uris, the callback is only invoked if the | ||
| * resolved uri is still the latest requested source (stale requests are dropped). | ||
| */ | ||
|
kligarski marked this conversation as resolved.
|
||
| fun resolve( | ||
| context: Context, | ||
| drawableIconResourceName: String?, | ||
| imageIconUri: String?, | ||
| onResult: (IconResolution) -> Unit, | ||
| ) { | ||
| lastDrawableName = drawableIconResourceName | ||
| lastImageUri = imageIconUri | ||
| if (drawableIconResourceName == lastEmittedDrawableName && | ||
| imageIconUri == lastEmittedImageUri | ||
| ) { | ||
| onResult(IconResolution.Unchanged) | ||
| return | ||
| } | ||
| lastEmittedDrawableName = drawableIconResourceName | ||
| lastEmittedImageUri = imageIconUri | ||
| when { | ||
| drawableIconResourceName != null -> | ||
| onResult(IconResolution.Resolved(getSystemDrawableResource(context, drawableIconResourceName))) | ||
| imageIconUri != null -> | ||
| loadImage(context, imageIconUri) { drawable -> | ||
| if (imageIconUri == lastImageUri && lastDrawableName == null) { | ||
| onResult(IconResolution.Resolved(drawable)) | ||
| } | ||
| } | ||
| else -> onResult(IconResolution.Resolved(null)) | ||
|
Comment on lines
+43
to
+60
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this is an issue now. Let me know if you think we should add it now.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. at least we should note that down for further work, but this PR contains many changes, and as the initial version, I'm okay with merging it in current shape |
||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.