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);
            }
        }
Esempio n. 2
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);
        }