Ejemplo n.º 1
0
        /// <summary>
        /// Called when the Activity has detected the user's press of the back key
        /// </summary>
        public static async void OnBackPressed()
        {
            await semaphore.WaitAsync();

            try
            {
                var container       = ContainerLocator.Container;
                var popupNavigation = container.Resolve <IPopupNavigation>();
                var appProvider     = container.Resolve <IApplicationProvider>();

                var topPage    = PopupUtilities.TopPage(popupNavigation, appProvider);
                var navService = container.Resolve <INavigationService>(PrismApplicationBase.NavigationServiceName);
                if (navService is IPageAware pa)
                {
                    pa.Page = topPage;
                }

                var parameters = new NavigationParameters();
                parameters.AddInternalParameter("_NavigationSource", "BackButton");
                await navService.GoBackAsync(parameters);
            }
            finally
            {
                semaphore.Release();
            }
        }
        private static void InvokeLifecyleEvent(PrismApplicationBase app, Action <IApplicationLifecycleAware> action)
        {
            if (app.MainPage != null)
            {
                var popupNavigation = app.Container.Resolve <IPopupNavigation>();
                var appProvider     = app.Container.Resolve <IApplicationProvider>();

                var page = PopupUtilities.TopPage(popupNavigation, appProvider);
                PageUtilities.InvokeViewAndViewModelAction(page, action);
            }
        }
Ejemplo n.º 3
0
        protected override async Task <INavigationResult> GoBackInternal(INavigationParameters parameters, bool?useModalNavigation, bool animated)
        {
            INavigationResult result = null;

            try
            {
                NavigationSource = PageNavigationSource.NavigationService;

                switch (PopupUtilities.TopPage(_popupNavigation, _applicationProvider))
                {
                case PopupPage popupPage:
                    var segmentParameters = UriParsingHelper.GetSegmentParameters(null, parameters);
                    ((INavigationParametersInternal)segmentParameters).Add("__NavigationMode", NavigationMode.Back);
                    var previousPage = PopupUtilities.GetOnNavigatedToTarget(_popupNavigation, _applicationProvider);

                    await DoPop(popupPage.Navigation, false, animated);

                    if (popupPage != null)
                    {
                        PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(popupPage, a => a.IsActive = false);
                        PageUtilities.OnNavigatedFrom(popupPage, segmentParameters);
                        PageUtilities.OnNavigatedTo(previousPage, segmentParameters);
                        PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(previousPage, a => a.IsActive = true);
                        PageUtilities.DestroyPage(popupPage);
                        result = new NavigationResult {
                            Success = true
                        };
                        break;
                    }
                    throw new NullReferenceException("The PopupPage was null following the Pop");

                default:
                    result = await base.GoBackInternal(parameters, useModalNavigation, animated);

                    break;
                }
            }
            catch (Exception e)
            {
#if DEBUG
                System.Diagnostics.Debugger.Break();
#endif
                _logger.Log(e.ToString(), Category.Exception, Priority.High);
                result = new NavigationResult {
                    Success = false, Exception = e
                };;
            }
            finally
            {
                NavigationSource = PageNavigationSource.Device;
            }
            return(result);
        }
Ejemplo n.º 4
0
        public override async Task <INavigationResult> GoBackAsync(INavigationParameters parameters)
        {
            try
            {
                NavigationSource = PageNavigationSource.NavigationService;

                switch (PopupUtilities.TopPage(_popupNavigation, _applicationProvider))
                {
                case PopupPage popupPage:
                    var segmentParameters = UriParsingHelper.GetSegmentParameters(null, parameters);
                    ((INavigationParametersInternal)segmentParameters).Add("__NavigationMode", NavigationMode.Back);
                    var previousPage = PopupUtilities.GetOnNavigatedToTarget(_popupNavigation, _applicationProvider);

                    PageUtilities.OnNavigatingTo(previousPage, segmentParameters);
                    await DoPop(popupPage.Navigation, false, true);

                    if (popupPage != null)
                    {
                        PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(popupPage, a => a.IsActive = false);
                        PageUtilities.OnNavigatedFrom(popupPage, segmentParameters);
                        PageUtilities.OnNavigatedTo(previousPage, segmentParameters);
                        PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(previousPage, a => a.IsActive = true);
                        PageUtilities.DestroyPage(popupPage);
                        return(new NavigationResult {
                            Success = true
                        });
                    }
                    throw new NullReferenceException("The PopupPage was null following the Pop");

                default:
                    return(await base.GoBackAsync(parameters));
                }
            }
            catch (Exception e)
            {
                _logger.Log(e.ToString(), Category.Exception, Priority.High);
                return(new NavigationResult {
                    Success = false, Exception = e
                });;
            }
            finally
            {
                NavigationSource = PageNavigationSource.Device;
            }
        }
        public override async Task <bool> GoBackAsync(INavigationParameters parameters = null, bool?useModalNavigation = default(bool?), bool animated = true)
        {
            try
            {
                NavigationSource = PageNavigationSource.NavigationService;

                switch (PopupUtilities.TopPage(_popupNavigation, _applicationProvider))
                {
                case PopupPage popupPage:
                    var segmentParameters = UriParsingHelper.GetSegmentParameters(null, parameters);
                    segmentParameters.Add(KnownNavigationParameters.NavigationMode, NavigationMode.Back);
                    var previousPage = PopupUtilities.GetOnNavigatedToTarget(_popupNavigation, _applicationProvider);

                    PageUtilities.OnNavigatingTo(previousPage, segmentParameters);
                    await DoPop(popupPage.Navigation, false, animated);

                    if (popupPage != null)
                    {
                        PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(popupPage, a => a.IsActive = false);
                        PageUtilities.OnNavigatedFrom(popupPage, segmentParameters);
                        PageUtilities.OnNavigatedTo(previousPage, segmentParameters);
                        PageUtilities.InvokeViewAndViewModelAction <IActiveAware>(previousPage, a => a.IsActive = true);
                        PageUtilities.DestroyPage(popupPage);
                        return(true);
                    }
                    break;

                default:
                    return(await base.GoBackAsync(parameters, useModalNavigation, animated));
                }
            }
            catch (Exception e)
            {
                _logger.Log(e.ToString(), Category.Exception, Priority.High);
                return(false);
            }
            finally
            {
                NavigationSource = PageNavigationSource.Device;
            }

            return(false);
        }