Example #1
0
        public override void ViewDidAppear(bool animated)
        {
            base.ViewDidAppear(animated);

            customizedTab = new CurvedBottomNavigationView();
            element       = Element as CurvedBottomTabbedPage;

            customizedTab.Frame                   = this.TabBar.Frame;
            customizedTab.Items                   = this.TabBar.Items;
            customizedTab.SelectedItem            = this.TabBar.SelectedItem;
            customizedTab.TintColor               = this.TabBar.TintColor;
            customizedTab.UnselectedItemTintColor = this.TabBar.UnselectedItemTintColor;
            customizedTab.BarBackgroundColor      = this.TabBar.BarTintColor;
            customizedTab.BackgroundColor         = Xamarin.Forms.Color.Transparent.ToUIColor();
            customizedTab.ItemSpacing             = 4f;
            customizedTab.ClipsToBounds           = true;
            this.TabBar.RemoveFromSuperview();

            SetMenuItems();

            // Creates a Button
            var appButton = new UIButton(UIButtonType.Custom);

            UIImage imageAppButtonButton = UIImage.FromBundle(element.FabIcon);

            if (imageAppButtonButton != null)
            {
                appButton.SetImage(imageAppButtonButton, UIControlState.Normal);
            }

            // Sets width and height to the Button
            appButton.Frame = new CGRect(0.0f, 0.0f, 48, 48);

            //appButton.SetBackgroundImage(imageAppButtonButton, UIControlState.Normal);
            appButton.BackgroundColor = UIColor.FromCGColor(element.FabBackgroundColor.ToCGColor());

            CGPoint centers = TabBar.Center;

            centers.Y        = this.customizedTab.Frame.Y;
            appButton.Center = centers;

            var eventHandler = new EventHandler(ButtonClick);

            appButton.AddTarget(eventHandler, events: UIControlEvent.TouchUpInside);

            //Create shadow effect
            appButton.Layer.ShadowColor   = UIColor.Black.CGColor;
            appButton.Layer.ShadowOffset  = new CGSize(width: 0.0, height: 5.0);
            appButton.Layer.ShadowOpacity = 0.5f;
            appButton.Layer.ShadowRadius  = 2.0f;
            appButton.Layer.MasksToBounds = false;
            appButton.Layer.CornerRadius  = 24;

            // Adds the Button to the view
            View.Add(customizedTab);
            View.AddSubview(appButton);
        }
        protected override void OnElementChanged(ElementChangedEventArgs <TabbedPage> e)
        {
            base.OnElementChanged(e);

            try
            {
                element = Element as CurvedBottomTabbedPage;

                var metrics = Resources.DisplayMetrics;
                var width   = metrics.WidthPixels;
                var height  = metrics.HeightPixels;

                if (!(GetChildAt(0) is ViewGroup layout))
                {
                    return;
                }

                if (!(layout.GetChildAt(1) is BottomNavigationView bottomNavigationView))
                {
                    return;
                }

                bottomNavigationView.RemoveFromParent();
                bottomNavigationView.RemoveAllViews();
                bottomNavigationView.RemoveAllViewsInLayout();

                var bottomView = LayoutInflater.From(Context).Inflate(Resource.Layout.BottomNavBar, null);

                bottombar = bottomView.FindViewById <CurvedBottomNavigationView>(Resource.Id.bottom_nav_bar);
                bottombar.RemoveFromParent();
                actionbutton = bottomView.FindViewById <FloatingActionButton>(Resource.Id.fab);
                actionbutton.RemoveFromParent();

                SetTabItems();
                SettingUpMenu();
                OnChildrenCollectionChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset));

                SetFabProperties();
                actionbutton.Click += Actionbutton_Click;

                bottombar.LabelVisibilityMode = LabelVisibilityMode.LabelVisibilityLabeled;
                layout.AddView(actionbutton);
                layout.AddView(bottombar);
                bottombar.SetZ(0);

                UpdateBarBackgroundColor();
                UpdateBarTextColor();
                UpdateItemIconColor();
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Example #3
0
        public static void SetShiftMode(this CurvedBottomNavigationView bottomNavigationView, bool enableShiftMode, bool enableItemShiftMode)
        {
            try
            {
                var menuView = bottomNavigationView.GetChildAt(0) as BottomNavigationMenuView;
                if (menuView == null)
                {
                    System.Diagnostics.Debug.WriteLine("Unable to find BottomNavigationMenuView");
                    return;
                }

                var shiftMode = menuView.Class.GetDeclaredField("mShiftingMode");

                shiftMode.Accessible = true;
                shiftMode.SetBoolean(menuView, enableShiftMode);
                shiftMode.Accessible = false;
                shiftMode.Dispose();


                for (int i = 0; i < menuView.ChildCount; i++)
                {
                    var item = menuView.GetChildAt(i) as BottomNavigationItemView;
                    if (item == null)
                    {
                        continue;
                    }

                    item.SetShiftingMode(enableItemShiftMode);
                    item.SetChecked(item.ItemData.IsChecked);
                }

                menuView.UpdateMenuView();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine($"Unable to set shift mode: {ex}");
            }
        }
 public BottomNavTabPageRenderer()
 {
     customizedTab = new CurvedBottomNavigationView();
 }