public override void ViewDidLayoutSubviews()
        {
            base.ViewDidLayoutSubviews();
            if (isViewAppearing || isViewRotating)
            {
                // Force the UICollectionViewFlowLayout to get laid out again with the new size if
                // a) The view is appearing.  This ensures that
                //    collectionView:layout:sizeForItemAtIndexPath: is called for a second time
                //    when the view is shown and when the view *frame(s)* are actually set
                //    (we need the view frame's to have been set to work out the size's and on the
                //    first call to collectionView:layout:sizeForItemAtIndexPath: the view frame(s)
                //    aren't set correctly)
                // b) The view is rotating.  This ensures that
                //    collectionView:layout:sizeForItemAtIndexPath: is called again and can use the views
                //    *new* frame so that the buttonBarView cell's actually get resized correctly
                CachedCellWidths = CalculateWidths();
                ButtonBarView.CollectionViewLayout.InvalidateLayout();

                // When the view first appears or is rotated we also need to ensure that the barButtonView's
                // selectedBar is resized and its contentOffset/scroll is set correctly (the selected
                // tab/cell may end up either skewed or off screen after a rotation otherwise)
                ButtonBarView.MoveToIndex((int)CurrentIndex, animated: false, swipeDirection: SwipeDirection.None, pagerScroll: PagerScroll.ScrollOnlyIfOutOfScreen);
                ButtonBarView.SelectItem(NSIndexPath.FromRowSection((System.nint)CurrentIndex, 0), false, UICollectionViewScrollPosition.None);
            }
        }
 public override void ReloadPagerTabStripView()
 {
     base.ReloadPagerTabStripView();
     if (IsViewLoaded)
     {
         ButtonBarView.ReloadData();
         cachedCellWidths = CalculateWidths();
         ButtonBarView.MoveToIndex((int)CurrentIndex, animated: false, swipeDirection: SwipeDirection.None, pagerScroll: PagerScroll.Yes);
     }
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            if (ButtonBarView == null)
            {
                ButtonBarView = InitializeButtonBarView();
            }

            if (CachedCellWidths == null)
            {
                CachedCellWidths = CalculateWidths();
            }

            if (ButtonBarView.Superview == null)
            {
                View.AddSubview(ButtonBarView);
            }
            if (ButtonBarView.Delegate == null)
            {
                ButtonBarView.Delegate = this;
            }
            if (ButtonBarView.DataSource == null)
            {
                ButtonBarView.DataSource = this;
            }
            ButtonBarView.ScrollsToTop = false;
            var flowLayout = ButtonBarView.CollectionViewLayout as UICollectionViewFlowLayout;

            flowLayout.ScrollDirection         = UICollectionViewScrollDirection.Horizontal;
            flowLayout.MinimumInteritemSpacing = Settings.Style.ButtonBarMinimumInteritemSpacing ?? flowLayout.MinimumLineSpacing;
            flowLayout.MinimumLineSpacing      = Settings.Style.ButtonBarMinimumLineSpacing ?? flowLayout.MinimumLineSpacing;
            var sectionInset = flowLayout.SectionInset;

            flowLayout.SectionInset = new UIEdgeInsets(sectionInset.Top, Settings.Style.ButtonBarLeftContentInset ?? sectionInset.Left,
                                                       sectionInset.Bottom, Settings.Style.ButtonBarRightContentInset ?? sectionInset.Right);

            ButtonBarView.ShowsHorizontalScrollIndicator = false;
            ButtonBarView.BackgroundColor             = Settings.Style.ButtonBarBackgroundColor ?? ButtonBarView.BackgroundColor;
            ButtonBarView.SelectedBar.BackgroundColor = Settings.Style.SelectedBarBackgroundColor;

            ButtonBarView.SelectedBarHeight            = Settings.Style.SelectedBarHeight ?? ButtonBarView.SelectedBarHeight;
            ButtonBarView.SelectedBarWidth             = Settings.Style.SelectedBarWidth ?? ButtonBarView.SelectedBarWidth;
            ButtonBarView.SelectedBarVerticalAlignment = Settings.Style.SelectedBarVerticalAlignment;

            //register button bar item cell
            if (ButtonBarItemSpec.NibName != null)
            {
                ButtonBarView.RegisterNibForCell(UINib.FromName(ButtonBarItemSpec.NibName, ButtonBarItemSpec.Bundle), "Cell");
            }
            else
            {
                ButtonBarView.RegisterClassForCell(typeof(ButtonBarViewCell), "Cell");
            }
        }
 public void PagerTabStripViewController(PagerTabStripViewController pagerTabStripViewController, int fromIndex, int toIndex, nfloat progressPercentage, bool indexWasChanged)
 {
     if (shouldUpdateButtonBarView)
     {
         ButtonBarView.MoveFromIndex(fromIndex, toIndex: toIndex, progressPercentage: progressPercentage, pagerScroll: PagerScroll.Yes);
         if (ChangeCurrentIndexProgressive != null)
         {
             var oldCell = ButtonBarView.CellForItem(NSIndexPath.FromItemSection(new nint(CurrentIndex != fromIndex ? fromIndex : toIndex), 0)) as ButtonBarViewCell;
             var newCell = ButtonBarView.CellForItem(NSIndexPath.FromItemSection(new nint(CurrentIndex), 0)) as ButtonBarViewCell;
             ChangeCurrentIndexProgressive(oldCell, newCell, progressPercentage, indexWasChanged, true);
         }
     }
 }
 public void PagerTabStripViewController(PagerTabStripViewController pagerTabStripViewController, int fromIndex, int toIndex)
 {
     if (shouldUpdateButtonBarView)
     {
         ButtonBarView.MoveToIndex(toIndex, animated: true, swipeDirection: toIndex < fromIndex ? SwipeDirection.Right : SwipeDirection.Left, pagerScroll: PagerScroll.Yes);
         if (ChangeCurrentIndex != null)
         {
             var oldCell = ButtonBarView.CellForItem(NSIndexPath.FromItemSection(new nint(CurrentIndex != fromIndex ? fromIndex : toIndex), 0)) as ButtonBarViewCell;
             var newCell = ButtonBarView.CellForItem(NSIndexPath.FromItemSection(new nint(CurrentIndex), 0)) as ButtonBarViewCell;
             ChangeCurrentIndex(oldCell, newCell, true);
         }
     }
 }
        private ButtonBarView InitializeButtonBarView()
        {
            UICollectionViewFlowLayout flowLayout = new UICollectionViewFlowLayout();

            flowLayout.ScrollDirection = UICollectionViewScrollDirection.Horizontal;
            var buttonBarHeight = new nfloat(Settings.Style.ButtonBarHeight ?? 44f);
            var buttonBar       = new ButtonBarView(frame: new CGRect(0, 0, View.Frame.Size.Width, buttonBarHeight), layout: flowLayout);

            buttonBar.BackgroundColor             = Settings.Style.ButtonBarBackgroundColor ?? UIColor.Orange;
            buttonBar.SelectedBar.BackgroundColor = Settings.Style.SelectedBarBackgroundColor ?? UIColor.Black;
            buttonBar.AutoresizingMask            = UIViewAutoresizing.FlexibleWidth;
            var newContainerViewFrame = new CGRect(ContainerView.Frame.X, buttonBarHeight, ContainerView.Frame.Size.Width, ContainerView.Frame.Size.Height - (buttonBarHeight - ContainerView.Frame.Y));

            ContainerView.Frame = newContainerViewFrame;
            return(buttonBar);
        }
        public void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
        {
            if (indexPath.Item != CurrentIndex)
            {
                ButtonBarView.MoveToIndex((int)indexPath.Item, true, SwipeDirection.None, PagerScroll.Yes);
                shouldUpdateButtonBarView = false;

                var oldCell = ButtonBarView.CellForItem(NSIndexPath.FromItemSection(new nint(CurrentIndex), 0)) as ButtonBarViewCell;
                var newCell = ButtonBarView.CellForItem(NSIndexPath.FromItemSection(indexPath.Item, 0)) as ButtonBarViewCell;

                if (PagerBehaviour.IsProgressiveIndicator)
                {
                    ChangeCurrentIndexProgressive?.Invoke(oldCell, newCell, 1, true, true);
                }
                else
                {
                    ChangeCurrentIndex?.Invoke(oldCell, newCell, true);
                }
                MoveToViewControllerAtIndex((uint)indexPath.Item);
            }
        }
 public override void ViewWillAppear(bool animated)
 {
     base.ViewWillAppear(animated);
     ButtonBarView.LayoutIfNeeded();
 }