Exemple #1
0
        private static void AddToBackStack(BaseView view)
        {
            //remove if presented
            while (BackStack.Remove(view))
            {
                ;
            }

            //add to end
            if (BackStack.Count == 0)
            {
                BackStack.AddLast(view);
                return;
            }

            //find by priority
            var node = BackStack.Last;

            while (node != null && node.Value.BackPrority > view.BackPrority)
            {
                node = node.Previous;
            }

            if (node == null)
            {
                BackStack.AddFirst(view);
                return;
            }
            else
            {
                BackStack.AddAfter(node, view);
            }
        }
Exemple #2
0
        private static void CloseNoAnimation(BaseView view)
        {
            if (view.VisibleState != VisibleState.Closed)
            {
                //close children
                foreach (var child in view.OpenedChildren.ToArray())
                {
                    CloseNoAnimation(child);
                }

                //remove from back stack
                while (BackStack.Remove(view))
                {
                    ;
                }

                //close
                try
                {
                    view.gameObject.SetActive(false);
                    OnViewClosed(view);
                    if (Instance.DestroyDynamicViews && view.IsDynamicallyCreated)
                    {
                        GameObject.Destroy(view.gameObject);
                    }
                }
                catch
                { // object destroyed?
                }

                //remove from owner list
                view.Owner?.OpenedChildren.Remove(view);
            }
        }
        public bool TryGoBack()
        {
            if (!CanGoBack)
            {
                return(false);
            }


            var destination = BackStack.LastOrDefault();

            if (destination == null)
            {
                return(false);
            }

            BackStack.Remove(destination);


            AddToForwardStack(
                CurrentViewModel,
                CurrentContent);


            SetCurrent(
                destination.ViewModel,
                destination.Content);


            return(true);
        }
        public static void RemoveBackEntry(Type pageType)
        {
            IList <PageStackEntry> entries = BackStack.Where(entry => entry.SourcePageType == pageType).ToList();

            foreach (PageStackEntry entry in entries)
            {
                BackStack.Remove(entry);
            }
        }
 private async Task GoBackAsync()
 {
     BackStack.Remove(CurrentItem);
     ForwardStack.Add(CurrentItem);
     if (BackStack.Count > 0)
     {
         CurrentItem = BackStack.Last();
     }
     await ReloadAsync();
 }
Exemple #6
0
        /// <summary>Close the view and all children views</summary>
        public static void Close(BaseView view, Action onAnimationDone = null, bool noAnimation = false)
        {
            //already closed?
            if (view.VisibleState == VisibleState.Closed)
            {
                //view.gameObject.SetActive(false);
                ClearOwnerAndShowIfHidden(view);
                onAnimationDone?.Invoke();
                return;
            }

            //close children w/o anitmation
            if (!Instance.CloseChildrenAfterOwner)
            {
                CloseAllChildren(view);
            }

            //remove from back stack
            while (BackStack.Remove(view))
            {
                ;
            }

            //close
            var prevState = view.VisibleState;

            OnViewClosed(view);

            //if was hidden - return
            if (prevState == VisibleState.Hidden)
            {
                view.gameObject.SetActive(false);
                if (Instance.CloseChildrenAfterOwner)
                {
                    CloseAllChildren(view);
                }
                ClearOwnerAndShowIfHidden(view);
                return;
            }

            //get close animation
            var anim = view.Animations.CloseAnimation ?? Instance.CloseAnimation;

            //play animation and deactivate
            Action onDone = () =>
            {
                if (view)
                {
                    view.gameObject.SetActive(false);
                    if (Instance.CloseChildrenAfterOwner)
                    {
                        CloseAllChildren(view);
                    }
                    if (Instance.DestroyDynamicViews && view.IsDynamicallyCreated)
                    {
                        GameObject.Destroy(view.gameObject);
                    }
                }
                onAnimationDone?.Invoke();
            };

            var animation = anim?.Animation;

            if (noAnimation)
            {
                animation = null;
            }

            ClearOwnerAndShowIfHidden(view);

            AnimationPlayer.Play(view.RectTransform, animation, onDone, true, 1, 1);
        }
Exemple #7
0
        private bool InnerNavigate(PageStackEntry entry, NavigationMode mode)
        {
            try
            {
                // Navigating
                var navigatingFromArgs = new NavigatingCancelEventArgs(
                    mode,
                    entry.NavigationTransitionInfo,
                    entry.Parameter,
                    entry.SourcePageType
                    );

                Navigating?.Invoke(this, navigatingFromArgs);

                CurrentEntry?.Instance.OnNavigatingFrom(navigatingFromArgs);

                if (navigatingFromArgs.Cancel)
                {
                    NavigationStopped?.Invoke(this, new NavigationEventArgs(
                                                  entry.Instance,
                                                  mode,
                                                  entry.NavigationTransitionInfo,
                                                  entry.Parameter,
                                                  entry.SourcePageType,
                                                  null
                                                  ));
                    return(false);
                }

                // Navigate
                var previousEntry = CurrentEntry;
                CurrentEntry = entry;

                if (mode == NavigationMode.New)
                {
                    // Doing this first allows CurrentEntry to reuse existing page if pooling is enabled
                    ReleasePages(ForwardStack);
                }

                if (CurrentEntry.Instance == null)
                {
                    var page = CreatePageInstanceCached(entry.SourcePageType);
                    if (page == null)
                    {
                        return(false);
                    }

                    page.Frame            = this;
                    CurrentEntry.Instance = page;
                }

                Content = CurrentEntry.Instance;

                switch (mode)
                {
                case NavigationMode.New:
                    ForwardStack.Clear();
                    if (previousEntry != null)
                    {
                        BackStack.Add(previousEntry);
                    }
                    break;

                case NavigationMode.Back:
                    ForwardStack.Add(previousEntry);
                    BackStack.Remove(CurrentEntry);
                    break;

                case NavigationMode.Forward:
                    BackStack.Add(previousEntry);
                    ForwardStack.Remove(CurrentEntry);
                    break;

                case NavigationMode.Refresh:
                    break;
                }

                // Navigated
                var navigationEvent = new NavigationEventArgs(
                    CurrentEntry.Instance,
                    mode,
                    entry.NavigationTransitionInfo,
                    entry.Parameter,
                    entry.SourcePageType,
                    null
                    );

                previousEntry?.Instance.OnNavigatedFrom(navigationEvent);
                CurrentEntry.Instance.OnNavigatedTo(navigationEvent);
                Navigated?.Invoke(this, navigationEvent);

                VisualTreeHelper.CloseAllPopups();

                return(true);
            }
            catch (Exception exception)
            {
                NavigationFailed?.Invoke(this, new NavigationFailedEventArgs(entry.SourcePageType, exception));
                return(false);
            }
        }