danielt1263 / RxEarthquake

A sample app describing my philosophy on how to write iOS code with RxSwift.
MIT License
113 stars 10 forks source link

How to manage inputs from the cells of a Table/CollectionView the Rx way? #1

Open FredericRuaudel opened 4 years ago

FredericRuaudel commented 4 years ago

Hi @danielt1263 !

First, thanks for your nice example, I really like your very functional style in this project and also in RxMyCoordinator 💯

I have a question for you. How would you deal with an input control added inside a cell ?

For example, in this project, let's say your project owner ask you to add a "more information" button directly inside an Earthquake cell because a user interview showed that it was an action done really often.

How would you make the tap input of this button reachable from the Coordinator in order to process the opening of the SFSafariVC without relying on any of the UITableViewDelegate methods ?

I'm curious to know your answer because I have a settings VC with lots of different inputs inside each cells and a dynamic layout where some inputs make other cells appear and disappear and I can't find a proper way to implement this…

Thanks in advance for your insight about this !

danielt1263 commented 4 years ago

In this case, I would have a subject inside the viewDidLoad or bind function that accepted a cell id or model. Then in the cellForRowAtIndexPath I would bind the button to that Subject (make sure the subscription is disposed by the cell's disposeBag which is deinited in the prepareForReuse method.) That subject would then be a cause for an effect which in this case would be presenting the safari view.