Example #1
0
        UICollectionViewLayout CreateLayout()
        {
            var itemSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(1),
                                                         NSCollectionLayoutDimension.CreateFractionalHeight(1));
            var item = NSCollectionLayoutItem.Create(itemSize);

            var groupSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(1),
                                                          NSCollectionLayoutDimension.CreateAbsolute(44));
            var group = NSCollectionLayoutGroup.CreateHorizontal(groupSize, item);

            var section = NSCollectionLayoutSection.Create(group);

            section.InterGroupSpacing = 5;
            section.ContentInsets     = new NSDirectionalEdgeInsets(0, 10, 0, 10);

            var headerFooterSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(1),
                                                                 NSCollectionLayoutDimension.CreateAbsolute(44));
            var sectionHeader = NSCollectionLayoutBoundarySupplementaryItem.Create(headerFooterSize, sectionHeaderElementKind, NSRectAlignment.Top);
            var sectionFooter = NSCollectionLayoutBoundarySupplementaryItem.Create(headerFooterSize, sectionFooterElementKind, NSRectAlignment.Bottom);

            sectionHeader.PinToVisibleBounds   = true;
            sectionHeader.ZIndex               = 2;
            section.BoundarySupplementaryItems = new [] { sectionHeader, sectionFooter };

            var layout = new UICollectionViewCompositionalLayout(section);

            return(layout);
        }
Example #2
0
        UICollectionViewLayout CreateLayout()
        {
            var config = new UICollectionViewCompositionalLayoutConfiguration {
                InterSectionSpacing = 20
            };

            return(new UICollectionViewCompositionalLayout(SectionProviderHandler, config));

            NSCollectionLayoutSection SectionProviderHandler(nint sectionIndex, INSCollectionLayoutEnvironment layoutEnvironment)
            {
                var itemSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(1),
                                                             NSCollectionLayoutDimension.CreateFractionalHeight(1));
                var item = NSCollectionLayoutItem.Create(itemSize);

                // if we have the space, adapt and go 2-up + peeking 3rd item
                var groupFractionalWidth = layoutEnvironment.Container.EffectiveContentSize.Width > 500 ? 0.425f : 0.85f;
                var groupSize            = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(groupFractionalWidth),
                                                                         NSCollectionLayoutDimension.CreateAbsolute(250));
                var group = NSCollectionLayoutGroup.CreateHorizontal(groupSize, item);

                var section = NSCollectionLayoutSection.Create(group);

                section.OrthogonalScrollingBehavior = UICollectionLayoutSectionOrthogonalScrollingBehavior.Continuous;
                section.InterGroupSpacing           = 20;
                section.ContentInsets = new NSDirectionalEdgeInsets(0, 20, 0, 20);

                var titleSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(1),
                                                              NSCollectionLayoutDimension.CreateEstimated(44));
                var titleSupplementary = NSCollectionLayoutBoundarySupplementaryItem.Create(titleSize, titleElementKind, NSRectAlignment.Top);

                section.BoundarySupplementaryItems = new [] { titleSupplementary };

                return(section);
            }
        }
Example #3
0
        //   +-----------------------------------------------------+
        //   | +---------------------------------+  +-----------+  |
        //   | |                                 |  |           |  |
        //   | |                                 |  |           |  |
        //   | |                                 |  |     1     |  |
        //   | |                                 |  |           |  |
        //   | |                                 |  |           |  |
        //   | |                                 |  +-----------+  |
        //   | |               0                 |                 |
        //   | |                                 |  +-----------+  |
        //   | |                                 |  |           |  |
        //   | |                                 |  |           |  |
        //   | |                                 |  |     2     |  |
        //   | |                                 |  |           |  |
        //   | |                                 |  |           |  |
        //   | +---------------------------------+  +-----------+  |
        //   +-----------------------------------------------------+

        UICollectionViewLayout CreateLayout()
        {
            var config = new UICollectionViewCompositionalLayoutConfiguration {
                InterSectionSpacing = 20
            };

            return(new UICollectionViewCompositionalLayout(SectionProviderHandler, config));

            NSCollectionLayoutSection SectionProviderHandler(nint sectionIndex, INSCollectionLayoutEnvironment layoutEnvironment)
            {
                var sectionKind = SectionKind.GetSectionKind(sectionIndex);

                var leadingItemSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(.7f),
                                                                    NSCollectionLayoutDimension.CreateFractionalHeight(1));
                var leadingItem = NSCollectionLayoutItem.Create(leadingItemSize);

                leadingItem.ContentInsets = new NSDirectionalEdgeInsets(10, 10, 10, 10);

                var trailingItemSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(1),
                                                                     NSCollectionLayoutDimension.CreateFractionalHeight(.3f));
                var trailingItem = NSCollectionLayoutItem.Create(trailingItemSize);

                trailingItem.ContentInsets = new NSDirectionalEdgeInsets(10, 10, 10, 10);

                var trailingGroupSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(.3f),
                                                                      NSCollectionLayoutDimension.CreateFractionalHeight(1));
                var trailingGroup = NSCollectionLayoutGroup.CreateVertical(trailingGroupSize, trailingItem, 2);

                var orthogonallyScrolls           = sectionKind.GetOrthogonalScrollingBehavior() != UICollectionLayoutSectionOrthogonalScrollingBehavior.None;
                var containerGroupFractionalWidth = orthogonallyScrolls ? .85f : 1;
                var containerGroupSize            = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(containerGroupFractionalWidth),
                                                                                  NSCollectionLayoutDimension.CreateFractionalHeight(.4f));
                var containerGroup = NSCollectionLayoutGroup.CreateHorizontal(containerGroupSize, leadingItem, trailingGroup);

                var section = NSCollectionLayoutSection.Create(containerGroup);

                section.OrthogonalScrollingBehavior = sectionKind.GetOrthogonalScrollingBehavior();

                var sectionHeaderSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(1),
                                                                      NSCollectionLayoutDimension.CreateAbsolute(44));
                var sectionHeader = NSCollectionLayoutBoundarySupplementaryItem.Create(sectionHeaderSize, headerElementKind, NSRectAlignment.Top);

                section.BoundarySupplementaryItems = new [] { sectionHeader };

                return(section);
            }
        }