public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            var view = base.OnCreateView(inflater, container, savedInstanceState);

            _bottomNavigationView = view.FindViewById <BottomNavigationViewEx>(Resource.Id.bottom_navigation_view);
            _bottomNavigationView?.SetOnNavigationItemSelectedListener(this);
            _bottomNavigationView?.SetOnNavigationItemReselectedListener(this);

            _bottomNavigationView?.Menu?.FindItem(Resource.Id.i_unchecked)?.SetChecked(true);
            var uncheckedItem = _bottomNavigationView?.FindViewById(Resource.Id.i_unchecked);

            if (uncheckedItem != null)
            {
                uncheckedItem.Visibility = ViewStates.Gone;
            }

            _bottomNavigationView?.EnableShiftingMode(false);

            var bindingSet = this.CreateBindingSet <BottomNavigationView, BottomNavigationViewModel>();

            bindingSet.Bind(this).For(h => h.CheckedItem).To(vm => vm.CheckedItem);
            bindingSet.Apply();

            if (savedInstanceState == null)
            {
            }

            return(view);
        }
        public static BottomNavigationViewEx SetupBottomBar(this ExtendedTabbedPageRenderer renderer,
                                                            global::Android.Widget.RelativeLayout rootLayout, BottomNavigationViewEx bottomNav, int barId)
        {
            if (bottomNav != null)
            {
                rootLayout.RemoveView(bottomNav);
                bottomNav.SetOnNavigationItemSelectedListener(null);
            }

            var barParams = new global::Android.Widget.RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MatchParent,
                ExtendedTabbedPageRenderer.BottomBarHeight.HasValue ?
                (int)rootLayout.Context.ToPixels(ExtendedTabbedPageRenderer.BottomBarHeight.Value) :
                ViewGroup.LayoutParams.WrapContent);

            barParams.AddRule(LayoutRules.AlignParentBottom);
            bottomNav = new BottomNavigationViewEx(rootLayout.Context)
            {
                LayoutParameters = barParams,
                Id = barId
            };
            if (ExtendedTabbedPageRenderer.BackgroundColor.HasValue)
            {
                bottomNav.SetBackgroundColor(ExtendedTabbedPageRenderer.BackgroundColor.Value);
            }

            bottomNav.SetOnNavigationItemSelectedListener(renderer);
            rootLayout.AddView(bottomNav, 1, barParams);

            return(bottomNav);
        }
Beispiel #3
0
        protected override void Dispose(bool disposing)
        {
            if (disposing && !_disposed)
            {
                _disposed = true;

                RemoveAllViews();

                foreach (Page pageToRemove in Element.Children)
                {
                    IVisualElementRenderer pageRenderer = Platform.GetRenderer(pageToRemove);

                    if (pageRenderer != null)
                    {
                        pageRenderer.ViewGroup.RemoveFromParent();
                        pageRenderer.Dispose();
                    }
                }

                if (_bottomBar != null)
                {
                    _bottomBar.SetOnNavigationItemSelectedListener(null);
                    _bottomBar.Dispose();
                    _bottomBar = null;
                }

                if (_frameLayout != null)
                {
                    _frameLayout.Dispose();
                    _frameLayout = null;
                }
            }

            base.Dispose(disposing);
        }
        protected override void Dispose(bool disposing)
        {
            if (disposing)
            {
                Element.ChildAdded        -= PagesChanged;
                Element.ChildRemoved      -= PagesChanged;
                Element.ChildrenReordered -= PagesChanged;

                if (_rootLayout != null)
                {
                    RemoveAllViews();
                    foreach (Page pageToRemove in Element.Children)
                    {
                        var pageRenderer = Platform.GetRenderer(pageToRemove);
                        if (pageRenderer != null)
                        {
                            pageRenderer.View.RemoveFromParent();
                            pageRenderer.Dispose();
                        }
                    }

                    if (_bottomNav != null)
                    {
                        _bottomNav.SetOnNavigationItemSelectedListener(null);
                        _bottomNav.Dispose();
                        _bottomNav = null;
                    }
                    _rootLayout.Dispose();
                    _rootLayout = null;
                }
            }

            base.Dispose(disposing);
        }
        protected override async void OnElementChanged(ElementChangedEventArgs <BottomBarPage> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                _element = e.NewElement;
                if (_bottomNavigationView == null)
                {
                    _rootLayout = new Android.Widget.RelativeLayout(Context)
                    {
                        LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent)
                    };
                    AddView(_rootLayout);

                    _frameLayout = new FrameLayout(Context)
                    {
                        LayoutParameters = new ActionBar.LayoutParams(LayoutParams.MatchParent,
                                                                      LayoutParams.MatchParent, GravityFlags.Fill)
                    };
                    _rootLayout.AddView(_frameLayout);

                    _bottomNavigationView = new BottomNavigationViewEx(Context)
                    {
                        LayoutParameters =
                            new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent,
                                                                           LayoutParams.WrapContent)
                    };
                    (_bottomNavigationView.LayoutParameters as Android.Widget.RelativeLayout.LayoutParams)?.AddRule(LayoutRules.AlignParentBottom);
                    _bottomNavigationView.SetOnNavigationItemSelectedListener(this);

                    if (_element.BarTextColor != default(Color))
                    {
                        _bottomNavigationView.ItemTextColor    = ColorStateList.ValueOf(_element.BarTextColor.ToAndroid());
                        _bottomNavigationView.ItemIconTintList = ColorStateList.ValueOf(_element.BarTextColor.ToAndroid());
                    }

                    if (_element.BarBackgroundColor != default(Color))
                    {
                        _bottomNavigationView.SetBackgroundColor(_element.BarBackgroundColor.ToAndroid());
                    }

                    foreach (var page in Element.Children)
                    {
                        await AddPage(page);
                    }

                    _rootLayout.AddView(_bottomNavigationView, 1);
                    _bottomNavigationView.EnableShiftingMode(false);
                    _bottomNavigationView.EnableItemShiftingMode(false);
                    ChangeCurrentPage(Element.Children[0]);
                    _element.ChildAdded   += Element_ChildAdded;
                    _element.ChildRemoved += Element_ChildRemoved;
                }
            }
        }
Beispiel #6
0
        public static BottomNavigationViewEx SetupBottomBar(this BottomTabbedRenderer renderer, Android.Widget.RelativeLayout rootLayout, BottomNavigationViewEx bottomNav, int barId)
        {
            if (bottomNav != null)
            {
                rootLayout.RemoveView(bottomNav);
                bottomNav.SetOnNavigationItemSelectedListener(null);
            }

            var barParams = new Android.Widget.RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MatchParent,
                BottomTabbedRenderer.BottomBarHeight.HasValue ? (int)rootLayout.Context.ToPixels(BottomTabbedRenderer.BottomBarHeight.Value) : ViewGroup.LayoutParams.WrapContent);

            //Add alignment rules to close to the lower edge of the parent contro
            barParams.AddRule(LayoutRules.AlignParentBottom);
            bottomNav = new BottomNavigationViewEx(rootLayout.Context)
            {
                LayoutParameters = barParams,
                Id = barId
            };
            if (BottomTabbedRenderer.BackgroundColor.HasValue)
            {
                bottomNav.SetBackgroundColor(BottomTabbedRenderer.BackgroundColor.Value);
            }
            if (BottomTabbedRenderer.ItemIconTintList != null)
            {
                bottomNav.ItemIconTintList = BottomTabbedRenderer.ItemIconTintList;
            }
            if (BottomTabbedRenderer.ItemTextColor != null)
            {
                bottomNav.ItemTextColor = BottomTabbedRenderer.ItemTextColor;
            }
            if (BottomTabbedRenderer.ItemBackgroundResource.HasValue)
            {
                bottomNav.ItemBackgroundResource = BottomTabbedRenderer.ItemBackgroundResource.Value;
            }
            //The listening callback method "setOnNavigationItemSelectedListener()", which defaults to the first entry being the first item selected, can be set by
            //"navigation.getMenu().getItem(index).setChecked(true);"
            bottomNav.SetOnNavigationItemSelectedListener(renderer);
            rootLayout.AddView(bottomNav, 1, barParams);

            return(bottomNav);
        }
        public static BottomNavigationViewEx SetupBottomBar(this BottomTabbedRenderer renderer, Android.Widget.RelativeLayout rootLayout, BottomNavigationViewEx bottomNav, int barId)
        {
            if (bottomNav != null)
            {
                rootLayout.RemoveView(bottomNav);
                bottomNav.SetOnNavigationItemSelectedListener(null);
            }

            var barParams = new Android.Widget.RelativeLayout.LayoutParams(
                ViewGroup.LayoutParams.MatchParent,
                BottomTabbedRenderer.BottomBarHeight.HasValue ? (int)rootLayout.Context.ToPixels(BottomTabbedRenderer.BottomBarHeight.Value) : ViewGroup.LayoutParams.WrapContent);

            barParams.AddRule(LayoutRules.AlignParentBottom);
            bottomNav = new BottomNavigationViewEx(rootLayout.Context)
            {
                LayoutParameters = barParams,
                Id = barId
            };
            if (BottomTabbedRenderer.BackgroundColor.HasValue)
            {
                bottomNav.SetBackgroundColor(BottomTabbedRenderer.BackgroundColor.Value);
            }
            if (BottomTabbedRenderer.ItemIconTintList != null)
            {
                bottomNav.ItemIconTintList = BottomTabbedRenderer.ItemIconTintList;
            }
            if (BottomTabbedRenderer.ItemTextColor != null)
            {
                bottomNav.ItemTextColor = BottomTabbedRenderer.ItemTextColor;
            }
            if (BottomTabbedRenderer.ItemBackgroundResource.HasValue)
            {
                bottomNav.ItemBackgroundResource = BottomTabbedRenderer.ItemBackgroundResource.Value;
            }

            bottomNav.SetOnNavigationItemSelectedListener(renderer);
            rootLayout.AddView(bottomNav, 1, barParams);

            return(bottomNav);
        }
Beispiel #8
0
        protected override void Dispose(bool disposing)
        {
            if (disposing && Element != null)
            {
                Element.ChildAdded        -= PagesChanged;
                Element.ChildRemoved      -= PagesChanged;
                Element.ChildrenReordered -= PagesChanged;

                if (rootLayout != null)
                {
                    //TODO Cleanup
                    RemoveAllViews();
                    foreach (Page pageToRemove in Element.Children)
                    {
                        IVisualElementRenderer pageRenderer = Platform.GetRenderer(pageToRemove);

                        if (pageRenderer != null)
                        {
                            pageRenderer.ViewGroup.RemoveFromParent();
                            pageRenderer.Dispose();
                        }
                    }

                    if (bottomNav != null)
                    {
                        bottomNav.SetOnNavigationItemSelectedListener(null);
                        bottomNav.Dispose();
                        bottomNav = null;
                    }
                    rootLayout.Dispose();
                    rootLayout = null;
                }
            }

            base.Dispose(disposing);
        }
Beispiel #9
0
        protected override void OnElementChanged(ElementChangedEventArgs <BottomTabbedPage> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement != null)
            {
                BottomTabbedPage bottomBarPage = e.NewElement;

                if (_bottomBar == null)
                {
                    _pageController = PageController.Create(bottomBarPage);

                    _rootLayout = new LinearLayout(Context)
                    {
                        LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent)
                    };
                    AddView(_rootLayout);

                    // create a view which will act as container for Page's
                    _frameLayout = new FrameLayout(Context)
                    {
                        LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent)
                    };
                    _rootLayout.AddView(_frameLayout);

                    _bottomBar = new BottomNavigationViewEx(Context)
                    {
                        LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent)
                    };

                    _rootLayout.AddView(_bottomBar);
                    _bottomBar.SetOnNavigationItemSelectedListener(this);

                    if (BackgroundColor.HasValue)
                    {
                        _bottomBar.SetBackgroundColor(BackgroundColor.Value);
                    }

                    if (ItemIconTintList != null)
                    {
                        _bottomBar.ItemIconTintList = ItemIconTintList;
                    }
                    if (ItemTextColor != null)
                    {
                        _bottomBar.ItemTextColor = ItemTextColor;
                    }
                    if (ItemBackgroundResource.HasValue)
                    {
                        _bottomBar.ItemBackgroundResource = ItemBackgroundResource.Value;
                    }
                    // Resource.Drawable.bnv_selector

                    _menu = (BottomNavigationMenu)_bottomBar.Menu;

                    UpdateTabs();
                }

                if (bottomBarPage.CurrentPage != null)
                {
                    SwitchContent(bottomBarPage.CurrentPage);
                }
            }
        }