diff options
author | Rui Marinho <me@ruimarinho.net> | 2016-05-27 12:17:38 +0100 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2016-05-27 12:17:38 +0100 |
commit | 2e75020b0ff028c70920074f32b996ead3a8f2bb (patch) | |
tree | e59fa77bd670dd8c5163ea6d060d6e1a6cb3ef14 | |
parent | 89aee2a3c2c592cf5a3c5d5f9a7415979f4b0748 (diff) | |
download | xamarin-forms-2e75020b0ff028c70920074f32b996ead3a8f2bb.tar.gz xamarin-forms-2e75020b0ff028c70920074f32b996ead3a8f2bb.tar.bz2 xamarin-forms-2e75020b0ff028c70920074f32b996ead3a8f2bb.zip |
[Android] UpdateToolbar when page is added before on non AppCompact (#195)
3 files changed, 122 insertions, 0 deletions
diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla40005.cs b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla40005.cs new file mode 100644 index 00000000..9a04bf55 --- /dev/null +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Bugzilla40005.cs @@ -0,0 +1,112 @@ +using System; +using System.Diagnostics; +using Xamarin.Forms.CustomAttributes; +using Xamarin.Forms.Internals; + +#if UITEST +using Xamarin.UITest; +using NUnit.Framework; +#endif + +namespace Xamarin.Forms.Controls +{ + [Preserve(AllMembers = true)] + [Issue(IssueTracker.Bugzilla, 40005, "Navigation Bar back button does not show when using InsertPageBefore")] + public class Bugzilla40005 : TestContentPage // or TestMasterDetailPage, etc ... + { + public Bugzilla40005() + { + Application.Current.MainPage = new NavigationPage(new Page1()); + } + + protected override void Init() + { + } + + public class Page1 : ContentPage + { + bool pageInserted; + + public Page1() + { + Button btn = new Button() { + Text = "Go to Page 2" + }; + btn.Clicked += async (sender, e) => { + await Navigation.PushAsync(new Page2()); + }; + + Content = new StackLayout { + VerticalOptions = LayoutOptions.Center, + Children = { + new Label { + HorizontalTextAlignment = TextAlignment.Center, + Text = "Page 1" + }, + btn + } + }; + } + + protected override void OnAppearing() + { + base.OnAppearing(); + if(!pageInserted) { + Navigation.InsertPageBefore(new InsertedPage(), this); + pageInserted = true; + } + } + + protected override bool OnBackButtonPressed() + { + Debug.WriteLine("Hardware BackButton Pressed on Page1"); + return base.OnBackButtonPressed(); + } + } + + + public class InsertedPage : ContentPage + { + public InsertedPage() + { + Content = new StackLayout { + VerticalOptions = LayoutOptions.Center, + Children = { + new Label { + HorizontalTextAlignment = TextAlignment.Center, + Text = "Inserted page" + } + } + }; + } + + protected override bool OnBackButtonPressed() + { + Debug.WriteLine("Hardware BackButton Pressed on InsertedPage"); + return base.OnBackButtonPressed(); + } + } + + public class Page2 : ContentPage + { + public Page2() + { + Content = new StackLayout { + VerticalOptions = LayoutOptions.Center, + Children = { + new Label { + HorizontalTextAlignment = TextAlignment.Center, + Text = "Page 2" + } + } + }; + } + + protected override bool OnBackButtonPressed() + { + Debug.WriteLine("Hardware BackButton Pressed on Page2"); + return base.OnBackButtonPressed(); + } + } + } +} diff --git a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems index fdeb7592..2a8db8fb 100644 --- a/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems +++ b/Xamarin.Forms.Controls.Issues/Xamarin.Forms.Controls.Issues.Shared/Xamarin.Forms.Controls.Issues.Shared.projitems @@ -98,6 +98,7 @@ <SubType>Code</SubType> </Compile> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla39702.cs" /> + <Compile Include="$(MSBuildThisFileDirectory)Bugzilla40005.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla40173.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla39821.cs" /> <Compile Include="$(MSBuildThisFileDirectory)Bugzilla40185.cs" /> diff --git a/Xamarin.Forms.Platform.Android/Renderers/NavigationRenderer.cs b/Xamarin.Forms.Platform.Android/Renderers/NavigationRenderer.cs index 395a0f82..dc9a8fe1 100644 --- a/Xamarin.Forms.Platform.Android/Renderers/NavigationRenderer.cs +++ b/Xamarin.Forms.Platform.Android/Renderers/NavigationRenderer.cs @@ -131,6 +131,15 @@ namespace Xamarin.Forms.Platform.Android void InsertPageBefore(Page page, Page before) { + + int index = Element.InternalChildren.IndexOf(before); + if (index == -1) + throw new InvalidOperationException("This should never happen, please file a bug"); + + Device.StartTimer(TimeSpan.FromMilliseconds(0), () => { + ((Platform)Element.Platform).UpdateNavigationTitleBar(); + return false; + }); } void OnInsertPageBeforeRequested(object sender, NavigationRequestedEventArgs e) |