예제 #1
0
        public override void ViewWillLayoutSubviews()
        {
            base.ViewWillLayoutSubviews();

            // We can't set this constraint up on ViewDidLoad, because Forms does other stuff that resizes the view
            // and we end up with massive layout errors. And View[Will/Did]Appear do not fire for this controller
            // reliably. So until one of those options is cleared up, we set this flag so that the initial constraints
            // are set up the first time this method is called.
            if (!_initialConstraintsSet)
            {
                ItemsViewLayout.ConstrainTo(CollectionView.Bounds.Size);
                _initialConstraintsSet = true;
            }

            // This update is only relevant if you have a footer view because it's used to place the footer view
            // based on the ContentSize so we just update the positions if the ContentSize has changed
            if (_footerUIView != null)
            {
                if (IsHorizontal)
                {
                    if (_footerUIView.Frame.X != ItemsViewLayout.CollectionViewContentSize.Width)
                    {
                        UpdateHeaderFooterPosition();
                    }
                }
                else
                {
                    if (_footerUIView.Frame.Y != ItemsViewLayout.CollectionViewContentSize.Height)
                    {
                        UpdateHeaderFooterPosition();
                    }
                }
            }
        }
예제 #2
0
        void CheckForEmptySource()
        {
            var wasEmpty = _isEmpty;

            _isEmpty = ItemsSource.ItemCount == 0;

            if (_isEmpty)
            {
                _measurementCells.Clear();
                _cellSizeCache.Clear();
            }

            if (wasEmpty != _isEmpty)
            {
                UpdateEmptyViewVisibility(_isEmpty);
            }

            if (wasEmpty && !_isEmpty)
            {
                // If we're going from empty to having stuff, it's possible that we've never actually measured
                // a prototype cell and our itemSize or estimatedItemSize are wrong/unset
                // So trigger a constraint update; if we need a measurement, that will make it happen
                ItemsViewLayout.ConstrainTo(CollectionView.Bounds.Size);
            }
        }
예제 #3
0
        public void UpdateLayout(ItemsViewLayout layout)
        {
            _layout = layout;
            _layout.GetPrototype = GetPrototype;

            // If we're updating from a previous layout, we should keep any settings for the SelectableItemsViewController around
            var selectableItemsViewController = Delegator?.SelectableItemsViewController;

            Delegator = new UICollectionViewDelegator(_layout, this);

            CollectionView.Delegate = Delegator;

            if (CollectionView.CollectionViewLayout != _layout)
            {
                // We're updating from a previous layout

                // Make sure the new layout is sized properly
                _layout.ConstrainTo(CollectionView.Bounds.Size);

                CollectionView.SetCollectionViewLayout(_layout, false);

                // Reload the data so the currently visible cells get laid out according to the new layout
                CollectionView.ReloadData();
            }
        }
예제 #4
0
 protected virtual void BoundsSizeChanged()
 {
     //We are changing orientation and we need to tell our layout
     //to update based on new size constrains
     ItemsViewLayout.ConstrainTo(CollectionView.Bounds.Size);
     //We call ReloadData so our VisibleCells also update their size
     CollectionView.ReloadData();
 }
예제 #5
0
        protected void BoundsSizeChanged()
        {
            ItemsViewLayout.ConstrainTo(CollectionView.Bounds.Size);

            //We call ReloadData so our VisibleCells also update their size
            CollectionView.ReloadData();

            Carousel.ScrollTo(Carousel.Position, position: Xamarin.Forms.ScrollToPosition.Center, animate: false);
        }
        public override void WillAnimateRotation(UIInterfaceOrientation toInterfaceOrientation, double duration)
        {
            //We are changing orientation and we need to tell our layout
            //to update based on new size constrains
            ItemsViewLayout.ConstrainTo(CollectionView.Bounds.Size);
            //We call ReloadData so our VisibleCells also update their size
            CollectionView.ReloadData();

            base.WillAnimateRotation(toInterfaceOrientation, duration);
        }
예제 #7
0
        public override void ViewWillLayoutSubviews()
        {
            base.ViewWillLayoutSubviews();

            // We can't set this constraint up on ViewDidLoad, because Forms does other stuff that resizes the view
            // and we end up with massive layout errors. And View[Will/Did]Appear do not fire for this controller
            // reliably. So until one of those options is cleared up, we set this flag so that the initial constraints
            // are set up the first time this method is called.
            if (!_initialConstraintsSet)
            {
                _layout.ConstrainTo(CollectionView.Bounds.Size);
                _initialConstraintsSet = true;
            }
        }
예제 #8
0
        public void UpdateLayout(ItemsViewLayout newLayout)
        {
            // Ignore calls to this method if the new layout is the same as the old one
            if (CollectionView.CollectionViewLayout == newLayout)
            {
                return;
            }

            ItemsViewLayout = newLayout;
            ItemsViewLayout.GetPrototype = GetPrototype;

            Delegator = CreateDelegator();
            CollectionView.Delegate = Delegator;

            // Make sure the new layout is sized properly
            ItemsViewLayout.ConstrainTo(CollectionView.Bounds.Size);

            CollectionView.SetCollectionViewLayout(ItemsViewLayout, false);

            // Reload the data so the currently visible cells get laid out according to the new layout
            CollectionView.ReloadData();
        }
예제 #9
0
        public void UpdateLayout(ItemsViewLayout layout)
        {
            ItemsViewLayout = layout;
            ItemsViewLayout.GetPrototype = GetPrototype;

            Delegator = CreateDelegator();

            CollectionView.Delegate = Delegator;

            if (CollectionView.CollectionViewLayout != ItemsViewLayout)
            {
                // We're updating from a previous layout

                // Make sure the new layout is sized properly
                ItemsViewLayout.ConstrainTo(CollectionView.Bounds.Size);

                CollectionView.SetCollectionViewLayout(ItemsViewLayout, false);

                // Reload the data so the currently visible cells get laid out according to the new layout
                CollectionView.ReloadData();
            }
        }