summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohan Karlsson <johan.kson@gmail.com>2016-07-11 20:39:11 +0200
committerJason Smith <jason.smith@xamarin.com>2016-07-11 11:39:11 -0700
commit09ff9355326065902e610e4058f7e4ee3160cdaa (patch)
tree164307323b871bc41a4770517f02d9e4b43f8c76
parentf167024ef3a02c199c797b5313342dbe5d9a21de (diff)
downloadxamarin-forms-09ff9355326065902e610e4058f7e4ee3160cdaa.tar.gz
xamarin-forms-09ff9355326065902e610e4058f7e4ee3160cdaa.tar.bz2
xamarin-forms-09ff9355326065902e610e4058f7e4ee3160cdaa.zip
Added PoppedToRootEventArgs to track popped pages when calling PopToRoot (#229)
-rw-r--r--Xamarin.Forms.Core.UnitTests/NavigationUnitTest.cs25
-rw-r--r--Xamarin.Forms.Core/NavigationPage.cs6
-rw-r--r--Xamarin.Forms.Core/PoppedToRootEventArgs.cs18
-rw-r--r--Xamarin.Forms.Core/Xamarin.Forms.Core.csproj1
-rw-r--r--docs/Xamarin.Forms.Core/Xamarin.Forms/NavigationPage.xml4
-rw-r--r--docs/Xamarin.Forms.Core/Xamarin.Forms/PoppedToRootEventArgs.xml60
6 files changed, 111 insertions, 3 deletions
diff --git a/Xamarin.Forms.Core.UnitTests/NavigationUnitTest.cs b/Xamarin.Forms.Core.UnitTests/NavigationUnitTest.cs
index f43e7019..1cc3ac6a 100644
--- a/Xamarin.Forms.Core.UnitTests/NavigationUnitTest.cs
+++ b/Xamarin.Forms.Core.UnitTests/NavigationUnitTest.cs
@@ -188,6 +188,31 @@ namespace Xamarin.Forms.Core.UnitTests
}
[Test]
+ public async Task TestPopToRootEventArgs ()
+ {
+ var nav = new NavigationPage ();
+
+ List<Page> poppedChildren = null;
+ nav.PoppedToRoot += (sender, args) => poppedChildren = (args as PoppedToRootEventArgs).PoppedPages.ToList();
+
+ var root = new ContentPage {Content = new View ()};
+ var child1 = new ContentPage {Content = new View ()};
+ var child2 = new ContentPage {Content = new View ()};
+
+ await nav.PushAsync (root);
+ await nav.PushAsync (child1);
+ await nav.PushAsync (child2);
+
+ await nav.PopToRootAsync ();
+
+ Assert.IsNotNull (poppedChildren);
+ Assert.AreEqual (2, poppedChildren.Count);
+ Assert.Contains (child1, poppedChildren);
+ Assert.Contains (child2, poppedChildren);
+ Assert.AreEqual (root, nav.CurrentPage);
+ }
+
+ [Test]
public async Task TestStackCopy ()
{
var nav = new NavigationPage ();
diff --git a/Xamarin.Forms.Core/NavigationPage.cs b/Xamarin.Forms.Core/NavigationPage.cs
index 85c8ac89..d7fb5f3e 100644
--- a/Xamarin.Forms.Core/NavigationPage.cs
+++ b/Xamarin.Forms.Core/NavigationPage.cs
@@ -319,7 +319,9 @@ namespace Xamarin.Forms
var root = (Page)PageController.InternalChildren.First();
- PageController.InternalChildren.ToArray().Where(c => c != root).ForEach(c => PageController.InternalChildren.Remove(c));
+ var childrenToRemove = PageController.InternalChildren.ToArray().Where(c => c != root);
+ foreach (var child in childrenToRemove)
+ PageController.InternalChildren.Remove(child);
CurrentPage = root;
@@ -335,7 +337,7 @@ namespace Xamarin.Forms
}
if (PoppedToRoot != null)
- PoppedToRoot(this, new NavigationEventArgs(root));
+ PoppedToRoot(this, new PoppedToRootEventArgs(root, childrenToRemove.OfType<Page>().ToList()));
}
async Task PushAsyncInner(Page page, bool animated)
diff --git a/Xamarin.Forms.Core/PoppedToRootEventArgs.cs b/Xamarin.Forms.Core/PoppedToRootEventArgs.cs
new file mode 100644
index 00000000..ead4f1a7
--- /dev/null
+++ b/Xamarin.Forms.Core/PoppedToRootEventArgs.cs
@@ -0,0 +1,18 @@
+using System;
+using System.Collections.Generic;
+
+namespace Xamarin.Forms
+{
+ public class PoppedToRootEventArgs : NavigationEventArgs
+ {
+ public PoppedToRootEventArgs(Page page, IEnumerable<Page> poppedPages) : base(page)
+ {
+ if (poppedPages == null)
+ throw new ArgumentNullException(nameof(poppedPages));
+
+ PoppedPages = poppedPages;
+ }
+
+ public IEnumerable<Page> PoppedPages { get; private set; }
+ }
+}
diff --git a/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj b/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
index 3ba0c05b..d0cb293c 100644
--- a/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
+++ b/Xamarin.Forms.Core/Xamarin.Forms.Core.csproj
@@ -415,6 +415,7 @@
<Compile Include="IApplicationController.cs" />
<Compile Include="IAppIndexingProvider.cs" />
<Compile Include="ListStringTypeConverter.cs" />
+ <Compile Include="PoppedToRootEventArgs.cs" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\Portable\$(TargetFrameworkVersion)\Microsoft.Portable.CSharp.targets" />
<ItemGroup>
diff --git a/docs/Xamarin.Forms.Core/Xamarin.Forms/NavigationPage.xml b/docs/Xamarin.Forms.Core/Xamarin.Forms/NavigationPage.xml
index f58b6d8f..d31d850e 100644
--- a/docs/Xamarin.Forms.Core/Xamarin.Forms/NavigationPage.xml
+++ b/docs/Xamarin.Forms.Core/Xamarin.Forms/NavigationPage.xml
@@ -477,7 +477,9 @@
</ReturnValue>
<Docs>
<summary>Event that is raised when the last nonroot element is popped from this <see cref="T:Xamarin.Forms.NavigationPage" /> element.</summary>
- <remarks>To be added.</remarks>
+ <remarks>The <see cref="T:Xamarin.Forms.NavigationEventArgs" /> can be cast to <see cref="T:Xamarin.Forms.PoppedToRootEventArgs" /> for
+ access to additional properties. For example, the list of popped pages.
+ </remarks>
</Docs>
</Member>
<Member MemberName="PopToRootAsync">
diff --git a/docs/Xamarin.Forms.Core/Xamarin.Forms/PoppedToRootEventArgs.xml b/docs/Xamarin.Forms.Core/Xamarin.Forms/PoppedToRootEventArgs.xml
new file mode 100644
index 00000000..98b78287
--- /dev/null
+++ b/docs/Xamarin.Forms.Core/Xamarin.Forms/PoppedToRootEventArgs.xml
@@ -0,0 +1,60 @@
+<Type Name="PoppedToRootEventArgs" FullName="Xamarin.Forms.PoppedToRootEventArgs">
+ <TypeSignature Language="C#" Value="public class PoppedToRootEventArgs : Xamarin.Forms.NavigationEventArgs" />
+ <TypeSignature Language="ILAsm" Value=".class public auto ansi beforefieldinit PoppedToRootEventArgs extends Xamarin.Forms.NavigationEventArgs" />
+ <AssemblyInfo>
+ <AssemblyName>Xamarin.Forms.Core</AssemblyName>
+ <AssemblyVersion>2.0.0.0</AssemblyVersion>
+ </AssemblyInfo>
+ <Base>
+ <BaseTypeName>Xamarin.Forms.NavigationEventArgs</BaseTypeName>
+ </Base>
+ <Interfaces />
+ <Docs>
+ <summary>EventArgs for the NavigationPage's PoppedToRoot navigation event.</summary>
+ <remarks>
+ The <see cref="E:Xamarin.Forms.NavigationPage.PoppedToRoot" /> passes <see cref="T:Xamarin.Forms.NavigationEventArgs" /> as the
+ event argument. This class can be cast to <see cref="T:Xamarin.Forms.PoppedToRootEventArgs" /> to allow for access to the
+ PoppedPages collection that exposes the pages that was popped.
+ </remarks>
+ <altmember cref="E:Xamarin.Forms.NavigationPage.PoppedToRoot" />
+ </Docs>
+ <Members>
+ <Member MemberName=".ctor">
+ <MemberSignature Language="C#" Value="public PoppedToRootEventArgs (Xamarin.Forms.Page page);" />
+ <MemberSignature Language="ILAsm" Value=".method public hidebysig specialname rtspecialname instance void .ctor(class Xamarin.Forms.Page page) cil managed" />
+ <MemberType>Constructor</MemberType>
+ <AssemblyInfo>
+ <AssemblyVersion>2.0.0.0</AssemblyVersion>
+ </AssemblyInfo>
+ <Parameters>
+ <Parameter Name="page" Type="Xamarin.Forms.Page" />
+ </Parameters>
+ <Docs>
+ <param name="page">The page that is the new root page.</param>
+ <summary></summary>
+ <remarks></remarks>
+ </Docs>
+ </Member>
+ <Member MemberName="PoppedPages">
+ <MemberSignature Language="C#" Value="public System.Collections.Generic.IEnumerable&lt;Xamarin.Forms.Page&gt; PoppedPages { get; set; }" />
+ <MemberSignature Language="ILAsm" Value=".property instance class System.Collections.Generic.IEnumerable`1&lt;class Xamarin.Forms.Page&gt; PoppedPages" />
+ <MemberType>Property</MemberType>
+ <AssemblyInfo>
+ <AssemblyVersion>2.0.0.0</AssemblyVersion>
+ </AssemblyInfo>
+ <ReturnValue>
+ <ReturnType>System.Collections.Generic.IEnumerable&lt;Xamarin.Forms.Page&gt;</ReturnType>
+ </ReturnValue>
+ <Docs>
+ <summary>Gets a collection of pages that was removed from the navigation stack.</summary>
+ <value></value>
+ <remarks>
+ <para>For <see cref="E:Xamarin.Forms.NavigationPage.PoppedToRoot" /> this represents the pages
+ that were popped. The order of the pages represents the order of the stack that was popped. The first page in the
+ collection is the page that was closest to the root page.
+ </para>
+ </remarks>
+ </Docs>
+ </Member>
+ </Members>
+</Type>