Is there a way to replace the method
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
from the UICollectionViewDelegateFlowLayout
protocol by something reactive using RxSwift?
Protocol methods that return values are pull based and as such are incompatible with Rx's push based philosophy. Not only is it currently impossible to replace that particular method with an Observable, it will never be possible.
The best you can do is implement the method by returning the value in a Variable
and use Rx to push data into the Variable
. When the collection view needs the size for the item in question, it will ask for it by calling this method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With