private void ShowNavigationBar(bool showNavBarNow) { var currentPage = GetCurrentPage(); if (_hideNavBarFeature == true && currentPage != null) { if (showNavBarNow == false && NavigationPage.GetHasNavigationBar(currentPage) == true) { if (Device.RuntimePlatform == Device.iOS) { this.Padding = new Thickness(0, DEFAULT_IOS_STATUS_BAR_HEIGHT, 0, 0); } NavigationPage.SetHasNavigationBar(currentPage, false); } if (showNavBarNow == true && NavigationPage.GetHasNavigationBar(currentPage) == false) { if (Device.RuntimePlatform == Device.iOS) { this.Padding = new Thickness(0, 0, 0, 0); } NavigationPage.SetHasNavigationBar(currentPage, true); } } }
bool ShouldShowActionBarTitleArea() { var activity = _context as Activity; if (activity == null) { return(false); } if (activity.Window.Attributes.Flags.HasFlag(WindowManagerFlags.Fullscreen)) { return(false); } bool hasMasterDetailPage = CurrentMasterDetailPage != null; bool navigated = CurrentNavigationPage != null && ((INavigationPageController)CurrentNavigationPage).StackDepth > 1; bool navigationPageHasNavigationBar = CurrentNavigationPage != null && NavigationPage.GetHasNavigationBar(CurrentNavigationPage.CurrentPage); //if we have MDP and Navigation , we let navigation choose if (CurrentNavigationPage != null && hasMasterDetailPage) { return(NavigationPage.GetHasNavigationBar(CurrentNavigationPage.CurrentPage)); } return(navigationPageHasNavigationBar || (hasMasterDetailPage && !navigated)); }
void ValidateNavbarExists(Page newCurrentPage) { //if the last time we did ViewDidLayoutSubviews we had other value for _hasNavigationBar //we will need to relayout. This is because Current is updated async of the layout happening if (_hasNavigationBar != NavigationPage.GetHasNavigationBar(newCurrentPage)) ViewDidLayoutSubviews(); }
void UpdateTitleOnParents() { if (Element == null) { return; } ITitleProvider render = null; if (_parentTabbedPage != null) { render = Platform.GetRenderer(_parentTabbedPage) as ITitleProvider; if (render != null) { render.ShowTitle = (_parentTabbedPage.CurrentPage == Element) && NavigationPage.GetHasNavigationBar(_currentPage); } } if (_parentMasterDetailPage != null) { render = Platform.GetRenderer(_parentMasterDetailPage) as ITitleProvider; if (render != null) { render.ShowTitle = (_parentMasterDetailPage.Detail == Element) && NavigationPage.GetHasNavigationBar(_currentPage); } } if (render != null && render.ShowTitle) { render.Title = _currentPage.Title; render.BarBackgroundBrush = GetBarBackgroundBrush(); render.BarForegroundBrush = GetBarForegroundBrush(); } }
void UpdateToolbarVisibilty() { // Enforce consistency rules on toolbar Control.ShouldShowToolbar = _detail is NavigationPage || _master is NavigationPage; if (_detail is NavigationPage _detailNav) { Control.ShouldShowNavigationBar = NavigationPage.GetHasNavigationBar(_detailNav.CurrentPage); } }
/// <summary> /// On size allocation. /// </summary> /// <param name="width">Width.</param> /// <param name="height">Height.</param> protected override void OnSizeAllocated(double width, double height) { //Permet d'afficher correctement la bar de status sur iOS if (Device.RuntimePlatform == Device.iOS) { this.mainLayout.Margin = App.NativeUtilities.GetStatusBarHidden() || NavigationPage.GetHasNavigationBar(this) ? new Thickness(0, 0, 0, 0) : new Thickness(0, 20, 0, 0); } base.OnSizeAllocated(width, height); }
/// <summary> /// Refreshs the margin. /// </summary> void RefreshMargin() { //Permet d'afficher correctement la bar de status sur iOS if (Device.RuntimePlatform == Device.iOS) { bool toMargin = App.NativeUtilities.GetStatusBarHidden() || NavigationPage.GetHasNavigationBar(this) ? false : true; mainLayout.Margin = toMargin ? new Thickness(0, 20, 0, 0) : new Thickness(0, 0, 0, 0); } }
private bool ControlsAreVisible() { if (NavigationPage.GetHasNavigationBar(App.MainBottomBarPage)) { return(true); } else { return(false); } }
internal void UpdateToolBar() { if (NSApplication.SharedApplication.MainWindow == null) { return; } if (_navigation == null) { if (_toolbar != null) { _toolbar.Visible = false; } _toolbar = null; return; } var currentPage = _navigation.Peek(0); if (NavigationPage.GetHasNavigationBar(currentPage)) { if (_toolbar == null) { _toolbar = ConfigureToolbar(); NSApplication.SharedApplication.MainWindow.Toolbar = _toolbar; _toolbar.InsertItem(NavigationGroupIdentifier, 0); _toolbar.InsertItem( HasTabs ? NSToolbar.NSToolbarSpaceItemIdentifier : NSToolbar.NSToolbarFlexibleSpaceItemIdentifier, 1); _toolbar.InsertItem(HasTabs ? TabbedGroupIdentifier : TitleGroupIdentifier, 2); _toolbar.InsertItem(NSToolbar.NSToolbarFlexibleSpaceItemIdentifier, 3); _toolbar.InsertItem(ToolbarItemsGroupIdentifier, 4); } _toolbar.Visible = true; UpdateToolbarItems(); UpdateTitle(); UpdateNavigationItems(); if (HasTabs) { UpdateTabbedItems(); } UpdateBarBackgroundColor(); } else { if (_toolbar != null) { _toolbar.Visible = false; } } }
public void SetNavigationBar() { var b = new ContentPage(); var container = GetNavigationContainer(); container.SetNavigationBar(true, b); Assert.Equal(true, NavigationPage.GetHasNavigationBar(b)); container.SetNavigationBar(false, b); Assert.Equal(false, NavigationPage.GetHasNavigationBar(b)); }
bool ShouldShowActionBarTitleArea() { if (Forms.TitleBarVisibility == AndroidTitleBarVisibility.Never) { return(false); } bool hasMasterDetailPage = CurrentMasterDetailPage != null; bool navigated = CurrentNavigationPage != null && ((INavigationPageController)CurrentNavigationPage).StackDepth > 1; bool navigationPageHasNavigationBar = CurrentNavigationPage != null && NavigationPage.GetHasNavigationBar(CurrentNavigationPage.CurrentPage); return(navigationPageHasNavigationBar || (hasMasterDetailPage && !navigated)); }
internal void UpdateToolBar() { if (_navigation == null) { if (_toolbar != null) { _toolbar.Visible = false; } _toolbar = null; return; } var currentPage = _navigation.Peek(0); if (NavigationPage.GetHasNavigationBar(currentPage)) { if (_toolbar == null) { _toolbar = ConfigureToolbar(); _toolbarIcon = new ImageControl { WidthRequest = 1, Aspect = ImageAspect.AspectFit }; _toolbarTitleSection.PackStart(_toolbarIcon, false, false, 8); _toolbarTitle = new Gtk.Label(); _toolbarTitleSection.PackEnd(_toolbarTitle, true, true, 0); } FindParentMasterDetail(); UpdateNavigationItems(); UpdateTitle(); UpdateIcon(); UpdateToolbarItems(); UpdateBarTextColor(); UpdateBarBackgroundColor(); } else { if (_toolbar != null) { _toolbar.Visible = false; } } }
protected override void OnLayout(bool changed, int l, int t, int r, int b) { var navigationPage = Element as NavigationPage; if (navigationPage.BarBackgroundColor != Color.Transparent) { if (navigationPage.CurrentPage.GetType() != typeof(PetProfilePage)) { base.OnLayout(changed, l, t + ActionBarHeight(), r, b + ActionBarHeight()); } } else { base.OnLayout(changed, l, t, r, b + ActionBarHeight()); } AToolbar bar = _toolbar; bar.BringToFront(); for (var i = 0; i < ChildCount; i++) { AView child = GetChildAt(i); var pageContainer = child.GetType().GetProperty("Child")?.GetValue(child) as IVisualElementRenderer; Page childPage = pageContainer?.Element as Page; if (childPage == null) { return; } bool childHasNavBar = NavigationPage.GetHasNavigationBar(childPage); if (childHasNavBar) { if (navigationPage.BarBackgroundColor != Color.Transparent) { if (navigationPage.CurrentPage.GetType() != typeof(PetProfilePage)) { child.Layout(0, ActionBarHeight(), r, b + ActionBarHeight()); } } else { child.Layout(0, 0, r, b + ActionBarHeight()); } } } }
private void Current_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (e.PropertyName == NavigationPage.HasNavigationBarProperty.PropertyName) { var has = NavigationPage.GetHasNavigationBar(CurrentPage); if (has) { CurrentPage.Layout(_bounds); _bounds = Rectangle.Zero; } else { CurrentPage.Layout(this.Bounds); } } }
void UpdateNavigationBarVisibility(bool animated) { var current = Child; if (current == null || NavigationController == null) { return; } var hasNavBar = NavigationPage.GetHasNavigationBar(current); if (NavigationController.NavigationBarHidden == hasNavBar) { NavigationController.SetNavigationBarHidden(!hasNavBar, animated); } }
public override void ViewDidLayoutSubviews() { base.ViewDidLayoutSubviews(); if (Current == null) { return; } UpdateToolBarVisible(); var navBarFrameBottom = Math.Min(NavigationBar.Frame.Bottom, 140); _navigationBottom = (nfloat)navBarFrameBottom; var toolbar = _secondaryToolbar; //save the state of the Current page we are calculating, this will fire before Current is updated _hasNavigationBar = NavigationPage.GetHasNavigationBar(Current); // Use 0 if the NavBar is hidden or will be hidden var toolbarY = NavigationBarHidden || NavigationBar.Translucent || !_hasNavigationBar ? 0 : navBarFrameBottom; toolbar.Frame = new RectangleF(0, toolbarY, View.Frame.Width, toolbar.Frame.Height); double trueBottom = toolbar.Hidden ? toolbarY : toolbar.Frame.Bottom; var modelSize = _queuedSize.IsZero ? Element.Bounds.Size : _queuedSize; PageController.ContainerArea = new Rectangle(0, toolbar.Hidden ? 0 : toolbar.Frame.Height, modelSize.Width, modelSize.Height - trueBottom); if (!_queuedSize.IsZero) { Element.Layout(new Rectangle(Element.X, Element.Y, _queuedSize.Width, _queuedSize.Height)); _queuedSize = Size.Zero; } _loaded = true; foreach (var view in View.Subviews) { if (view == NavigationBar || view == _secondaryToolbar) { continue; } view.Frame = View.Bounds; } }
/// <summary> /// On size allocation. /// </summary> /// <param name="width">Width.</param> /// <param name="height">Height.</param> protected override void OnSizeAllocated(double width, double height) { //Permet d'afficher correctement la bar de status sur iOS if (Device.RuntimePlatform == Device.iOS) { mainLayout.Margin = App.NativeUtilities.GetStatusBarHidden() || NavigationPage.GetHasNavigationBar(this) ? new Thickness(0, 0, 0, 0) : new Thickness(0, 20, 0, 0); } var w = bodyLayout.Width / 2; leftEntryLayout.WidthRequest = w; rightEntryLayout.WidthRequest = w; var h = usernameEntry.Measure(rightEntryLayout.Width, rightEntryLayout.Height).Request.Height; lblCourriel.HeightRequest = h; lblPassword.HeightRequest = h; bottomButtonLayout.Padding = new Thickness(width * 0.1, 0); base.OnSizeAllocated(width, height); }
void UpdateTitleVisible() { UpdateTitleOnParents(); bool showing = _container.TitleVisibility == Visibility.Visible; bool newValue = GetIsNavBarPossible() && NavigationPage.GetHasNavigationBar(_currentPage); if (showing == newValue) { return; } _container.TitleVisibility = newValue ? Visibility.Visible : Visibility.Collapsed; // Force ContentHeight/Width to update, doesn't work from inside PageControl for some reason _container.UpdateLayout(); UpdateContainerArea(); }
void UpdateNavigationBarVisibility(bool animated) { var current = Child; if (current == null || NavigationController == null) { return; } var hasNavBar = NavigationPage.GetHasNavigationBar(current); if (NavigationController.NavigationBarHidden == hasNavBar) { // prevent bottom content "jumping" current.IgnoresContainerArea = !hasNavBar; NavigationController.SetNavigationBarHidden(!hasNavBar, animated); } }
#pragma warning disable 1998 // considered for removal async void UpdateTitleOnParents() #pragma warning restore 1998 { if (Element == null) { return; } ITitleProvider render = null; if (_parentTabbedPage != null) { render = Platform.GetRenderer(_parentTabbedPage) as ITitleProvider; if (render != null) { render.ShowTitle = (_parentTabbedPage.CurrentPage == Element) && NavigationPage.GetHasNavigationBar(_currentPage); } } if (_parentMasterDetailPage != null) { render = Platform.GetRenderer(_parentMasterDetailPage) as ITitleProvider; if (render != null) { render.ShowTitle = (_parentMasterDetailPage.Detail == Element) && NavigationPage.GetHasNavigationBar(_currentPage); } } if (render != null && render.ShowTitle) { render.Title = _currentPage.Title; render.BarBackgroundBrush = GetBarBackgroundBrush(); render.BarForegroundBrush = GetBarForegroundBrush(); #if WINDOWS_UWP await(Element.Platform as Platform).UpdateToolbarItems(); #endif } else if (_showTitle) { #if WINDOWS_UWP await(Element.Platform as Platform).UpdateToolbarItems(); #endif } }
/// <summary> /// On size allocation. /// </summary> /// <param name="width">Width.</param> /// <param name="height">Height.</param> protected override void OnSizeAllocated(double width, double height) { //Permet d'afficher correctement la bar de status sur iOS if (Device.RuntimePlatform == Device.iOS) { mainLayout.Margin = App.NativeUtilities.GetStatusBarHidden() || NavigationPage.GetHasNavigationBar(this) ? new Thickness(0, 0, 0, 0) : new Thickness(0, 20, 0, 0); } labelLatitude.HeightRequest = entryLatitude.Height; labelRadius.HeightRequest = radiusPicker.Height; labelLongitude.HeightRequest = entryLongitude.Height; double size = (btnLayout.Width - btnLayout.Spacing) * 0.5; btnSave.WidthRequest = size; btnCancel.WidthRequest = size; typeEnterLayout.WidthRequest = typeLayout.Width / 2; typeExitLayout.WidthRequest = typeLayout.Width / 2; base.OnSizeAllocated(width, height); }
public void RestoreModalOverlay(View page) { if (NavigationBar == null) { NavigationBar = NavigationPage.GetHasNavigationBar(this); NavigationPage.SetHasNavigationBar(this, false); } try { PART_Modal.Content = page; PART_Modal.IsVisible = true; PART_Modal.TranslationY = this.Height; PART_Modal.TranslateTo(0, 0); } catch (Exception) { throw; } }
public MultiGallery() { var button = new Button { Text = "Toggle Nav Bar" }; Content = new ScrollView { Content = new StackLayout { Children = { button, new Editor(), new Entry(), new Image { Source = ImageSource.FromFile("cover1.jpg") }, new Label { Text = "Label" }, new ProgressBar(), new ActivityIndicator(), new Switch(), new Stepper(), new Slider(), new ProgressBar(), new ActivityIndicator(), new Switch(), new Stepper(), new Slider() } } }; button.Clicked += (sender, args) => NavigationPage.SetHasNavigationBar(this, !NavigationPage.GetHasNavigationBar(this)); ToolbarItems.Add(new ToolbarItem("Back", "bank.png", () => Navigation.PopAsync(), ToolbarItemOrder.Primary)); ToolbarItems.Add(new ToolbarItem("It's", "bank.png", () => Navigation.PopAsync(), ToolbarItemOrder.Secondary)); ToolbarItems.Add(new ToolbarItem("A", "bank.png", () => Navigation.PopAsync(), ToolbarItemOrder.Secondary)); ToolbarItems.Add(new ToolbarItem("TARP!", "bank.png", () => Navigation.PopAsync(), ToolbarItemOrder.Secondary)); }
protected override void OnLayout(bool changed, int l, int t, int r, int b) { base.OnLayout(changed, l, t, r, b); AToolbar bar = _toolbar; bar.BringToFront(); //int barHeight = ActionBarHeight(); //bar.Measure(MeasureSpecFactory.MakeMeasureSpec(r - l, MeasureSpecMode.Exactly), MeasureSpecFactory.MakeMeasureSpec(barHeight, MeasureSpecMode.Exactly)); //var barOffset = ToolbarVisible ? barHeight : 0; //int containerHeight = b - t - ContainerPadding; //PageController.ContainerArea = new Rectangle(0, 0, Context.FromPixels(r - l), Context.FromPixels(containerHeight)); for (var i = 0; i < ChildCount; i++) { AView child = GetChildAt(i); var pageContainer = child.GetType().GetProperty("Child")?.GetValue(child) as IVisualElementRenderer; Page childPage = pageContainer?.Element as Page; if (childPage == null) { return; } // We need to base the layout of both the child and the bar on the presence of the NavBar on the child Page itself. // If we layout the bar based on ToolbarVisible, we get a white bar flashing at the top of the screen. // If we layout the child based on ToolbarVisible, we get a white bar flashing at the bottom of the screen. bool childHasNavBar = NavigationPage.GetHasNavigationBar(childPage); if (childHasNavBar) { //bar.Layout(0, 0, r - l, barHeight); child.Layout(0, 0, r, b); } } }
private bool HasAncestorNavigationPage(TPage page) { bool hasParentNavigation = false; TPage parent; TPage current = page; while ((parent = current.Parent as TPage) != null) { hasParentNavigation = parent is NavigationPage; if (hasParentNavigation) { break; } current = parent; } return(hasParentNavigation && NavigationPage.GetHasNavigationBar(parent)); }
public override void WillShowViewController(UINavigationController navigationController, [Transient] UIViewController viewController, bool animated) { var element = _self.ElementForViewController(viewController); bool navBarVisible = true; if (element is BindableObject bo) { navBarVisible = NavigationPage.GetHasNavigationBar(bo); } navigationController.SetNavigationBarHidden(!navBarVisible, true); var coordinator = viewController.GetTransitionCoordinator(); if (coordinator != null && coordinator.IsInteractive) { // handle swipe to dismiss gesture coordinator.NotifyWhenInteractionChanges(OnInteractionChanged); } }
public Page1() { Title = "Page 1"; BackgroundColor = Color.Gray; var relativeLayout = new RelativeLayout { }; relativeLayout.Children.Add(new StackLayout { VerticalOptions = LayoutOptions.Center, Children = { new Label { HorizontalTextAlignment = TextAlignment.Center, Text = "Page 1", TextColor = Color.White }, new Button { Text = "Go to page 2", Command = new Command(async () => await Navigation.PushAsync(new Page2())), AutomationId = Button1, TextColor = Color.White }, new Button { Text = "Toggle Nav Bar", Command = new Command(() => NavigationPage.SetHasNavigationBar(this, !NavigationPage.GetHasNavigationBar(this))), TextColor = Color.White } } }, yConstraint: Xamarin.Forms.Constraint.RelativeToParent(parent => { return parent.Y; })); relativeLayout.Children.Add(new Label { Text = BottomLabel, TextColor = Color.White }, yConstraint: Xamarin.Forms.Constraint.RelativeToParent(parent => { return parent.Height - 30; })); Content = relativeLayout; NavigationPage.SetHasNavigationBar(this, false); }
private void ShowNavigationBar(bool showNavBarNow) { if (_hideNavBarFeature == true && this.Parent != null) { if (showNavBarNow == false && NavigationPage.GetHasNavigationBar(this.Parent) == true) { Device.OnPlatform(iOS: () => { this.Padding = new Thickness(0, 20, 0, 0); }); NavigationPage.SetHasNavigationBar(this.Parent, false); } if (showNavBarNow == true && NavigationPage.GetHasNavigationBar(this.Parent) == false) { Device.OnPlatform(iOS: () => { this.Padding = new Thickness(0, 0, 0, 0); }); NavigationPage.SetHasNavigationBar(this.Parent, true); } } }
public override void ViewDidLayoutSubviews() { base.ViewDidLayoutSubviews(); UpdateToolBarVisible(); //var navBarFrameBotton = Forms.IsiOS11OrNewer ? View.SafeAreaInsets.Top : NavigationBar.Frame.Bottom; var navBarFrameBotton = NavigationBar.Frame.Bottom; var toolbar = _secondaryToolbar; // Use 0 if the NavBar is hidden or will be hidden var toolbarY = NavigationBarHidden || NavigationBar.Translucent || !NavigationPage.GetHasNavigationBar(Current) ? 0 : navBarFrameBotton; toolbar.Frame = new RectangleF(0, toolbarY, View.Frame.Width, toolbar.Frame.Height); double trueBottom = toolbar.Hidden ? toolbarY : toolbar.Frame.Bottom; var modelSize = _queuedSize.IsZero ? Element.Bounds.Size : _queuedSize; PageController.ContainerArea = new Rectangle(0, toolbar.Hidden ? 0 : toolbar.Frame.Height, modelSize.Width, modelSize.Height - trueBottom); if (!_queuedSize.IsZero) { Element.Layout(new Rectangle(Element.X, Element.Y, _queuedSize.Width, _queuedSize.Height)); _queuedSize = Size.Zero; } _loaded = true; foreach (var view in View.Subviews) { if (view == NavigationBar || view == _secondaryToolbar) { continue; } view.Frame = View.Bounds; } }
void UpdateToolbarVisibility() { bool showNavBar = NavigationPage.GetHasNavigationBar(CurrentPage); if (!showNavBar) { if (AppBar.LayoutParameters is CoordinatorLayout.LayoutParams cl) { cl.Height = 0; AppBar.LayoutParameters = cl; } } else { if (AppBar.LayoutParameters is CoordinatorLayout.LayoutParams cl) { if (NavigationView.IsSet(BarHeightProperty)) { cl.Height = NavigationView.OnThisPlatform().GetBarHeight(); } else { cl.Height = ActionBarHeight(); } AppBar.LayoutParameters = cl; } } int ActionBarHeight() { int actionBarHeight = (int)NavigationLayout.Context.GetThemeAttributePixels(Resource.Attribute.actionBarSize); return(actionBarHeight); } }