From: Pavel Yakovlev Date: Thu, 21 Mar 2019 10:03:50 +0000 (+0300) Subject: [shell] Fix show DisplayAlert (#5491) fixes #5504 X-Git-Tag: accepted/tizen/5.5/unified/20200421.150457~454^2~3 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d9f580e529db147a77165040dc3c1964f597129a;p=platform%2Fcore%2Fcsapi%2Fxsf.git [shell] Fix show DisplayAlert (#5491) fixes #5504 * [shell, ios, tizen] fixes show alert * - added helper extension - fix navigation model --- diff --git a/Xamarin.Forms.Controls/XamStore/Views/StorePages.cs b/Xamarin.Forms.Controls/XamStore/Views/StorePages.cs index f2c4697..1fa37f4 100644 --- a/Xamarin.Forms.Controls/XamStore/Views/StorePages.cs +++ b/Xamarin.Forms.Controls/XamStore/Views/StorePages.cs @@ -210,6 +210,12 @@ namespace Xamarin.Forms.Controls.XamStore }), 2, 14); + grid.Children.Add(MakeButton("Show Alert", + async () => { + var result = await DisplayAlert("Title", "Message", "Ok", "Cancel"); + Console.WriteLine($"Alert result: {result}"); + }), 0, 15); + Content = new ScrollView { Content = grid }; diff --git a/Xamarin.Forms.Core/Internals/PageExtensions.cs b/Xamarin.Forms.Core/Internals/PageExtensions.cs new file mode 100644 index 0000000..4ebf634 --- /dev/null +++ b/Xamarin.Forms.Core/Internals/PageExtensions.cs @@ -0,0 +1,17 @@ +using System.ComponentModel; + +namespace Xamarin.Forms.Internals +{ + [EditorBrowsable(EditorBrowsableState.Never)] + public static class PageExtensions + { + public static Page AncestorToRoot(this Page page) + { + Element parent = page; + while (!Application.IsApplicationOrNull(parent.RealParent)) + parent = parent.RealParent; + + return parent as Page; + } + } +} diff --git a/Xamarin.Forms.Core/NavigationModel.cs b/Xamarin.Forms.Core/NavigationModel.cs index e3c45b4..7decc31 100644 --- a/Xamarin.Forms.Core/NavigationModel.cs +++ b/Xamarin.Forms.Core/NavigationModel.cs @@ -61,7 +61,7 @@ namespace Xamarin.Forms.Internals public Page Pop(Page ancestralNav) { - ancestralNav = AncestorToRoot(ancestralNav); + ancestralNav = ancestralNav.AncestorToRoot(); foreach (List stack in _navTree) { if (stack.Contains(ancestralNav)) @@ -111,7 +111,7 @@ namespace Xamarin.Forms.Internals public void PopToRoot(Page ancestralNav) { - ancestralNav = AncestorToRoot(ancestralNav); + ancestralNav = ancestralNav.AncestorToRoot(); foreach (List stack in _navTree) { if (stack.Contains(ancestralNav)) @@ -136,7 +136,7 @@ namespace Xamarin.Forms.Internals return; } - ancestralNav = AncestorToRoot(ancestralNav); + ancestralNav = ancestralNav.AncestorToRoot(); foreach (List stack in _navTree) { @@ -168,13 +168,5 @@ namespace Xamarin.Forms.Internals return found; } - - Page AncestorToRoot(Page ancestor) - { - Page result = ancestor; - while (!Application.IsApplicationOrNull(result.RealParent)) - result = (Page)result.RealParent; - return result; - } } } \ No newline at end of file diff --git a/Xamarin.Forms.Platform.Tizen/Platform.cs b/Xamarin.Forms.Platform.Tizen/Platform.cs index 8fb22ca..aab48c7 100644 --- a/Xamarin.Forms.Platform.Tizen/Platform.cs +++ b/Xamarin.Forms.Platform.Tizen/Platform.cs @@ -557,10 +557,8 @@ namespace Xamarin.Forms.Platform.Tizen bool PageIsChildOfPlatform(Page page) { - while (!Application.IsApplicationOrNull(page.RealParent)) - page = (Page)page.RealParent; - - return Page == page || _navModel.Roots.Contains(page); + var parent = page.AncestorToRoot(); + return Page == parent || _navModel.Roots.Contains(parent); } SizeRequest IPlatform.GetNativeSize(VisualElement view, double widthConstraint, double heightConstraint) diff --git a/Xamarin.Forms.Platform.iOS/Platform.cs b/Xamarin.Forms.Platform.iOS/Platform.cs index 4723f5c..f5d952c 100644 --- a/Xamarin.Forms.Platform.iOS/Platform.cs +++ b/Xamarin.Forms.Platform.iOS/Platform.cs @@ -313,10 +313,8 @@ namespace Xamarin.Forms.Platform.iOS bool PageIsChildOfPlatform(Page page) { - while (!Application.IsApplicationOrNull(page.RealParent)) - page = (Page)page.RealParent; - - return Page == page || _modals.Contains(page); + var parent = page.AncestorToRoot(); + return Page == parent || _modals.Contains(parent); } // Creates a UIAlertAction which includes a call to hide the presenting UIWindow at the end