Exemple #1
0
 /// <summary>
 /// Invalidates the EventArgs if _isPopped is false.
 /// The method should be overridden in the children class.
 /// </summary>
 /// <since_tizen> preview </since_tizen>
 protected override void OnInvalidate()
 {
     if (!_isPopped)
     {
         Popped?.Invoke(this, EventArgs.Empty);
     }
 }
        public new T Pop()
        {
            var item = base.Pop();

            Popped?.Invoke(item, base.Peek(), EventArgs.Empty);
            return(item);
        }
        public Task RemovePageAsync(PopupPage page, bool animate = true)
        {
            lock (_locker)
            {
                if (page == null)
                {
                    return(Task.CompletedTask);
                }

                if (!_popupStack.Contains(page))
                {
                    return(Task.CompletedTask);
                }

                if (page.DisappearingTransactionTask != null)
                {
                    return(page.DisappearingTransactionTask);
                }

                var task = InvokeThreadSafe(async() =>
                {
                    if (page.AppearingTransactionTask != null)
                    {
                        await page.AppearingTransactionTask;
                    }

                    lock (_locker)
                    {
                        if (!_popupStack.Contains(page))
                        {
                            return;
                        }
                    }

                    animate = CanBeAnimated(animate);

                    if (animate)
                    {
                        await page.DisappearingAnimation();
                    }

                    await RemoveAsync(page);

                    if (animate)
                    {
                        page.DisposingAnimation();
                    }

                    lock (_locker)
                    {
                        _popupStack.Remove(page);
                        page.DisappearingTransactionTask = null;
                    }
                });

                page.DisappearingTransactionTask = task;
                Popped?.Invoke(this, new NavigationEventArgs(page));
                return(task);
            }
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PopupViewStackServiceBase"/> class.
        /// </summary>
        /// <param name="view">The view.</param>
        /// <param name="popupNavigation">The popup navigation.</param>
        /// <param name="viewLocator">The view locator.</param>
        /// <param name="viewModelFactory">The view model factory.</param>
        protected PopupViewStackServiceBase(IView view, IPopupNavigation popupNavigation, IViewLocator viewLocator, IViewModelFactory viewModelFactory)
            : base(view, viewModelFactory)
        {
            _popupNavigation = popupNavigation;
            _viewLocator = viewLocator;
            PopupSubject = new BehaviorSubject<IImmutableList<IViewModel>>(ImmutableList<IViewModel>.Empty);

            Pushing = Observable.FromEvent<EventHandler<PopupNavigationEventArgs>, PopupNavigationEventArgs>(
                eventHandler =>
                {
                    void Handler(object? sender, PopupNavigationEventArgs args) => eventHandler(args);

                    return Handler;
                },
                x => _popupNavigation.Pushing += x,
                x => _popupNavigation.Pushing -= x)
                .Select(x => new PopupNavigationEvent((IViewFor)x.Page, x.IsAnimated));

            Pushed = Observable.FromEvent<EventHandler<PopupNavigationEventArgs>, PopupNavigationEventArgs>(
                eventHandler =>
                {
                    void Handler(object? sender, PopupNavigationEventArgs args)
                        => eventHandler(args);

                    return Handler;
                },
                x => _popupNavigation.Pushed += x,
                x => _popupNavigation.Pushed -= x)
                .Select(x => new PopupNavigationEvent((IViewFor)x.Page, x.IsAnimated));

            Popping = Observable.FromEvent<EventHandler<PopupNavigationEventArgs>, PopupNavigationEventArgs>(
                eventHandler =>
                {
                    void Handler(object? sender, PopupNavigationEventArgs args)
                        => eventHandler(args);

                    return Handler;
                },
                x => _popupNavigation.Popping += x,
                x => _popupNavigation.Popping -= x)
                .Select(x => new PopupNavigationEvent((IViewFor)x.Page, x.IsAnimated));

            Popped = Observable.FromEvent<EventHandler<PopupNavigationEventArgs>, PopupNavigationEventArgs>(
                eventHandler =>
                {
                    void Handler(object? sender, PopupNavigationEventArgs args) => eventHandler(args);

                    return Handler;
                },
                x => _popupNavigation.Popped += x,
                x => _popupNavigation.Popped -= x)
                .Select(x => new PopupNavigationEvent((IViewFor)x.Page, x.IsAnimated));

            Popped
                .Subscribe(popped => popped.ViewModel.InvokeViewModelAction<IDestructible>(x => x.Destroy()))
                .DisposeWith(NavigationDisposables);

            PopupSubject.DisposeWith(NavigationDisposables);
        }
Exemple #5
0
        /// <summary>
        /// Pops the top page from Navigator.
        /// </summary>
        /// <returns>The popped page.</returns>
        /// <exception cref="InvalidOperationException">Thrown when there is no page in Navigator.</exception>
        /// <since_tizen> 9 </since_tizen>
        public Page PopWithTransition()
        {
            if (!transitionFinished)
            {
                Tizen.Log.Error("NUI", "Transition is still not finished.\n");
                return(null);
            }

            if (navigationPages.Count == 0)
            {
                throw new InvalidOperationException("There is no page in Navigator.");
            }

            var topPage = Peek();

            if (navigationPages.Count == 1)
            {
                Remove(topPage);

                //Invoke Popped event
                Popped?.Invoke(this, new PoppedEventArgs()
                {
                    Page = topPage
                });

                return(topPage);
            }
            var newTopPage = navigationPages[navigationPages.Count - 2];

            //Invoke Page events
            newTopPage.InvokeAppearing();
            topPage.InvokeDisappearing();
            topPage.SaveKeyFocus();

            transitionSet           = CreateTransitions(topPage, newTopPage, false);
            transitionSet.Finished += (object sender, EventArgs e) =>
            {
                Remove(topPage);
                topPage.SetVisible(true);

                // Need to update Content of the new page
                ShowContentOfPage(newTopPage);

                //Invoke Page events
                newTopPage.InvokeAppeared();
                newTopPage.RestoreKeyFocus();

                topPage.InvokeDisappeared();

                //Invoke Popped event
                Popped?.Invoke(this, new PoppedEventArgs()
                {
                    Page = topPage
                });
            };
            transitionFinished = false;

            return(topPage);
        }
        public Task RemovePageAsync(PopupPage page, bool animate = true)
        {
            lock (_locker)
            {
                if (page == null)
                {
                    throw new NullReferenceException("Page can not be null");
                }

                if (!_popupStack.Contains(page))
                {
                    throw new InvalidOperationException("The page has not been pushed yet or has been removed already");
                }

                if (page.DisappearingTransactionTask != null)
                {
                    return(page.DisappearingTransactionTask);
                }

                var task = InvokeThreadSafe(async() =>
                {
                    if (page.AppearingTransactionTask != null)
                    {
                        await page.AppearingTransactionTask;
                    }

                    lock (_locker)
                    {
                        if (!_popupStack.Contains(page))
                        {
                            return;
                        }
                    }

                    Popping?.Invoke(this, new PopupNavigationEventArgs(page, animate));

                    animate = CanBeAnimated(animate);

                    if (animate)
                    {
                        await page.DisappearingAnimation();
                        page.DisposingAnimation();
                    }
                    await RemoveAsync(page);

                    lock (_locker)
                    {
                        _popupStack.Remove(page);
                        page.DisappearingTransactionTask = null;

                        Popped?.Invoke(this, new PopupNavigationEventArgs(page, animate));
                    }
                });

                page.DisappearingTransactionTask = task;

                return(task);
            }
        }
Exemple #7
0
        /// <inheritdoc/>
        public Task PopAsync(bool animate = true)
        {
            Popping?.Invoke(this, new PopupNavigationEventArgs(_stack.Peek(), animate));
            var poppedPage = _stack.Pop();

            Popped?.Invoke(this, new PopupNavigationEventArgs(poppedPage, animate));
            return(Task.CompletedTask);
        }
Exemple #8
0
        /// <inheritdoc/>
        public Task RemovePageAsync(PopupPage page, bool animate = true)
        {
            var remove = _stack.ToList()[EnumerableExtensions.IndexOf(_stack.ToList(), page)];

            _stack.ToList().Remove(remove);
            Popped?.Invoke(this, new PopupNavigationEventArgs(remove, animate));
            return(Task.CompletedTask);
        }
Exemple #9
0
        private void Timer_Elapsed(object sender, ElapsedEventArgs e)
        {
            var time = timeout.Subtract(DateTime.Now.Subtract(start));

            if (time.TotalMilliseconds < 0)
            {
                Popped?.Invoke(this, new EventArgs());
            }
            Dispatcher.Invoke(() => ElapsedText.Content = time.ToString("m\\:ss"));
        }
Exemple #10
0
        public void Dequeue()
        {
            if (IsEmpty)
            {
                throw new QueueException("An exception occurred: Queue is empty");
            }
            var value = _head.Value;

            _head = _head.NextNode;
            Count--;
            Popped?.Invoke(this, new PopFromQueueEventArgs <T>(value, $"{value} popped"));
        }
Exemple #11
0
 NaviItem(IntPtr handle, EvasObject content) : base(handle)
 {
     _isPopped = false;
     _content  = content;
     _popped   = (d, i) =>
     {
         _isPopped = true;
         Popped?.Invoke(this, EventArgs.Empty);
         return(true);
     };
     Interop.Elementary.elm_naviframe_item_pop_cb_set(handle, _popped, IntPtr.Zero);
 }
Exemple #12
0
        void ItemPoppedHandler(object sender, EventArgs e)
        {
            NaviItem item = sender as NaviItem;

            if (item == null)
            {
                return;
            }
            _itemStack.Remove(item);
            Popped?.Invoke(this, new NaviframeEventArgs {
                Content = item.Content
            });
        }
Exemple #13
0
 public virtual void onPop(object sender, EventArgs e)
 {
     if (Content != null)
     {
         Content.Visible = true;
         if (Content.Parent == null)
         {
             CurrentInterface.AddWidget(Content, true);
         }
         if (Content.LogicalParent != this)
         {
             Content.LogicalParent = this;
         }
         CurrentInterface.PutOnTop(Content, true);
         _content_LayoutChanged(this, new LayoutingEventArgs(LayoutingType.Sizing));
     }
     Popped.Raise(this, e);
 }
        async Task SendHandlerUpdateAsync(bool animated, bool push = false, bool pop = false, bool popToRoot = false)
        {
            // Wait for any pending navigation tasks to finish
            await WaitForCurrentNavigationTask();

            var completionSource = new TaskCompletionSource <object>();

            CurrentNavigationTask = completionSource.Task;
            _taskCompletionSource = completionSource;

            // We create a new list to send to the handler because the structure backing
            // The Navigation stack isn't immutable
            var previousPage             = CurrentPage;
            var immutableNavigationStack = new List <IView>(NavigationStack);

            // Alert currently visible pages that navigation is happening
            SendNavigating();

            // Create the request for the handler
            var request = new NavigationRequest(immutableNavigationStack, animated);

            ((INavigationView)this).RequestNavigation(request);

            // Wait for the handler to finish processing the navigation
            await completionSource.Task;

            // Send navigated event to currently visible pages and associated navigation event
            SendNavigated(previousPage);
            if (push)
            {
                Pushed?.Invoke(this, new NavigationEventArgs(CurrentPage));
            }
            else if (pop)
            {
                Popped?.Invoke(this, new NavigationEventArgs(previousPage));
            }
            else
            {
                PoppedToRoot?.Invoke(this, new NavigationEventArgs(previousPage));
            }
        }
Exemple #15
0
        /// <summary>
        /// Pops the top page from Navigator.
        /// </summary>
        /// <returns>The popped page.</returns>
        /// <exception cref="InvalidOperationException">Thrown when there is no page in Navigator.</exception>
        /// <since_tizen> 9 </since_tizen>
        public Page Pop()
        {
            if (!transitionFinished)
            {
                Tizen.Log.Error("NUI", "Transition is still not finished.\n");
                return(null);
            }

            if (navigationPages.Count == 0)
            {
                throw new InvalidOperationException("There is no page in Navigator.");
            }

            var curTop = Peek();

            if (navigationPages.Count == 1)
            {
                Remove(curTop);

                //Invoke Popped event
                Popped?.Invoke(this, new PoppedEventArgs()
                {
                    Page = curTop
                });

                return(curTop);
            }

            var newTop = navigationPages[navigationPages.Count - 2];

            //Invoke Page events
            newTop.InvokeAppearing();
            curTop.InvokeDisappearing();
            curTop.SaveKeyFocus();

            //TODO: The following transition codes will be replaced with view transition.
            InitializeAnimation();

            if (curTop is DialogPage == false)
            {
                curAnimation = new Animation(DefaultTransitionDuration);
                curAnimation.AnimateTo(curTop, "PositionX", SizeWidth, 0, DefaultTransitionDuration);
                curAnimation.EndAction = Animation.EndActions.StopFinal;
                curAnimation.Finished += (object sender, EventArgs e) =>
                {
                    //Removes the current top page after transition is finished.
                    Remove(curTop);
                    curTop.PositionX = 0.0f;

                    //Invoke Page events
                    curTop.InvokeDisappeared();

                    //Invoke Popped event
                    Popped?.Invoke(this, new PoppedEventArgs()
                    {
                        Page = curTop
                    });
                };
                curAnimation.Play();

                newTop.SetVisible(true);
                // Set Content visible because it was hidden by HideContentOfPage.
                (newTop as ContentPage)?.Content?.SetVisible(true);

                newAnimation = new Animation(DefaultTransitionDuration);
                newAnimation.AnimateTo(newTop, "PositionX", 0.0f, 0, DefaultTransitionDuration);
                newAnimation.EndAction = Animation.EndActions.StopFinal;
                newAnimation.Finished += (object sender, EventArgs e) =>
                {
                    // Need to update Content of the new page
                    ShowContentOfPage(newTop);

                    //Invoke Page events
                    newTop.InvokeAppeared();

                    newTop.RestoreKeyFocus();
                };
                newAnimation.Play();
            }
            else
            {
                Remove(curTop);
            }

            return(curTop);
        }
Exemple #16
0
        /// <summary>
        /// Pops the top page from Navigator.
        /// </summary>
        /// <returns>The popped page.</returns>
        /// <exception cref="InvalidOperationException">Thrown when there is no page in Navigator.</exception>
        /// <since_tizen> 9 </since_tizen>
        public Page Pop()
        {
            if (!transitionFinished)
            {
                Tizen.Log.Error("NUI", "Transition is still not finished.\n");
                return(null);
            }

            if (navigationPages.Count == 0)
            {
                throw new InvalidOperationException("There is no page in Navigator.");
            }

            var curTop = Peek();

            if (navigationPages.Count == 1)
            {
                Remove(curTop);

                //Invoke Popped event
                Popped?.Invoke(this, new PoppedEventArgs()
                {
                    Page = curTop
                });

                return(curTop);
            }

            var newTop = navigationPages[navigationPages.Count - 2];

            //Invoke Page events
            newTop.InvokeAppearing();
            curTop.InvokeDisappearing();

            //TODO: The following transition codes will be replaced with view transition.
            InitializeAnimation();

            if (curTop is DialogPage == false)
            {
                curAnimation = new Animation(1000);
                curAnimation.AnimateTo(curTop, "Opacity", 0.0f, 0, 1000);
                curAnimation.EndAction = Animation.EndActions.StopFinal;
                curAnimation.Finished += (object sender, EventArgs e) =>
                {
                    //Removes the current top page after transition is finished.
                    Remove(curTop);
                    curTop.Opacity = 1.0f;

                    //Invoke Page events
                    curTop.InvokeDisappeared();

                    //Invoke Popped event
                    Popped?.Invoke(this, new PoppedEventArgs()
                    {
                        Page = curTop
                    });
                };
                curAnimation.Play();

                newTop.Opacity = 1.0f;
                newTop.SetVisible(true);
                newAnimation = new Animation(1000);
                newAnimation.AnimateTo(newTop, "Opacity", 1.0f, 0, 1000);
                newAnimation.EndAction = Animation.EndActions.StopFinal;
                newAnimation.Finished += (object sender, EventArgs e) =>
                {
                    //Invoke Page events
                    newTop.InvokeAppeared();
                };
                newAnimation.Play();
            }
            else
            {
                Remove(curTop);
            }

            return(curTop);
        }
Exemple #17
0
 public void Pop()
 {
     Popped?.Invoke(this, null);
 }
 public override void OnPop(MachineId machineId, string currentStateName, string restoredStateName)
 {
     base.OnPop(machineId, currentStateName, restoredStateName);
     Popped?.Invoke(machineId, currentStateName, restoredStateName);
 }
Exemple #19
0
                public void Dispose()
                {
                    var item = _stack.Pop();

                    Popped?.Invoke(item);
                }