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

minimumColumnSpacing is ambiguous in Swift and Objective-C version #207

Open
HY558 opened this issue Dec 7, 2021 · 0 comments · May be fixed by #208
Open

minimumColumnSpacing is ambiguous in Swift and Objective-C version #207

HY558 opened this issue Dec 7, 2021 · 0 comments · May be fixed by #208

Comments

@HY558
Copy link

HY558 commented Dec 7, 2021

Objective-C:

- (CGFloat)itemWidthInSectionAtIndex:(NSInteger)section {
  UIEdgeInsets sectionInset;
  if ([self.delegate respondsToSelector:@selector(collectionView:layout:insetForSectionAtIndex:)]) {
    sectionInset = [self.delegate collectionView:self.collectionView layout:self insetForSectionAtIndex:section];
  } else {
    sectionInset = self.sectionInset;
  }
  CGFloat width = self.collectionView.bounds.size.width - sectionInset.left - sectionInset.right;
  NSInteger columnCount = [self columnCountForSection:section];

  CGFloat columnSpacing = self.minimumColumnSpacing;
  if ([self.delegate respondsToSelector:@selector(collectionView:layout:minimumColumnSpacingForSectionAtIndex:)]) {
    columnSpacing = [self.delegate collectionView:self.collectionView layout:self minimumColumnSpacingForSectionAtIndex:section];
  }

  return CHTFloorCGFloat((width - (columnCount - 1) * columnSpacing) / columnCount);
}

Swift:

    public func itemWidth(inSection section: Int) -> CGFloat {
        let columnCount = self.columnCount(forSection: section)
        let spaceColumCount = CGFloat(columnCount - 1)
        let width = collectionViewContentWidth(ofSection: section)
        return floor((width - (spaceColumCount * minimumColumnSpacing)) / CGFloat(columnCount))
    }

In Swift version, collectionView:layout:minimumColumnSpacingForSectionAtIndex not be called in real time. minimumColumnSpacing for section not work.

ApolloZhu added a commit to ApolloZhu/CHTCollectionViewWaterfallLayout that referenced this issue Dec 10, 2021
@ApolloZhu ApolloZhu linked a pull request Dec 26, 2021 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant