void RootPush(Page newPage, NavigationPushInfo pushInfo = null) { try { var navPage = new NavigationPage(newPage) { BarTextColor = Colors.White, BarBackgroundColor = Color.Goldenrod }; Xamarin.Forms.PlatformConfiguration.iOSSpecific.NavigationPage.SetIsNavigationBarTranslucent(navPage, false); Xamarin.Forms.PlatformConfiguration.iOSSpecific.NavigationPage.SetHideNavigationBarSeparator(navPage, true); if (Application.Current.MainPage == null && newPage is ContentPage) { Device.BeginInvokeOnMainThread(() => Application.Current.MainPage = navPage); } else if (newPage is TabbedPage tp) { Application.Current.MainPage = navPage; pushInfo?.OnCompletedTask?.SetResult(true); } } catch (Exception e) { Console.WriteLine(e); pushInfo?.OnCompletedTask?.SetResult(false); } finally { _isBusy = false; } }
void ModalPush(Page newPage, NavigationPushInfo pushInfo) { Device.BeginInvokeOnMainThread(async() => { try { if (pushInfo.NewNavigationStack) { await GetTopNavigation().PopToRootAsync(pushInfo.WithAnimtation); newPage = new NavigationPage(newPage) { BarTextColor = Color.White }; await Task.Delay(10); Application.Current.MainPage = newPage; } else { await GetTopNavigation().PushModalAsync(newPage, pushInfo.WithAnimtation); } pushInfo.OnCompletedTask.SetResult(true); } catch (Exception ex) { pushInfo.OnCompletedTask.SetResult(false); Debug.WriteLine(ex); } finally { _isBusy = false; } }); }
void Push(NavigationPushInfo pushInfo) { var newPage = GetInitializedPage(pushInfo); switch (pushInfo.Mode) { case NavigationMode.Normal: NormalPush(newPage, pushInfo); break; case NavigationMode.Modal: ModalPush(newPage, pushInfo); break; case NavigationMode.RootPage: RootPush(newPage, pushInfo); break; case NavigationMode.Popup: PopupPush(newPage, pushInfo); break; default: throw new NotImplementedException(); } }
void NavigationPushCallback(MessageBus bus, NavigationPushInfo navigationPushInfo) { if (navigationPushInfo == null) { throw new ArgumentNullException(nameof(navigationPushInfo)); } if (string.IsNullOrEmpty(navigationPushInfo.To)) { throw new FieldAccessException(@"'To' page value should be set"); } if (_isBusy) { return; } _isBusy = true; Push(navigationPushInfo); }
void NormalPush(Page newPage, NavigationPushInfo pushInfo) { Device.BeginInvokeOnMainThread(async() => { try { await GetTopNavigation().PushAsync(newPage, pushInfo.WithAnimtation); pushInfo.OnCompletedTask.SetResult(true); } catch (Exception ex) { Debug.WriteLine(ex); pushInfo.OnCompletedTask.SetResult(false); } finally { _isBusy = false; } }); }
void PopupPush(Page newPage, NavigationPushInfo pushInfo) { Device.BeginInvokeOnMainThread(async() => { try { var nav = PopupNavigation.Instance; var page = (PopupPage)newPage; await nav.PushAsync(page, pushInfo.WithAnimtation); pushInfo.OnCompletedTask.SetResult(true); } catch { pushInfo.OnCompletedTask.SetResult(false); } finally { _isBusy = false; } }); }
Page GetInitializedPage(NavigationPushInfo navigationPushInfo) { return(GetInitializedPage(navigationPushInfo.To, navigationPushInfo.NavigationParams)); }