-
-
Notifications
You must be signed in to change notification settings - Fork 654
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
Open
kligarski
wants to merge
18
commits into
main
Choose a base branch
from
@kligarski/stack-v5-android-toolbar-menu-icon
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
5236b8b
add icon props on JS layer, extract common fuction with Tabs
kligarski 8d51156
add SFT
kligarski 1e20452
fix import
kligarski 2dc95ae
add shared IconResolver, use it for back button icon
kligarski 0e2e7d7
parse initial toolbarMenuItems prop
kligarski d02b56e
handle icon via prop
kligarski 1282876
fix bug with disappearing icons
kligarski fae26af
scale toolbar menu item icon to 24 dp height
kligarski 3f0e6a9
extract tint list logic, update docs
kligarski b427ccd
handle view commands part 1
kligarski b0f24af
handle view commands part 2
kligarski db6fb53
format Android
kligarski ec11c6b
fix restoring colors
kligarski 8105b22
add scenario
kligarski 77082be
minor suggestions from CR, restore unrelated test
kligarski 6d8b112
reuse resolvers for both paths
kligarski d25f86a
fix type import
kligarski 2e47a32
fix doc
kligarski File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
63 changes: 63 additions & 0 deletions
63
android/src/main/java/com/swmansion/rnscreens/gamma/helpers/IconResolver.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. |
||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.