[shell] Fix show DisplayAlert (#5491) fixes #5504
authorPavel Yakovlev <v-payako@microsoft.com>
Thu, 21 Mar 2019 10:03:50 +0000 (13:03 +0300)
committerRui Marinho <me@ruimarinho.net>
Thu, 21 Mar 2019 10:03:50 +0000 (10:03 +0000)
* [shell, ios, tizen] fixes show alert

* - added helper extension
- fix navigation model

Xamarin.Forms.Controls/XamStore/Views/StorePages.cs
Xamarin.Forms.Core/Internals/PageExtensions.cs [new file with mode: 0644]
Xamarin.Forms.Core/NavigationModel.cs
Xamarin.Forms.Platform.Tizen/Platform.cs
Xamarin.Forms.Platform.iOS/Platform.cs

index f2c4697..1fa37f4 100644 (file)
@@ -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 (file)
index 0000000..4ebf634
--- /dev/null
@@ -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;
+               }
+       }
+}
index e3c45b4..7decc31 100644 (file)
@@ -61,7 +61,7 @@ namespace Xamarin.Forms.Internals
 
                public Page Pop(Page ancestralNav)
                {
-                       ancestralNav = AncestorToRoot(ancestralNav);
+                       ancestralNav = ancestralNav.AncestorToRoot();
                        foreach (List<Page> 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<Page> stack in _navTree)
                        {
                                if (stack.Contains(ancestralNav))
@@ -136,7 +136,7 @@ namespace Xamarin.Forms.Internals
                                return;
                        }
 
-                       ancestralNav = AncestorToRoot(ancestralNav);
+                       ancestralNav = ancestralNav.AncestorToRoot();
 
                        foreach (List<Page> 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
index 8fb22ca..aab48c7 100644 (file)
@@ -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)
index 4723f5c..f5d952c 100644 (file)
@@ -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