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

Support for UICollectionViewDelegateFlowLayout (sizeForItemAt) #335

Open
hiddely opened this issue Sep 16, 2019 · 2 comments
Open

Support for UICollectionViewDelegateFlowLayout (sizeForItemAt) #335

hiddely opened this issue Sep 16, 2019 · 2 comments

Comments

@hiddely
Copy link

hiddely commented Sep 16, 2019

Are there plans to support UICollectionViewDelegateFlowLayout in some reactive way, to respond to sizes based on the data model instead of only being able to rely on indexPath?

Currently, I'm doing something like this:

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
        
        guard self.events?.count ?? 0 > indexPath.section,
            let item = self.events?[indexPath.section] else {
            return .zero
        }
        
        switch item {
        case .comingUp(items: _):
            return // something
        case .other(month: _, items: _):
            return CGSize(width: collectionView.bounds.width, height: CompactEventCollectionViewCell.cellHeight)
        case .otherFirst(month: _, items: _):
            return CGSize(width: collectionView.bounds.width, height: CompactEventCollectionViewCell.cellHeight)
        case .tips(items: _):
            return CGSize(width: collectionView.bounds.width, height: HorizontalTipCollectionViewCell.cellHeight)
        }
    }

However, this relies on some helper local variable events, which may or may not have been updated by an observable when the delegate is called.

@cd5z
Copy link

cd5z commented Dec 25, 2019

#350

@lordzsolt
Copy link
Member

lordzsolt commented Jan 19, 2020

A slight improvement, though not the ideal solution: Both UICollectionView and UITableView expose func model<T>(at indexPath: IndexPath) throws -> T

So you could rewrite the top part to:

guard let item = try? collectionView.rx.model(at: indexPath) as YourModel else { 
    return .zero
}

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

3 participants