Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the below code of layout section before iOS 13 is not work correctly #132

Open
willokyes opened this issue Dec 17, 2019 · 2 comments
Open

Comments

@willokyes
Copy link

willokyes commented Dec 17, 2019

     // i.e.  all iOS version is work correctly
    func layoutSection(layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? {
        let itemSize = NSCollectionLayoutSize(widthDimension: .fractionalWidth(1.0),
                                              heightDimension: .fractionalHeight(1.0))
        let item = NSCollectionLayoutItem(layoutSize: itemSize)
        
        let groupSize = NSCollectionLayoutSize(widthDimension: .absolute(185),
                                               heightDimension: .absolute(160))
        let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
        
        let section = NSCollectionLayoutSection(group: group)
        section.contentInsets = .init(top: 0, leading: 15, bottom: 0, trailing: 15)
        section.orthogonalScrollingBehavior = .continuous
        section.interGroupSpacing = 10
        return section
    }
    
    // i.e.  before iOS 13 is not work correctly
    func layoutSection_v1(layoutEnvironment: NSCollectionLayoutEnvironment) -> NSCollectionLayoutSection? {
        let itemCount = items.count
        guard itemCount > 0 else {
            return nil
        }
        
        let itemSize = NSCollectionLayoutSize(widthDimension: .absolute(185),
                                              heightDimension: .fractionalHeight(1.0))
        let item = NSCollectionLayoutItem(layoutSize: itemSize)
        
        let width = CGFloat(15 + 185 * itemCount + 10 * (itemCount - 1) + 15)
        let groupSize = NSCollectionLayoutSize(widthDimension: .absolute(width),
                                               heightDimension: .absolute(160))
        let group = NSCollectionLayoutGroup.horizontal(layoutSize: groupSize, subitems: [item])
        group.contentInsets = .init(top: 0, leading: 15, bottom: 0, trailing: 15)
        group.interItemSpacing = .fixed(10)
        
        let section = NSCollectionLayoutSection(group: group)
        section.orthogonalScrollingBehavior = .continuous
        section.interGroupSpacing = 0
        return section
    }

@seleemdeveloper
Copy link

seleemdeveloper commented Dec 21, 2019

I think you need to add IBP before NS eg) IBPNSCollectionLayoutSize instead of NSCollectionLayoutSize.

@willokyes
Copy link
Author

@seleemdeveloper it is typealias NS* for IBP*:
typealias_IBP_NS

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants