Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Conversation

@jimmgarrido
Copy link
Contributor

@jimmgarrido jimmgarrido commented Jun 2, 2017

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

  • Has tests (if omitted, state reason in description)
  • Rebased on top of master at time of PR
  • Changes adhere to coding standard
  • Consolidate commits as makes sense

TextView actionBarTitleTextView = null;

if(Forms.IsLollipopOrNewer)
int actionBarTitleId = _context.Resources.GetIdentifier("action_bar_title", "id", "android");
Copy link

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.

@jimmgarrido
Copy link
Contributor Author

@jassmith Re-did the fix so it maintains the original preference order 👍

}
else

if(actionBarTitleTextView == null)
Copy link

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)
Copy link

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.

Copy link
Member

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)
Copy link
Member

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

Toolbar toolbar = (Toolbar)((Activity)_context).FindViewById(actionbarId);

for( int i = 0; i < toolbar.ChildCount; i++ )
var toolbar = (ViewGroup)((Activity)_context).FindViewById(actionbarId);
Copy link
Member

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..

@rmarinho
Copy link
Member

this is failing @jimmgarrido

Copy link
Member

@rmarinho rmarinho left a 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 :)

@jimmgarrido
Copy link
Contributor Author

@rmarinho done 👍

@rmarinho rmarinho merged commit 330b515 into xamarin:master Jun 22, 2017
rmarinho pushed a commit that referenced this pull request Jun 22, 2017
…msApplicationActivity (#961)

* Fix possible crash on API 21+ at launch

* Do not use an explicit cast

* Do not use C# 7 pattern matching
assemhakmeh added a commit to assemhakmeh/Xamarin.Forms that referenced this pull request Jul 28, 2017
* 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)
@samhouts samhouts added this to the 2.3.5 milestone Jun 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants