Bug 57578 - CustomRenderer can not override AppCompat NavigationPageRenderer OnPopViewAsync & OnPushAsync methods
Summary: CustomRenderer can not override AppCompat NavigationPageRenderer OnPopViewAsy...
Status: RESOLVED FIXED
Alias: None
Product: Forms
Classification: Xamarin
Component: Android ()
Version: 2.3.5
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2017-06-17 19:34 UTC by Bernard Blanckaert
Modified: 2017-06-20 16:48 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Bernard Blanckaert 2017-06-17 19:34:43 UTC
Where a custom renderer inheriting from NavigationRenderer can override the OnPopToRootAsync, OnPopViewAsync and OnPushAsync methods, this is no longer the case in the AppCompat/NavigationPageRenderer.

REPLICATION CODE:
-----------------
The following shows the applicable internal code for both classes:

NavigationRenderer:
-------------------
protected virtual Task<bool> OnPopToRootAsync(Page page, bool animated)
{
	return SwitchContentAsync(page, animated, true);
}

protected virtual Task<bool> OnPopViewAsync(Page page, bool animated)
{
	Page pageToShow = ((INavigationPageController)Element).Peek(1);
	if (pageToShow == null)
		return Task.FromResult(false);

	return SwitchContentAsync(pageToShow, animated, true);
}

protected virtual Task<bool> OnPushAsync(Page view, bool animated)
{
	return SwitchContentAsync(view, animated);
}

Using this Renderer, a developer is able to override the methods in a custom renderer.


AppCompat/NavigationPageRenderer:
---------------------------------
Task<bool> OnPopToRootAsync(Page page, bool animated)
{
	return SwitchContentAsync(page, animated, true, true);
}

Task<bool> OnPopViewAsync(Page page, bool animated)
{
	Page pageToShow = ((INavigationPageController)Element).Peek(1);
	if (pageToShow == null)
		return Task.FromResult(false);

	return SwitchContentAsync(pageToShow, animated, true);
}

Task<bool> OnPushAsync(Page view, bool animated)
{
	return SwitchContentAsync(view, animated);
}

CONCLUSION:
-----------
Custom Renderers that used these methods are no longer able to do so under APPCOMPAT due to a lack of 'protected virtual' definition on each method.
Comment 1 adrianknight89 2017-06-17 21:49:03 UTC
See https://github.com/xamarin/Xamarin.Forms/pull/1001
Comment 2 Bernard Blanckaert 2017-06-20 04:44:50 UTC
ok, ready to test this when released using https://github.com/bbl-Laobu/CustomBackIconDemo. 
A Simple Custom Navigation Page Back Button Style Demo for Xamarin Forms which overrides the OnPopViewAsync and OnPushAsync to replace the back button with different styles (different icons, different formats...).
Comment 3 E.Z. Hart [MSFT] 2017-06-20 16:48:48 UTC
Should be fixed in 2.3.6-pre1