Exemplo n.º 1
0
        public CGSize CollectionView(UICollectionView collectionView, UICollectionViewLayout collectionViewLayout,
                                     NSIndexPath indexPath)
        {
            if (!(collectionViewLayout is UICollectionViewFlowLayout layout))
            {
                throw new ImagePickerException("currently only UICollectionViewFlowLayout is supported");
            }

            var layoutModel = new LayoutModel(Configuration, 0);

            switch (indexPath.Section)
            {
            case 0:
                //this will make sure that action item is either square if there are 2 items,
                //or a recatangle if there is only 1 item
                //let width = sizeForItem(numberOfItemsInRow: 2, preferredWidthOrHeight: nil, collectionView: collectionView, scrollDirection: layout.scrollDirection).width
                nfloat ratio = 0.25f;
                nfloat width = collectionView.Frame.Width * ratio;
                return(SizeForItem(layoutModel.NumberOfItems(Configuration.SectionIndexForActions),
                                   width, collectionView, layout.ScrollDirection));

            case 1:
                //lets keep this ratio so camera item is a nice rectangle

                var traitCollection = collectionView.TraitCollection;

                ratio = 160f / 212f;

                switch (traitCollection.UserInterfaceIdiom)
                {
                case var _
                    when traitCollection.HorizontalSizeClass == UIUserInterfaceSizeClass.Unspecified &&
                    traitCollection.VerticalSizeClass == UIUserInterfaceSizeClass.Compact:
                case var _ when traitCollection.HorizontalSizeClass == UIUserInterfaceSizeClass.Regular &&
                    traitCollection.VerticalSizeClass == UIUserInterfaceSizeClass.Compact:
                case var _ when traitCollection.HorizontalSizeClass == UIUserInterfaceSizeClass.Compact &&
                    traitCollection.VerticalSizeClass == UIUserInterfaceSizeClass.Compact:
                    ratio = 1 / ratio;
                    break;
                }

                var widthOrHeight = collectionView.Frame.Height * ratio;
                return(SizeForItem(layoutModel.NumberOfItems(Configuration.SectionIndexForCamera),
                                   widthOrHeight, collectionView, layout.ScrollDirection));

            case 2:
                //make sure there is at least 1 item, othewise invalid layout
                if (Configuration.NumberOfAssetItemsInRow < 0)
                {
                    throw new ImagePickerException(
                              "invalid layout - numberOfAssetItemsInRow must be > 0, check your layout configuration ");
                }

                return(SizeForItem(Configuration.NumberOfAssetItemsInRow, null, collectionView,
                                   layout.ScrollDirection));

            default:
                throw new ImagePickerException("unexpected sections count");
            }
        }
Exemplo n.º 2
0
 public override nint GetItemsCount(UICollectionView collectionView, nint section)
 {
     return(_layoutModel.NumberOfItems((int)section));
 }