-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Fix app crash caused by dynamic template switching in ListView #24808
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
Changes from all commits
f3a35c7
fad7b59
ccbd4a8
6b5e7f0
368e00a
cc79372
e5dc8c4
b6abc86
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 |
|---|---|---|
|
|
@@ -220,8 +220,9 @@ public static Color? AccentColor | |
|
|
||
| return null; | ||
| #elif ANDROID | ||
| if (Current?.Windows?.Count > 0) | ||
| return Current.Windows[0].MauiContext.Context?.GetAccentColor(); | ||
| var context = (Current?.Windows?.Count > 0 && Current.Windows[0].MauiContext is not null) ? Current.Windows[0].MauiContext.Context : Current?.FindMauiContext()?.Context; | ||
| if (context is not null) | ||
| return context?.GetAccentColor(); | ||
|
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. If the current Window MauiContext is null, we keep having the same null Color exception, right?
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. @jsuarezruiz , Thank you for the feedback. I’ve added a fallback to ensure context is retrieved effectively in all cases, even when the primary window context might not be accessible. Please review and let us know if any further changes are required. |
||
|
|
||
| return null; | ||
| #elif IOS | ||
|
|
||
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.
Did you validate if
Current?.FindMauiContext()?.Contextwill return an accent color? That's the application context on the Activity so I feel like it won't have the theme resources loaded into it.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.
@PureWeen
Thank you for the feedback. Here are the findings:
Windows.Count Unavailability: The condition where
Current?.Windows?.Countis not available and the fallback toFindMauiContext()?.Contextis triggered occurs specifically during Android device tests. Notably, this behavior is not observed when running individual device tests locally, suggesting it is tied to the test execution environment rather than regular application behavior.Accent Color Validation: When falling back to
FindMauiContext()?.Context, we are still able to retrieve an accent color, which is:[Color: Red=0.101960786, Green=0.4509804, Blue=0.9098039, Alpha=1]In contrast, when
Windows.Countis available and the primary path is used(Current.Windows[0].MauiContext.Context), the accent color retrieved is:[Color: Red=0.20392157, Green=0.59607846, Blue=0.85882354, Alpha=1]While there is a slight variation between these colors, both provide valid accent values for their respective scenarios.
Please let us know if there’s anything further you would like us to address.