From 046950c085cc1ed670d441a9ea83724232874cec Mon Sep 17 00:00:00 2001 From: Jaehyun Cho Date: Tue, 22 Dec 2020 21:31:09 +0900 Subject: [PATCH] [NUI] Override Dispose() in Navigator Pages pushed into Navigator are disposed if Navigator is disposed. To override Dispose() in Navigator, two dictionaries are required to remove disposed navigator from dictionary. TODO: Needs to consider how to remove disposed window from dictionary. --- .../Controls/Navigation/Navigator.cs | 36 ++++++++++++++++++++++ .../Tizen.NUI.Samples/Samples/NavigatorSample.cs | 14 ++------- 2 files changed, 39 insertions(+), 11 deletions(-) diff --git a/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs b/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs index acbcb1c..10f371c 100755 --- a/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs +++ b/src/Tizen.NUI.Components/Controls/Navigation/Navigator.cs @@ -37,7 +37,10 @@ namespace Tizen.NUI.Components //This will be replaced with view transition class instance. private Animation _newAnimation = null; + //TODO: Needs to consider how to remove disposed window from dictionary. + //Two dictionaries are required to remove disposed navigator from dictionary. private static Dictionary windowNavigator = new Dictionary(); + private static Dictionary navigatorWindow = new Dictionary(); /// /// Creates a new instance of a Navigator. @@ -310,6 +313,38 @@ namespace Tizen.NUI.Components } /// + /// Disposes Navigator and all children on it. + /// + /// Dispose type. + [EditorBrowsable(EditorBrowsableState.Never)] + protected override void Dispose(DisposeTypes type) + { + if (disposed) + { + return; + } + + if (type == DisposeTypes.Explicit) + { + foreach (Page page in NavigationPages) + { + Utility.Dispose(page); + } + NavigationPages.Clear(); + + Window window; + + if (navigatorWindow.TryGetValue(this, out window) == true) + { + navigatorWindow.Remove(this); + windowNavigator.Remove(window); + } + } + + base.Dispose(type); + } + + /// /// Returns the default navigator of the given window. /// /// The default navigator of the given window. @@ -332,6 +367,7 @@ namespace Tizen.NUI.Components defaultNavigator.HeightResizePolicy = ResizePolicyType.FillToParent; window.Add(defaultNavigator); windowNavigator.Add(window, defaultNavigator); + navigatorWindow.Add(defaultNavigator, window); return defaultNavigator; } 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 74ece7b..6eea4be 100755 --- a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/NavigatorSample.cs +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/NavigatorSample.cs @@ -81,20 +81,12 @@ namespace Tizen.NUI.Samples { NUIApplication.GetDefaultWindow().Remove(navigator); - firstButton.Dispose(); + navigator.Dispose(); + navigator = null; firstButton = null; - - secondButton.Dispose(); - secondButton = null; - - firstPage.Dispose(); firstPage = null; - - secondPage.Dispose(); + secondButton = null; secondPage = null; - - navigator.Dispose(); - navigator = null; } } } -- 2.7.4