2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
19 using System.Collections.Generic;
20 using System.ComponentModel;
21 using Tizen.NUI.BaseComponents;
22 using Tizen.NUI.Binding;
24 namespace Tizen.NUI.Components
27 /// PoppedEventArgs is a class to record <see cref="Navigator.Popped"/> event arguments which will be sent to user.
29 /// <since_tizen> 9 </since_tizen>
30 public class PoppedEventArgs : EventArgs
33 /// Page popped by Navigator.
35 /// <since_tizen> 9 </since_tizen>
36 public Page Page { get; internal set; }
40 /// The Navigator is a class which navigates pages with stack methods such as Push and Pop.
43 /// With Transition class, Navigator supports smooth transition of View pair between two Pages
44 /// by using <see cref="PushWithTransition(Page)"/> and <see cref="PopWithTransition()"/> methods.
45 /// If current top Page and next top Page have <see cref="View"/>s those have same TransitionTag,
46 /// Navigator creates smooth transition motion for them.
47 /// Navigator.Transition property can be used to set properties of the Transition such as TimePeriod and AlphaFunction.
48 /// When all transitions are finished, Navigator calls a callback methods those connected on the "TransitionFinished" event.
52 /// Navigator navigator = new Navigator()
54 /// TimePeriod = new TimePeriod(500),
55 /// AlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.EaseInOutSine)
58 /// View view = new View()
60 /// TransitionOptions = new TransitionOptions()
62 /// /* Set properties for the transition of this View */
66 /// ContentPage newPage = new ContentPage()
71 /// Navigator.PushWithTransition(newPage);
74 /// <since_tizen> 9 </since_tizen>
75 public class Navigator : Control
78 /// TransitionProperty
80 [EditorBrowsable(EditorBrowsableState.Never)]
81 public static readonly BindableProperty TransitionProperty = BindableProperty.Create(nameof(Transition), typeof(Transition), typeof(Navigator), null, propertyChanged: (bindable, oldValue, newValue) =>
83 var instance = (Navigator)bindable;
86 instance.InternalTransition = newValue as Transition;
89 defaultValueCreator: (bindable) =>
91 var instance = (Navigator)bindable;
92 return instance.InternalTransition;
96 /// EnableBackNavigationProperty
98 [EditorBrowsable(EditorBrowsableState.Never)]
99 public static readonly BindableProperty EnableBackNavigationProperty = BindableProperty.Create(nameof(EnableBackNavigation), typeof(bool), typeof(Navigator), default(bool), propertyChanged: (bindable, oldValue, newValue) =>
101 var instance = (Navigator)bindable;
102 if (newValue != null)
104 instance.InternalEnableBackNavigation = (bool)newValue;
107 defaultValueCreator: (bindable) =>
109 var instance = (Navigator)bindable;
110 return instance.InternalEnableBackNavigation;
113 private const int DefaultTransitionDuration = 300;
115 //This will be replaced with view transition class instance.
116 private Animation curAnimation = null;
118 //This will be replaced with view transition class instance.
119 private Animation newAnimation = null;
121 private TransitionSet transitionSet = null;
123 private Transition transition = new Transition()
125 TimePeriod = new TimePeriod(DefaultTransitionDuration),
126 AlphaFunction = new AlphaFunction(AlphaFunction.BuiltinFunctions.Default),
129 private bool transitionFinished = true;
131 //TODO: Needs to consider how to remove disposed window from dictionary.
132 //Two dictionaries are required to remove disposed navigator from dictionary.
133 private static Dictionary<Window, Navigator> windowNavigator = new Dictionary<Window, Navigator>();
134 private static Dictionary<Navigator, Window> navigatorWindow = new Dictionary<Navigator, Window>();
136 private List<Page> navigationPages = new List<Page>();
138 private bool enableBackNavigation = true;
140 private Window parentWindow;
142 private void OnWindowKeyEvent(object sender, Window.KeyEventArgs e)
144 if (!EnableBackNavigation)
149 if ((e.Key.State == Key.StateType.Up) && ((e.Key.KeyPressedName == "Escape") || (e.Key.KeyPressedName == "BackSpace") || (e.Key.KeyPressedName == "XF86Back")))
151 OnBackNavigation(new BackNavigationEventArgs());
155 private void OnAddedToWindow(object sender, EventArgs e)
157 parentWindow = Window.Get(this);
158 parentWindow.KeyEvent += OnWindowKeyEvent;
161 private void OnRemovedFromWindow(object sender, EventArgs e)
163 parentWindow.KeyEvent -= OnWindowKeyEvent;
167 private void Initialize()
169 Layout = new AbsoluteLayout();
171 AddedToWindow += OnAddedToWindow;
172 RemovedFromWindow += OnRemovedFromWindow;
176 /// Creates a new instance of a Navigator.
178 /// <since_tizen> 9 </since_tizen>
179 public Navigator() : base()
185 /// Creates a new instance of a Navigator with style.
187 /// <param name="style">A style applied to the newly created Navigator.</param>
188 [EditorBrowsable(EditorBrowsableState.Never)]
189 public Navigator(ControlStyle style) : base(style)
195 [EditorBrowsable(EditorBrowsableState.Never)]
196 public override void OnInitialize()
200 AccessibilityRole = Role.PageTabList;
204 /// An event fired when Transition has been finished.
206 /// <since_tizen> 9 </since_tizen>
207 public event EventHandler<EventArgs> TransitionFinished;
210 /// An event fired when Pop of a page has been finished.
213 /// When you free resources in the Popped event handler, please make sure if the popped page is the page you find.
215 /// <since_tizen> 9 </since_tizen>
216 public event EventHandler<PoppedEventArgs> Popped;
219 /// Returns the count of pages in Navigator.
221 /// <since_tizen> 9 </since_tizen>
222 public int PageCount => navigationPages.Count;
225 /// Transition properties for the transition of View pair having same transition tag.
227 /// <since_tizen> 9 </since_tizen>
228 public Transition Transition
232 return GetValue(TransitionProperty) as Transition;
236 SetValue(TransitionProperty, value);
237 NotifyPropertyChanged();
240 private Transition InternalTransition
253 /// Pushes a page to Navigator.
254 /// If the page is already in Navigator, then it is not pushed.
256 /// <param name="page">The page to push to Navigator.</param>
257 /// <exception cref="ArgumentNullException">Thrown when the argument page is null.</exception>
258 /// <since_tizen> 9 </since_tizen>
259 public void PushWithTransition(Page page)
261 if (!transitionFinished)
263 Tizen.Log.Error("NUI", "Transition is still not finished.\n");
269 throw new ArgumentNullException(nameof(page), "page should not be null.");
272 //Duplicate page is not pushed.
273 if (navigationPages.Contains(page)) return;
275 var topPage = Peek();
283 navigationPages.Add(page);
285 page.Navigator = this;
288 page.InvokeAppearing();
289 topPage.InvokeDisappearing();
290 topPage.SaveKeyFocus();
292 transitionSet = CreateTransitions(topPage, page, true);
293 transitionSet.Finished += (object sender, EventArgs e) =>
295 if (page is DialogPage == false)
297 topPage.SetVisible(false);
300 // Need to update Content of the new page
301 ShowContentOfPage(page);
304 page.InvokeAppeared();
305 page.RestoreKeyFocus();
307 topPage.InvokeDisappeared();
308 NotifyAccessibilityStatesChangeOfPages(topPage, page);
310 transitionFinished = false;
314 /// Pops the top page from Navigator.
316 /// <returns>The popped page.</returns>
317 /// <exception cref="InvalidOperationException">Thrown when there is no page in Navigator.</exception>
318 /// <since_tizen> 9 </since_tizen>
319 public Page PopWithTransition()
321 if (!transitionFinished)
323 Tizen.Log.Error("NUI", "Transition is still not finished.\n");
327 if (navigationPages.Count == 0)
329 throw new InvalidOperationException("There is no page in Navigator.");
332 var topPage = Peek();
334 if (navigationPages.Count == 1)
338 //Invoke Popped event
339 Popped?.Invoke(this, new PoppedEventArgs() { Page = topPage });
343 var newTopPage = navigationPages[navigationPages.Count - 2];
346 newTopPage.InvokeAppearing();
347 topPage.InvokeDisappearing();
348 topPage.SaveKeyFocus();
350 transitionSet = CreateTransitions(topPage, newTopPage, false);
351 transitionSet.Finished += (object sender, EventArgs e) =>
354 topPage.SetVisible(true);
356 // Need to update Content of the new page
357 ShowContentOfPage(newTopPage);
360 newTopPage.InvokeAppeared();
361 newTopPage.RestoreKeyFocus();
363 topPage.InvokeDisappeared();
365 //Invoke Popped event
366 Popped?.Invoke(this, new PoppedEventArgs() { Page = topPage });
368 transitionFinished = false;
374 /// Pushes a page to Navigator.
375 /// If the page is already in Navigator, then it is not pushed.
377 /// <param name="page">The page to push to Navigator.</param>
378 /// <exception cref="ArgumentNullException">Thrown when the argument page is null.</exception>
379 /// <since_tizen> 9 </since_tizen>
380 public void Push(Page page)
382 if (!transitionFinished)
384 Tizen.Log.Error("NUI", "Transition is still not finished.\n");
390 throw new ArgumentNullException(nameof(page), "page should not be null.");
393 //Duplicate page is not pushed.
394 if (navigationPages.Contains(page)) return;
404 navigationPages.Add(page);
406 page.Navigator = this;
409 page.InvokeAppearing();
410 curTop.InvokeDisappearing();
412 curTop.SaveKeyFocus();
414 //TODO: The following transition codes will be replaced with view transition.
415 InitializeAnimation();
417 if (page is DialogPage == false)
419 curAnimation = new Animation(DefaultTransitionDuration);
420 curAnimation.AnimateTo(curTop, "PositionX", 0.0f, 0, DefaultTransitionDuration);
421 curAnimation.EndAction = Animation.EndActions.StopFinal;
422 curAnimation.Finished += (object sender, EventArgs args) =>
424 curTop.SetVisible(false);
427 curTop.InvokeDisappeared();
431 page.PositionX = SizeWidth;
432 page.SetVisible(true);
433 // Set Content visible because it was hidden by HideContentOfPage.
434 (page as ContentPage)?.Content?.SetVisible(true);
436 newAnimation = new Animation(DefaultTransitionDuration);
437 newAnimation.AnimateTo(page, "PositionX", 0.0f, 0, DefaultTransitionDuration);
438 newAnimation.EndAction = Animation.EndActions.StopFinal;
439 newAnimation.Finished += (object sender, EventArgs e) =>
441 // Need to update Content of the new page
442 ShowContentOfPage(page);
445 page.InvokeAppeared();
446 NotifyAccessibilityStatesChangeOfPages(curTop, page);
448 page.RestoreKeyFocus();
454 ShowContentOfPage(page);
455 page.RestoreKeyFocus();
460 /// Pops the top page from Navigator.
462 /// <returns>The popped page.</returns>
463 /// <exception cref="InvalidOperationException">Thrown when there is no page in Navigator.</exception>
464 /// <since_tizen> 9 </since_tizen>
467 if (!transitionFinished)
469 Tizen.Log.Error("NUI", "Transition is still not finished.\n");
473 if (navigationPages.Count == 0)
475 throw new InvalidOperationException("There is no page in Navigator.");
480 if (navigationPages.Count == 1)
484 //Invoke Popped event
485 Popped?.Invoke(this, new PoppedEventArgs() { Page = curTop });
490 var newTop = navigationPages[navigationPages.Count - 2];
493 newTop.InvokeAppearing();
494 curTop.InvokeDisappearing();
495 curTop.SaveKeyFocus();
497 //TODO: The following transition codes will be replaced with view transition.
498 InitializeAnimation();
500 if (curTop is DialogPage == false)
502 curAnimation = new Animation(DefaultTransitionDuration);
503 curAnimation.AnimateTo(curTop, "PositionX", SizeWidth, 0, DefaultTransitionDuration);
504 curAnimation.EndAction = Animation.EndActions.StopFinal;
505 curAnimation.Finished += (object sender, EventArgs e) =>
507 //Removes the current top page after transition is finished.
510 curTop.PositionX = 0.0f;
513 curTop.InvokeDisappeared();
515 //Invoke Popped event
516 Popped?.Invoke(this, new PoppedEventArgs() { Page = curTop });
520 newTop.SetVisible(true);
521 // Set Content visible because it was hidden by HideContentOfPage.
522 (newTop as ContentPage)?.Content?.SetVisible(true);
524 newAnimation = new Animation(DefaultTransitionDuration);
525 newAnimation.AnimateTo(newTop, "PositionX", 0.0f, 0, DefaultTransitionDuration);
526 newAnimation.EndAction = Animation.EndActions.StopFinal;
527 newAnimation.Finished += (object sender, EventArgs e) =>
529 // Need to update Content of the new page
530 ShowContentOfPage(newTop);
533 newTop.InvokeAppeared();
535 newTop.RestoreKeyFocus();
542 newTop.RestoreKeyFocus();
549 /// Returns the page of the given index in Navigator.
550 /// The indices of pages in Navigator are basically the order of pushing or inserting to Navigator.
551 /// So a page's index in Navigator can be changed whenever push/insert or pop/remove occurs.
553 /// <param name="index">The index of a page in Navigator.</param>
554 /// <returns>The page of the given index in Navigator.</returns>
555 /// <exception cref="ArgumentOutOfRangeException">Thrown when the argument index is less than 0, or greater than the number of pages.</exception>
556 public Page GetPage(int index)
558 if ((index < 0) || (index > navigationPages.Count))
560 throw new ArgumentOutOfRangeException(nameof(index), "index should be greater than or equal to 0, and less than or equal to the number of pages.");
563 return navigationPages[index];
567 /// Returns the current index of the given page in Navigator.
568 /// The indices of pages in Navigator are basically the order of pushing or inserting to Navigator.
569 /// So a page's index in Navigator can be changed whenever push/insert or pop/remove occurs.
571 /// <param name="page">The page in Navigator.</param>
572 /// <returns>The index of the given page in Navigator. If the given page is not in the Navigator, then -1 is returned.</returns>
573 /// <exception cref="ArgumentNullException">Thrown when the argument page is null.</exception>
574 /// <since_tizen> 9 </since_tizen>
575 public int IndexOf(Page page)
579 throw new ArgumentNullException(nameof(page), "page should not be null.");
582 for (int i = 0; i < navigationPages.Count; i++)
584 if (navigationPages[i] == page)
594 /// Inserts a page at the specified index of Navigator.
595 /// The indices of pages in Navigator are basically the order of pushing or inserting to Navigator.
596 /// So a page's index in Navigator can be changed whenever push/insert or pop/remove occurs.
597 /// To find the current index of a page in Navigator, please use IndexOf(page).
598 /// If the page is already in Navigator, then it is not inserted.
600 /// <param name="index">The index of a page in Navigator where the page will be inserted.</param>
601 /// <param name="page">The page to insert to Navigator.</param>
602 /// <exception cref="ArgumentOutOfRangeException">Thrown when the argument index is less than 0, or greater than the number of pages.</exception>
603 /// <exception cref="ArgumentNullException">Thrown when the argument page is null.</exception>
604 /// <since_tizen> 9 </since_tizen>
605 public void Insert(int index, Page page)
607 if ((index < 0) || (index > navigationPages.Count))
609 throw new ArgumentOutOfRangeException(nameof(index), "index should be greater than or equal to 0, and less than or equal to the number of pages.");
614 throw new ArgumentNullException(nameof(page), "page should not be null.");
617 //Duplicate page is not pushed.
618 if (navigationPages.Contains(page)) return;
620 //TODO: The following transition codes will be replaced with view transition.
621 InitializeAnimation();
623 ShowContentOfPage(page);
625 if (index == PageCount)
627 page.SetVisible(true);
631 page.SetVisible(false);
634 navigationPages.Insert(index, page);
636 page.SiblingOrder = index;
637 page.Navigator = this;
638 if (index == PageCount - 1)
642 NotifyAccessibilityStatesChangeOfPages(navigationPages[PageCount - 2], page);
646 NotifyAccessibilityStatesChangeOfPages(null, page);
652 /// Inserts a page to Navigator before an existing page.
653 /// If the page is already in Navigator, then it is not inserted.
655 /// <param name="before">The existing page, before which a page will be inserted.</param>
656 /// <param name="page">The page to insert to Navigator.</param>
657 /// <exception cref="ArgumentNullException">Thrown when the argument before is null.</exception>
658 /// <exception cref="ArgumentNullException">Thrown when the argument page is null.</exception>
659 /// <exception cref="ArgumentException">Thrown when the argument before does not exist in Navigator.</exception>
660 /// <since_tizen> 9 </since_tizen>
661 public void InsertBefore(Page before, Page page)
665 throw new ArgumentNullException(nameof(before), "before should not be null.");
670 throw new ArgumentNullException(nameof(page), "page should not be null.");
673 //Find the index of before page.
674 int beforeIndex = navigationPages.FindIndex(x => x == before);
676 //before does not exist in Navigator.
677 if (beforeIndex == -1)
679 throw new ArgumentException("before does not exist in Navigator.", nameof(before));
682 Insert(beforeIndex, page);
686 /// Removes a page from Navigator.
688 /// <param name="page">The page to remove from Navigator.</param>
689 /// <exception cref="ArgumentNullException">Thrown when the argument page is null.</exception>
690 /// <since_tizen> 9 </since_tizen>
691 public void Remove(Page page)
695 throw new ArgumentNullException(nameof(page), "page should not be null.");
698 //TODO: The following transition codes will be replaced with view transition.
699 InitializeAnimation();
701 HideContentOfPage(page);
707 navigationPages[PageCount - 2].SetVisible(true);
708 NotifyAccessibilityStatesChangeOfPages(page, navigationPages[PageCount - 2]);
710 else if (PageCount == 1)
712 NotifyAccessibilityStatesChangeOfPages(page, null);
715 page.Navigator = null;
716 navigationPages.Remove(page);
721 /// Removes a page at the specified index of Navigator.
722 /// The indices of pages in Navigator are basically the order of pushing or inserting to Navigator.
723 /// So a page's index in Navigator can be changed whenever push/insert or pop/remove occurs.
724 /// To find the current index of a page in Navigator, please use IndexOf(page).
726 /// <param name="index">The index of a page in Navigator where the page will be removed.</param>
727 /// <exception cref="ArgumentOutOfRangeException">Thrown when the index is less than 0, or greater than or equal to the number of pages.</exception>
728 /// <since_tizen> 9 </since_tizen>
729 public void RemoveAt(int index)
731 if ((index < 0) || (index >= navigationPages.Count))
733 throw new ArgumentOutOfRangeException(nameof(index), "index should be greater than or equal to 0, and less than the number of pages.");
736 Remove(navigationPages[index]);
740 /// Returns the page at the top of Navigator.
742 /// <returns>The page at the top of Navigator.</returns>
743 /// <since_tizen> 9 </since_tizen>
746 if (navigationPages.Count == 0) return null;
748 return navigationPages[navigationPages.Count - 1];
752 /// Gets or sets if Navigator pops the peek page when back button or back key is pressed and released.
754 [EditorBrowsable(EditorBrowsableState.Never)]
755 public bool EnableBackNavigation
759 return (bool)GetValue(EnableBackNavigationProperty);
763 SetValue(EnableBackNavigationProperty, value);
764 NotifyPropertyChanged();
768 private bool InternalEnableBackNavigation
772 enableBackNavigation = value;
776 return enableBackNavigation;
781 /// Disposes Navigator and all children on it.
783 /// <param name="type">Dispose type.</param>
784 [EditorBrowsable(EditorBrowsableState.Never)]
785 protected override void Dispose(DisposeTypes type)
792 if (type == DisposeTypes.Explicit)
794 foreach (Page page in navigationPages)
796 Utility.Dispose(page);
798 navigationPages.Clear();
802 if (navigatorWindow.TryGetValue(this, out window) == true)
804 navigatorWindow.Remove(this);
805 windowNavigator.Remove(window);
808 AddedToWindow -= OnAddedToWindow;
809 RemovedFromWindow -= OnRemovedFromWindow;
816 /// Returns the default navigator of the given window.
818 /// <returns>The default navigator of the given window.</returns>
819 /// <exception cref="ArgumentNullException">Thrown when the argument window is null.</exception>
820 /// <since_tizen> 9 </since_tizen>
821 public static Navigator GetDefaultNavigator(Window window)
825 throw new ArgumentNullException(nameof(window), "window should not be null.");
828 if (windowNavigator.ContainsKey(window) == true)
830 return windowNavigator[window];
833 var defaultNavigator = new Navigator();
834 defaultNavigator.WidthResizePolicy = ResizePolicyType.FillToParent;
835 defaultNavigator.HeightResizePolicy = ResizePolicyType.FillToParent;
836 window.Add(defaultNavigator);
837 windowNavigator.Add(window, defaultNavigator);
838 navigatorWindow.Add(defaultNavigator, window);
840 return defaultNavigator;
844 /// Sets the default navigator of the given window.
845 /// SetDefaultNavigator does not remove the previous default navigator from the window.
846 /// Therefore, if a user does not want to show the previous default navigator, then it should be removed from the window manually.
848 /// <exception cref="ArgumentNullException">Thrown when the argument window is null.</exception>
849 /// <exception cref="ArgumentNullException">Thrown when the argument newNavigator is null.</exception>
850 [EditorBrowsable(EditorBrowsableState.Never)]
851 public static void SetDefaultNavigator(Window window, Navigator newNavigator)
855 throw new ArgumentNullException(nameof(window), "window should not be null.");
858 if (newNavigator == null)
860 throw new ArgumentNullException(nameof(newNavigator), "newNavigator should not be null.");
863 if (windowNavigator.ContainsKey(window) == true)
865 var oldNavigator = windowNavigator[window];
866 if (oldNavigator == newNavigator)
871 navigatorWindow.Remove(oldNavigator);
872 windowNavigator.Remove(window);
875 window.Add(newNavigator);
876 windowNavigator.Add(window, newNavigator);
877 navigatorWindow.Add(newNavigator, window);
881 /// Called when the back navigation is started.
883 /// <param name="eventArgs">The back navigation information.</param>
884 [EditorBrowsable(EditorBrowsableState.Never)]
885 protected virtual void OnBackNavigation(BackNavigationEventArgs eventArgs)
889 if (Peek().EnableBackNavigation)
891 Peek().NavigateBack();
897 /// Called when the back navigation is required outside Navigator.
899 internal void NavigateBack()
901 OnBackNavigation(new BackNavigationEventArgs());
905 /// Create Transitions between currentTopPage and newTopPage
907 /// <param name="currentTopPage">The top page of Navigator.</param>
908 /// <param name="newTopPage">The new top page after transition.</param>
909 /// <param name="pushTransition">True if this transition is for push new page</param>
910 private TransitionSet CreateTransitions(Page currentTopPage, Page newTopPage, bool pushTransition)
912 currentTopPage.SetVisible(true);
913 // Set Content visible because it was hidden by HideContentOfPage.
914 (currentTopPage as ContentPage)?.Content?.SetVisible(true);
916 newTopPage.SetVisible(true);
917 // Set Content visible because it was hidden by HideContentOfPage.
918 (newTopPage as ContentPage)?.Content?.SetVisible(true);
920 List<View> taggedViewsInNewTopPage = new List<View>();
921 RetrieveTaggedViews(taggedViewsInNewTopPage, newTopPage, true);
922 List<View> taggedViewsInCurrentTopPage = new List<View>();
923 RetrieveTaggedViews(taggedViewsInCurrentTopPage, currentTopPage, true);
925 List<KeyValuePair<View, View>> sameTaggedViewPair = new List<KeyValuePair<View, View>>();
926 foreach (View currentTopPageView in taggedViewsInCurrentTopPage)
928 bool findPair = false;
929 foreach (View newTopPageView in taggedViewsInNewTopPage)
931 if ((currentTopPageView.TransitionOptions != null) && (newTopPageView.TransitionOptions != null) &&
932 currentTopPageView.TransitionOptions?.TransitionTag == newTopPageView.TransitionOptions?.TransitionTag)
934 sameTaggedViewPair.Add(new KeyValuePair<View, View>(currentTopPageView, newTopPageView));
941 taggedViewsInNewTopPage.Remove(sameTaggedViewPair[sameTaggedViewPair.Count - 1].Value);
944 foreach (KeyValuePair<View, View> pair in sameTaggedViewPair)
946 taggedViewsInCurrentTopPage.Remove(pair.Key);
949 TransitionSet newTransitionSet = new TransitionSet();
950 foreach (KeyValuePair<View, View> pair in sameTaggedViewPair)
952 TransitionItem pairTransition = transition.CreateTransition(pair.Key, pair.Value, pushTransition);
953 if (pair.Value.TransitionOptions?.TransitionWithChild ?? false)
955 pairTransition.TransitionWithChild = true;
957 newTransitionSet.AddTransition(pairTransition);
960 newTransitionSet.Finished += (object sender, EventArgs e) =>
962 if (newTopPage.Layout != null)
964 newTopPage.Layout.RequestLayout();
966 if (currentTopPage.Layout != null)
968 currentTopPage.Layout.RequestLayout();
970 transitionFinished = true;
971 InvokeTransitionFinished();
972 transitionSet.Dispose();
975 if (!pushTransition || newTopPage is DialogPage == false)
977 View transitionView = (currentTopPage is ContentPage) ? (currentTopPage as ContentPage).Content : (currentTopPage as DialogPage).Content;
978 if (currentTopPage.DisappearingTransition != null && transitionView != null)
980 TransitionItemBase disappearingTransition = currentTopPage.DisappearingTransition.CreateTransition(transitionView, false);
981 disappearingTransition.TransitionWithChild = true;
982 newTransitionSet.AddTransition(disappearingTransition);
986 currentTopPage.SetVisible(false);
989 if (pushTransition || currentTopPage is DialogPage == false)
991 View transitionView = (newTopPage is ContentPage) ? (newTopPage as ContentPage).Content : (newTopPage as DialogPage).Content;
992 if (newTopPage.AppearingTransition != null && transitionView != null)
994 TransitionItemBase appearingTransition = newTopPage.AppearingTransition.CreateTransition(transitionView, true);
995 appearingTransition.TransitionWithChild = true;
996 newTransitionSet.AddTransition(appearingTransition);
1000 newTransitionSet.Play();
1002 return newTransitionSet;
1006 /// Retrieve Tagged Views in the view tree.
1008 /// <param name="taggedViews">Returned tagged view list..</param>
1009 /// <param name="view">Root View to get tagged child View.</param>
1010 /// <param name="isRoot">Flag to check current View is page or not</param>
1011 private void RetrieveTaggedViews(List<View> taggedViews, View view, bool isRoot)
1013 if (!isRoot && view.TransitionOptions != null)
1015 if (!string.IsNullOrEmpty(view.TransitionOptions?.TransitionTag))
1017 taggedViews.Add((view as View));
1018 if (view.TransitionOptions.TransitionWithChild)
1026 foreach (View child in view.Children)
1028 RetrieveTaggedViews(taggedViews, child, false);
1033 /// Notify accessibility states change of pages.
1035 /// <param name="disappearedPage">Disappeared page</param>
1036 /// <param name="appearedPage">Appeared page</param>
1037 private void NotifyAccessibilityStatesChangeOfPages(Page disappearedPage, Page appearedPage)
1039 if (disappearedPage != null)
1041 disappearedPage.UnregisterDefaultLabel();
1042 //We can call disappearedPage.NotifyAccessibilityStatesChange
1043 //To reduce accessibility events, we are using currently highlighted view instead
1044 View curHighlightedView = Accessibility.Accessibility.GetCurrentlyHighlightedView();
1045 if (curHighlightedView != null)
1047 curHighlightedView.NotifyAccessibilityStatesChange(new AccessibilityStates(AccessibilityState.Visible, AccessibilityState.Showing), AccessibilityStatesNotifyMode.Single);
1051 if (appearedPage != null)
1053 appearedPage.RegisterDefaultLabel();
1054 appearedPage.NotifyAccessibilityStatesChange(new AccessibilityStates(AccessibilityState.Visible, AccessibilityState.Showing), AccessibilityStatesNotifyMode.Single);
1058 internal void InvokeTransitionFinished()
1060 TransitionFinished?.Invoke(this, new EventArgs());
1063 //TODO: The following transition codes will be replaced with view transition.
1064 private void InitializeAnimation()
1066 if (curAnimation != null)
1068 curAnimation.Stop();
1069 curAnimation.Clear();
1070 curAnimation = null;
1073 if (newAnimation != null)
1075 newAnimation.Stop();
1076 newAnimation.Clear();
1077 newAnimation = null;
1081 // Show and Register Content of Page to Accessibility bridge
1082 private void ShowContentOfPage(Page page)
1084 View content = (page is DialogPage) ? (page as DialogPage)?.Content : (page as ContentPage)?.Content;
1085 if (content != null)
1087 content.Show(); // Calls RegisterDefaultLabel()
1091 // Hide and Remove Content of Page from Accessibility bridge
1092 private void HideContentOfPage(Page page)
1094 View content = (page is DialogPage) ? (page as DialogPage)?.Content : (page as ContentPage)?.Content;
1095 if (content != null)
1097 content.Hide(); // Calls UnregisterDefaultLabel()
1103 /// BackNavigationEventArgs is a class to record back navigation event arguments which will sent to user.
1105 [EditorBrowsable(EditorBrowsableState.Never)]
1106 public class BackNavigationEventArgs : EventArgs