From f1e8f7878cb673fcd79db4e350c6e29490d72fb4 Mon Sep 17 00:00:00 2001 From: Jaehyun Cho Date: Tue, 20 Jul 2021 17:10:16 +0900 Subject: [PATCH] [NUI] Add Popped event to Navigator Popped event is added to Navigator. Popped event passes Page handle popped by Navigator. By using Popped event, for example, user can dispose the popped page. --- .../Controls/Navigation/Navigator.cs | 34 ++++++++++++++++++++++ .../Tizen.NUI.Samples/Samples/NavigatorSample.cs | 26 +++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs b/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs index a736988..755313c 100755 --- a/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs +++ b/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs @@ -23,6 +23,19 @@ using Tizen.NUI.BaseComponents; namespace Tizen.NUI.Components { /// + /// PoppedEventArgs is a class to record popped event arguments which will be sent to user. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class PoppedEventArgs : EventArgs + { + /// + /// Page popped by Navigator. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public Page Page { get; internal set; } + } + + /// /// The Navigator is a class which navigates pages with stack methods such as Push and Pop. /// /// @@ -101,6 +114,13 @@ namespace Tizen.NUI.Components public event EventHandler TransitionFinished; /// + /// An event fired when Pop of a page has been finished. + /// Notice that Popped event handler should be removed when it is called not to call it duplicate. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public event EventHandler Popped; + + /// /// Returns the count of pages in Navigator. /// /// 9 @@ -200,6 +220,10 @@ namespace Tizen.NUI.Components if (navigationPages.Count == 1) { Remove(topPage); + + //Invoke Popped event + Popped?.Invoke(this, new PoppedEventArgs() { Page = topPage }); + return topPage; } var newTopPage = navigationPages[navigationPages.Count - 2]; @@ -219,6 +243,9 @@ namespace Tizen.NUI.Components //Invoke Page events newTopPage.InvokeAppeared(); topPage.InvokeDisappeared(); + + //Invoke Popped event + Popped?.Invoke(this, new PoppedEventArgs() { Page = topPage }); }; transitionFinished = false; @@ -319,6 +346,10 @@ namespace Tizen.NUI.Components if (navigationPages.Count == 1) { Remove(curTop); + + //Invoke Popped event + Popped?.Invoke(this, new PoppedEventArgs() { Page = curTop }); + return curTop; } @@ -344,6 +375,9 @@ namespace Tizen.NUI.Components //Invoke Page events curTop.InvokeDisappeared(); + + //Invoke Popped event + Popped?.Invoke(this, new PoppedEventArgs() { Page = curTop }); }; curAnimation.Play(); diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/NavigatorSample.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/NavigatorSample.cs index 83ad660..a8dfb52 100644 --- a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/NavigatorSample.cs +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/NavigatorSample.cs @@ -9,6 +9,23 @@ namespace Tizen.NUI.Samples private ContentPage firstPage, secondPage; private Button firstButton, secondButton; + private void Popped(object sender, PoppedEventArgs args) + { + global::System.Console.WriteLine("Page is popped!"); + args.page.Dispose(); + + if (args.page == firstPage) + { + firstPage = null; + } + else + { + secondPage = null; + } + + navigator.Popped -= Popped; + } + public void Activate() { Window window = NUIApplication.GetDefaultWindow(); @@ -38,6 +55,11 @@ namespace Tizen.NUI.Samples firstPage = new ContentPage() { + AppBar = new AppBar() + { + AutoNavigationContent = false, + Title = "FirstPage", + }, Content = firstButton, }; firstPage.Appearing += (object sender, PageAppearingEventArgs e) => @@ -67,6 +89,10 @@ namespace Tizen.NUI.Samples secondPage = new ContentPage() { + AppBar = new AppBar() + { + Title = "SecondPage", + }, Content = secondButton, }; secondPage.Appearing += (object sender, PageAppearingEventArgs e) => -- 2.7.4