-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Android] Fix NavigationPage dispose crash when it parents a MasterDetailPage #577
Conversation
@@ -173,13 +152,52 @@ protected override void Dispose(bool disposing) | |||
if (_drawerLayout != null && _drawerListener != null) | |||
{ | |||
_drawerLayout.RemoveDrawerListener(_drawerListener); |
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 issue is _drawerLayout
is disposed because of the above foreach
loop. That block of code should be executed at the end so that we can remove drawer listeners safely before disposing the MDP.
{ | ||
_backgroundDrawable.Dispose(); | ||
_backgroundDrawable = 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.
Dispose _backgroundDrawable
in case it's not null.
@@ -173,13 +152,52 @@ protected override void Dispose(bool disposing) | |||
if (_drawerLayout != null && _drawerListener != null) | |||
{ | |||
_drawerLayout.RemoveDrawerListener(_drawerListener); | |||
} | |||
|
|||
if (_drawerListener != 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.
This can be moved to its own if block since the previous _drawerLayout != null && _drawerListener != null
may evaluate to false.
@@ -499,7 +514,7 @@ void RegisterToolbar() | |||
if (renderer == null) | |||
return; | |||
|
|||
_drawerLayout = (DrawerLayout)renderer; | |||
_drawerLayout = renderer; |
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.
renderer
is always a DrawerLayout
.
navController.PopToRootRequested -= OnPoppedToRoot; | ||
navController.InsertPageBeforeRequested -= OnInsertPageBeforeRequested; | ||
navController.RemovePageRequested -= OnRemovePageRequested; | ||
} |
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.
Execute this logic at the end.
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.
Looks good, just needs some minor changes.
}; | ||
} | ||
} | ||
} |
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.
This whole test class can probably just be dropped. It doesn't test the issue in 45702, and I'm not sure there even is a way to test that from inside ControlGallery.
|
||
Current = null; | ||
|
||
// dispose child renderers at the end to avoid compliations with MasterDetailPage being nested under NavigationPage |
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.
Let's update this comment to something more descriptive, like
"We dispose the child renderers after cleaning up everything related to Drawer Layout in case one of the children is a Master Detail Page (which may dispose of the Drawer Layout)"
Done. |
@adrianknight89 Sorry for the trouble, but could you rebase this? I think the |
Done. |
@adrianknight89 Thanks! |
Only failing test is the broken CellsGalleryImageUrlCellList test on iOS 10; not an issue with these changes. |
…tailPage (xamarin#577) * fix navigation page dispose crash * changes after review
* Add pressed and released events to Button * Update ButtonRenderer.cs * Apply safely casting to android button renderer * Use safety casting for Android buttin renderer * [Windows] Fix modal pages being laid out below soft buttons (#395) * Add sample HanselForms and TwitterDemo to ControlGallery (#651) * [Controls] Add Hanselforms sample * Remove extra twitter sample * [Controls]Add TwitterDemo sample * [Controls] Fix build * Slider should show user-set value on initial load (#378) * [UWP] Use toolbar foreground color on primary items (#640) * Avoid duplicating code in OmPlatform (#591) * [iOS] Entry should not pass a newline to the next responder (#397) * UITextField should not return so that the next field does not get passed a newline * Added code sample * [XamlC] import members on x:Static and factories (#642) * [Xaml] support short Properties for PropertyCondition (#645) * Xamlc compile data triggers (#648) * [Xaml] DataTrigger and PropertyCondition no longer use a ServiceProvider * [XamlC] avoid generating ServiceProvider for unused ProvideValue * fix tests * Fix comment typo * [UWP] Fix TextBox style for foreground focus color (#618) * Adding image to use for CellsGalleryImageUrlCellList UI test * Update ImageCellListPage to use an image we control; Update CellsGalleryImageUrlCellList test to wait longer than 1s for images to load if necessary * fix nre when changing content in datepickerselected (#494) * Make CellsGalleryImageUrlCellList test finish early if possible * [iOS] Change keyboard type while keyboard is visible (#443) * Change keyboard while changing text * add sample code * [Android] Fix NavigationPage dispose crash when it parents a MasterDetailPage (#577) * fix navigation page dispose crash * changes after review * [XamlC] detect duplicate x:Name at compile time (#655) * [XamlC] detect duplicate x:Name at compile time * invoking methods with the right arguments produces better results * Make UWP toolbar display rules consistent with other platforms (#638) * Allow subscriber to be collected if MessagingCenter is the only reference to it (#617) * Repro * Make messaging center callbacks weak references * Preserve attribute * Fix test method name * Watch for collection of actual delegate target instead of wrapper delegate * Preserve the original platform instance when changing main page * Better tests for lambda situations * Update tests, make callback target a weakreference if it's the subscriber * Ensure old Platform MessagingCenter subs are gone before creating new Platform * [iOS] Prevent multiple ListView cells from being swiped simultaneously (#578) * disable multiple cell swipe * add sample code * refactored * convert to weakreference * remove null setting * change weakreference setting place * remove if * revert isopen changes * add instructions * [WinRT/UWP] Apply BackgroundColor to Stepper buttons (#581) * [WinRT/UWP] Apply BackgroundColor to Stepper buttons * Add explanatory text; use nameof * Move explanatory text to a label * Return group instead of internal class (#461) * [iOS/Android] Move Map camera to correct region on layout change (#548) * Move to region on layout change * remove visibility check * [iOS] Platform specifics for controlling Picker SelectedIndex change behavior (#540) * picker selected index could change when picker view is dismissed * use enum * [iOS] Ignore intermittent failing test on XTC (#666) * [UITest] Update to UITest 2.0.5 (#665) * Rebase the current branch onto upstream latest
Description of Change
When a
MasterDetailPage
is nested underNavigationPage
, hitting the back button triggers disposal ofNavigationPage
and results in a hard-crash.Bugs Fixed
PR Checklist