Exemplo n.º 1
0
        public async Task Push(NavigationPushInfo pushInfo)
        {
            var         newPage = GetInitializedPage(pushInfo);
            INavigation navigation;

            var masterDetailPage = _app.MainPage as MasterDetailPage;

            if (masterDetailPage != null && masterDetailPage.IsPresented)
            {
                masterDetailPage.IsPresented = false;
                await Task.Delay(300);
            }

            switch (pushInfo.Mode)
            {
            case NavigationMode.Normal:
                if (_navigations.TryPeek(out navigation))
                {
                    await navigation.PushAsync(newPage, pushInfo.WithAnimation);
                }
                break;

            case NavigationMode.Modal:
                if (_navigations.TryPeek(out navigation))
                {
                    await navigation.PushModalAsync(newPage, pushInfo.WithAnimation);

                    if (newPage.Navigation != null && !_navigations.Contains(newPage.Navigation))
                    {
                        _navigations.Push(newPage.Navigation);
                    }
                }
                break;

            case NavigationMode.Root:
                if (masterDetailPage != null)
                {
                    await SetRootDetailPage(masterDetailPage, newPage, pushInfo.WithAnimation);
                }
                else
                {
                    _app.MainPage = newPage;
                }

                DisposePages(_navigations.ToArray());

                _navigations.Clear();
                _navigations.Push(newPage.Navigation);
                break;

            case NavigationMode.Custom:
                await HandleCustomPushNavigation(masterDetailPage, pushInfo);

                break;

            default:
                throw new NotImplementedException();
            }
        }
Exemplo n.º 2
0
        void NavigationPushCallback(MessageBus bus, NavigationPushInfo navigationPushInfo)
        {
            if (_isBusy)
            {
                return;
            }

            if (navigationPushInfo == null)
            {
                throw new ArgumentNullException(nameof(navigationPushInfo));
            }

            if (string.IsNullOrEmpty(navigationPushInfo.To))
            {
                throw new FieldAccessException(@"'To' page value should be set");
            }
            if (_app == null)
            {
                throw new FieldAccessException(@"App property not set. Use Init() before navigation");
            }
            if (_navigations.Count == 0)
            {
                throw new FieldAccessException(@"Navigation is null. Add NavigationPage first");
            }

            Device.BeginInvokeOnMainThread(async() => {
                _isBusy = true;

                try {
                    await Push(navigationPushInfo);
                }
                catch (Exception e) {
                    System.Diagnostics.Debug.WriteLine(e);
                }

                _isBusy = false;
            });
        }
Exemplo n.º 3
0
 Page GetInitializedPage(NavigationPushInfo navigationPushInfo)
 {
     return(GetInitializedPage(navigationPushInfo.To, navigationPushInfo.Mode, navigationPushInfo.NavigationParams,
                               navigationPushInfo.NewNavigationStack, navigationPushInfo.WithAnimation,
                               navigationPushInfo.WithBackButton, navigationPushInfo.ToTitle));
 }
Exemplo n.º 4
0
 Task HandleCustomPushNavigation(MasterDetailPage masterDetailPage, NavigationPushInfo pushInfo)
 {
     // TODO: Implement your own navigation stack manipulation using pushInfo
     return(Task.FromResult(0));
 }