-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Fix possible crash on API 21+ at launch when using Holo theme and FormsApplicationActivity #961
Conversation
| TextView actionBarTitleTextView = null; | ||
|
|
||
| if(Forms.IsLollipopOrNewer) | ||
| int actionBarTitleId = _context.Resources.GetIdentifier("action_bar_title", "id", "android"); |
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.
the only thing I don't like about this change is it changes the preference order of action_bar_title/toolbar usage to be inverse what it was before. It would be good to retain the preference ordering just in case there are any oddball scenarios out there.
a114f33 to
12ebbea
Compare
|
@jassmith Re-did the fix so it maintains the original preference order 👍 |
| } | ||
| else | ||
|
|
||
| if(actionBarTitleTextView == null) |
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.
Nit: if (
| { | ||
| actionBarTitleTextView = (TextView)toolbar.GetChildAt(i); | ||
| break; | ||
| if (toolbar.GetChildAt(i) is TextView) |
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.
GetChildAt(i) is being called twice. Maybe use c#7:
GetChildAt(i) is TextView textView and use that in the inner block.
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.
yeah let's fix this and do only 1 getChild
| { | ||
| actionBarTitleTextView = (TextView)toolbar.GetChildAt(i); | ||
| break; | ||
| if (toolbar.GetChildAt(i) is TextView) |
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.
yeah let's fix this and do only 1 getChild
f5d3af7 to
aba158e
Compare
| Toolbar toolbar = (Toolbar)((Activity)_context).FindViewById(actionbarId); | ||
|
|
||
| for( int i = 0; i < toolbar.ChildCount; i++ ) | ||
| var toolbar = (ViewGroup)((Activity)_context).FindViewById(actionbarId); |
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.
as ViewGroup instead of explicit cast here please..
|
this is failing @jimmgarrido |
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.
Build is failing, no c# 7 please :)
|
@rmarinho done 👍 |
…msApplicationActivity (#961) * Fix possible crash on API 21+ at launch * Do not use an explicit cast * Do not use C# 7 pattern matching
* 2.3.5: [UWP] Fixes for usage of XF with .net native toolchain (xamarin#1024) [UWP] Make sure to update HitTestVisible when IsEnable changes (xamarin#1015) [Android] Dispose check before setting properties on Button (xamarin#1013) Add missing member variable to FormsApplicationActivity Fix NRE when background color of button set in FormsApplicationActivity (xamarin#1010) Fix border on android buttons (xamarin#941) [iOS] ListView with UnevenRows and Cell Heights will no longer be slow to load (xamarin#994) Set the Id field for Android Views created by Forms xamarin#1004 Fix build Fix possible crash on API 21+ at launch when using Holo theme and FormsApplicationActivity (xamarin#961) [Android] Remove the ". " on empty labels (Accessibility) on Fastrenderers (xamarin#915) Remove debug outputs (xamarin#1008) Add check for instance of UITableView (xamarin#885) [XamlC] fix release builds of Xaml Unit Tests Dispose check on ButtonRenderer (xamarin#975) [previewer] make sure we do not crash even if the previewer doesn't s… (xamarin#946) [XamlC] fix build Remove VisualElement finalizer (xamarin#918) [XamlC] process symbols if DebugType is set (xamarin#925)
Description of Change
The changes made in #631 and #835 were causing an InvalidCastException when using the Holo theme on Lollipop or higher since that theme does not use a Toolbar.
This fixes it by first checking if there is the older ActionBarTextView on all Android versions and if not, then checking for a Toolbar. This also includes a null check for the Toolbar for situations were it is not present, e.g. using a NoActionBar theme.
Bugs Fixed
API Changes
None
Behavioral Changes
None
PR Checklist