예제 #1
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);
            }
        }
예제 #2
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);
        }
예제 #3
0
        private UICollectionViewLayout CreateLayout()
        {
            var layout = new UICollectionViewCompositionalLayout((sectionIndex, layoutEnvironment) =>
            {
                var sectionKind = EnumExtensions.FindByValue <Section>((byte)sectionIndex);
                var columns     = sectionKind.ColumnCount(layoutEnvironment.Container.EffectiveContentSize.Width);

                var itemSize = NSCollectionLayoutSize.Create(
                    width: CreateFractionalWidth(1.0f),
                    height: CreateFractionalHeight(1.0f));
                var item           = NSCollectionLayoutItem.Create(itemSize);
                item.ContentInsets = new NSDirectionalEdgeInsets(top: 2, leading: 2, bottom: 2, trailing: 2);

                var groupHeight = layoutEnvironment.TraitCollection.VerticalSizeClass == UIUserInterfaceSizeClass.Compact
                    ? CreateAbsolute(44)
                    : CreateFractionalWidth(0.2f);

                var groupSize = NSCollectionLayoutSize.Create(
                    width: CreateFractionalWidth(1.0f),
                    height: groupHeight);
                var group = NSCollectionLayoutGroup.CreateHorizontal(layoutSize: groupSize, subitem: item, count: columns);

                var section           = NSCollectionLayoutSection.Create(group);
                section.ContentInsets = new NSDirectionalEdgeInsets(top: 20, leading: 20, bottom: 20, trailing: 20);
                return(section);
            });

            return(layout);
        }
예제 #4
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(10, 10, 10, 10);

            var sectionBackgroundDecoration = NSCollectionLayoutDecorationItem.Create(sectionBackgroundDecorationElementKind);

            sectionBackgroundDecoration.ContentInsets = new NSDirectionalEdgeInsets(5, 5, 5, 5);
            section.DecorationItems = new [] { sectionBackgroundDecoration };

            var layout = new UICollectionViewCompositionalLayout(section);

            layout.RegisterClassForDecorationView(typeof(SectionBackgroundDecorationView), new NSString(sectionBackgroundDecorationElementKind));

            return(layout);
        }
예제 #5
0
        //   +-----------------------------------------------------+
        //   | +---------------------------------+  +-----------+  |
        //   | |                                 |  |           |  |
        //   | |                                 |  |           |  |
        //   | |                                 |  |     1     |  |
        //   | |                                 |  |           |  |
        //   | |                                 |  |           |  |
        //   | |                                 |  +-----------+  |
        //   | |               0                 |                 |
        //   | |                                 |  +-----------+  |
        //   | |                                 |  |           |  |
        //   | |                                 |  |           |  |
        //   | |                                 |  |     2     |  |
        //   | |                                 |  |           |  |
        //   | |                                 |  |           |  |
        //   | +---------------------------------+  +-----------+  |
        //   +-----------------------------------------------------+

        UICollectionViewLayout CreateLayout()
        {
            return(new UICollectionViewCompositionalLayout(SectionProviderHandler));

            NSCollectionLayoutSection SectionProviderHandler(nint sectionIndex, INSCollectionLayoutEnvironment layoutEnvironment)
            {
                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 containerGroupSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(.85f),
                                                                       NSCollectionLayoutDimension.CreateFractionalHeight(.4f));
                var containerGroup = NSCollectionLayoutGroup.CreateHorizontal(containerGroupSize, leadingItem, trailingGroup);

                var section = NSCollectionLayoutSection.Create(containerGroup);

                section.OrthogonalScrollingBehavior = UICollectionLayoutSectionOrthogonalScrollingBehavior.Continuous;

                return(section);
            }
        }
예제 #6
0
        //   +---------------------------------------------------+
        //   | +-----------------------------------------------+ |
        //   | |                                               | |
        //   | |                                               | |
        //   | |                       0                       | |  <- topItem
        //   | |                                               | |
        //   | |                                               | |
        //   | +-----------------------------------------------+ |
        //   | +---------------------------------+ +-----------+ |
        //   | |                                 | |           | |
        //   | |                                 | |           | |
        //   | |                                 | |     2     | |  <- trailingItem
        //   | |                                 | |           | |
        //   | |                                 | |           | |
        //   | |                                 | +-----------+ |
        //   | |               1                 |               |  <- bottomNestedGroup
        //   | |                                 | +-----------+ |
        //   | |                                 | |           | |
        //   | |                                 | |           | |
        //   | |                                 | |     3     | |  <- trailingItem
        //   | |                                 | |           | |
        //   | |                                 | |           | |
        //   | +---------------------------------+ +-----------+ |
        //   +---------------------------------------------------+
        //                leadingItem              trailingGroup
        private UICollectionViewLayout CreateLayout()
        {
            var layout = new UICollectionViewCompositionalLayout((sectionIndex, layoutEnvironment) =>
            {
                var leadingItem = NSCollectionLayoutItem.Create(
                    layoutSize: NSCollectionLayoutSize.Create(
                        width: CreateFractionalWidth(0.7f),
                        height: CreateFractionalHeight(1.0f)));
                leadingItem.ContentInsets = new NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10);

                var trailingItem = NSCollectionLayoutItem.Create(
                    layoutSize: NSCollectionLayoutSize.Create(
                        width: CreateFractionalWidth(1.0f),
                        height: CreateFractionalHeight(0.3f)));
                trailingItem.ContentInsets = new NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10);

                var trailingGroup = NSCollectionLayoutGroup.CreateVertical(
                    layoutSize: NSCollectionLayoutSize.Create(
                        width: CreateFractionalWidth(0.3f),
                        height: CreateFractionalHeight(1.0f)),
                    subitem: trailingItem,
                    count: 2);

                var bottomNestedGroup = NSCollectionLayoutGroup.CreateHorizontal(
                    layoutSize: NSCollectionLayoutSize.Create(
                        width: CreateFractionalWidth(1.0f),
                        height: CreateFractionalHeight(0.6f)),
                    subitems: new[] { leadingItem, trailingGroup });

                var topItem = NSCollectionLayoutItem.Create(
                    layoutSize: NSCollectionLayoutSize.Create(
                        width: CreateFractionalWidth(1.0f),
                        height: CreateFractionalHeight(0.3f)));
                topItem.ContentInsets = new NSDirectionalEdgeInsets(top: 10, leading: 10, bottom: 10, trailing: 10);

                var nestedGroup = NSCollectionLayoutGroup.CreateVertical(
                    layoutSize: NSCollectionLayoutSize.Create(
                        width: CreateFractionalWidth(1.0f),
                        height: CreateFractionalHeight(0.4f)),
                    subitems: new[] { topItem, bottomNestedGroup });

                var section = NSCollectionLayoutSection.Create(group: nestedGroup);

                section.OrthogonalScrollingBehavior = UICollectionLayoutSectionOrthogonalScrollingBehavior.Continuous;

                return(section);
            });

            return(layout);
        }
예제 #7
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);
            }
        }
        private UICollectionViewLayout GetUiCollectionViewLayout()
        {
            var layoutSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(1), NSCollectionLayoutDimension.CreateEstimated(100));
            var item       = NSCollectionLayoutItem.Create(layoutSize);
            var group      = NSCollectionLayoutGroup.CreateHorizontal(layoutSize: layoutSize, subitem: item, count: 1);
            var section    = NSCollectionLayoutSection.Create(group);

            // this is what you need for content inset
            section.ContentInsets = new NSDirectionalEdgeInsets(top: 5, leading: 5, bottom: 5, trailing: 5);

            // this is spacing between items
            section.InterGroupSpacing = 5;

            var layout = new UICollectionViewCompositionalLayout(section);

            return(layout);
        }
예제 #9
0
        UICollectionViewLayout CreateLayout()
        {
            return(new UICollectionViewCompositionalLayout(SectionProviderHandler));

            NSCollectionLayoutSection SectionProviderHandler(nint sectionIndex, INSCollectionLayoutEnvironment layoutEnvironment)
            {
                var contentSize = layoutEnvironment.Container.EffectiveContentSize;
                var columns     = (int)(contentSize.Width / nodeSize.Width);
                var rowHeight   = nodeSize.Height;

                var itemSize = NSCollectionLayoutSize.Create(NSCollectionLayoutDimension.CreateFractionalWidth(1),
                                                             NSCollectionLayoutDimension.CreateFractionalHeight(1));
                var item = NSCollectionLayoutItem.Create(itemSize);

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

                var section = NSCollectionLayoutSection.Create(group);

                return(section);
            }
        }