void InitializeComponent() { SetAlignment(-1, -1); SetWeight(1, 1); SetLayoutCallback(OnLayout); _viewStack = new SimpleViewStack(Forms.NativeParent); if (Device.Idiom == TargetIdiom.Phone) { _viewStack.BackgroundColor = ElmSharp.Color.White; } _viewStack.Show(); PackEnd(_viewStack); _navBar = new ShellNavBar(); _navBar.Show(); PackEnd(_navBar); IShellSectionController controller = ShellSection; controller.NavigationRequested += OnNavigationRequested; controller.AddDisplayedPageObserver(this, UpdateDisplayedPage); ((IShellController)Shell.Current).AddAppearanceObserver(this, ShellSection); ((IShellController)Shell.Current).AddFlyoutBehaviorObserver(_navBar); _shellSectionRenderer = CreateShellSectionRenderer(ShellSection); _shellSectionRenderer.NativeView.Show(); _viewStack.Push(_shellSectionRenderer.NativeView); Device.BeginInvokeOnMainThread(() => { (_shellSectionRenderer.NativeView as Widget)?.SetFocus(true); }); }
public ShellSectionNavigation(IFlyoutController flyoutController, ShellSection section) : base(Forms.NativeParent) { _section = section; _section.PropertyChanged += OnSectionPropertyChanged; _rootPage = ((IShellContentController)_section.CurrentItem).GetOrCreateContent(); _navBar = new ShellNavBar(flyoutController, this); _navBar.Show(); var renderer = CreateShellSection(section); renderer.Control.Show(); _navigationStack.AddLast(renderer.Control); _pageToNative[_rootPage] = renderer.Control; _nativeToPage[renderer.Control] = _rootPage; IShellSectionController controller = _section as IShellSectionController; controller.NavigationRequested += OnNavigationRequested; controller.AddDisplayedPageObserver(this, UpdateDisplayedPage); PackEnd(_navBar); PackEnd(renderer.Control); LayoutUpdated += OnLayoutUpdated; ((IShellController)_section.Parent.Parent).AddAppearanceObserver(this, _section); }
void OnLayout() { if (Geometry.Width == 0 || Geometry.Height == 0) { return; } var bound = Geometry; int navBarHeight; if (_navBarIsVisible) { var navBound = bound; navBarHeight = Forms.ConvertToScaledPixel(_navBar.GetDefaultHeight()); navBound.Height = navBarHeight; _navBar.Show(); _navBar.Geometry = navBound; _navBar.RaiseTop(); } else { navBarHeight = 0; _navBar.Hide(); } bound.Y += navBarHeight; bound.Height -= navBarHeight; _viewStack.Geometry = bound; }
void OnLayoutUpdated(object sender, LayoutEventArgs e) { if (_navBarIsVisible) { _navBarHeight = _defaultNavBarHeight; _navBar.Show(); _navBar.Move(e.Geometry.X, e.Geometry.Y); _navBar.Resize(e.Geometry.Width, _navBarHeight); } else { _navBarHeight = 0; _navBar.Hide(); } CurrentNative.Show(); CurrentNative.Move(e.Geometry.X, e.Geometry.Y + _navBarHeight); CurrentNative.Resize(e.Geometry.Width, e.Geometry.Height - _navBarHeight); }