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

DrawerKit with RxCocoa, UITableView didSelectRow not called #94

Closed
popei69 opened this issue Mar 18, 2019 · 4 comments
Closed

DrawerKit with RxCocoa, UITableView didSelectRow not called #94

popei69 opened this issue Mar 18, 2019 · 4 comments

Comments

@popei69
Copy link

popei69 commented Mar 18, 2019

I use DrawerKit to display a UIViewController with an UITableView. I use RxSwift / RxCocoa to handle UITableView data / events.

I've noticed that DrawerKit PullToDismissManager can't forward event to RxTableViewDelegateProxy as it does with UITableViewDelegate:

  • If I don't implement scrollViewForPullToDismiss, tableView.rx.itemSelected works as usual.
  • If I implement scrollViewForPullToDismiss with a classic UITableViewDelegate approach, implementation of didSelectRowAt:index works as usual.
  • If I implement scrollViewForPullToDismiss, tableView.rx.itemSelected doesn't work.

I'm not sure if it's more a question to address in RxCocoa side or DrawerKit. I wonder if you had this issue before and have a hint to proceed except reimplementing UITableViewDelegate for that specific view.

Thanks

@inamiy
Copy link

inamiy commented Mar 18, 2019

Hi @popei69

I'm not sure if it's more a question to address in RxCocoa side or DrawerKit

I guess this issue is rather a matter of RxSwift than DrawerKit.

But as far as I know from my experience, you can set scrollViewForPullToDismiss = tableView first (which steals tableView.delegate internally) then call tableView.rx.setDelegate(...) to fix this issue.
If you set in wrong order, no matter you are using DrawerKit or other 3rd party library that steals delegate, it will break RxSwift's delegate proxying so that tableView.rx.itemSelected will no longer be called.

@popei69
Copy link
Author

popei69 commented Mar 18, 2019

Hi @inamiy, thanks for the quick reply.

you can set scrollViewForPullToDismiss = tableView first

Sorry for the confusion, that's already the case, that's what I meant by "If I implement scrollViewForPullToDismiss": scrolling into the tableView is actually dragging the view as well as expected.

then call tableView.rx.setDelegate(...)

I'm not sure what you meant here. If the DrawerKit still the delegate for scrolling purpose, what should be the parameter of tableView.rx.setDelegate to get it forward back to RxSwift and tableView.rx.itemSelected?

No matter you are using DrawerKit or other 3rd party library that steals delegate, it will break RxSwift's delegate proxying so that tableView.rx.itemSelected will no longer be called.

That make sense, that's what I thought. I worked around by reimplementing the delegate and manually triggering the next observer for time being.
Thanks

@inamiy
Copy link

inamiy commented Mar 19, 2019

@popei69

what should be the parameter of tableView.rx.setDelegate

// 1. Set `scrollViewForPullToDismiss` first.
// (NOTE: This will swap `tableView.delegate` internally)
drawerPresentationController?.scrollViewForPullToDismiss = tableView

// 2. Then, set `tableView.rx.setDelegate` with swapped `tableView.delegate` as an argument.
// (NOTE: This will retry `RxScrollViewDelegateProxy.installForwardDelegate` internally)
if let delegate = tableView.delegate {
    _ = tableView.rx.setDelegate(delegate)
}

Try this. This will retry calling RxScrollViewDelegateProxy.installForwardDelegate internally.

@popei69
Copy link
Author

popei69 commented Mar 20, 2019

@inamiy Thanks for the update.

I had a look into it but it seems to create an infinite loop and finally crash. The PullToDismissManager forward the message to the delegate but RxSwift does the equivalent via tableView.rx.setDelegate and forward back to PullToDismissManager.

So I kept my previous version where I reimplement the UITableViewDelegate and manually forward the events to the right observer.

Anyway thanks for taking time to reply, I understand more how both works so it's much appreciated. Closing this ticket since it's a RxSwift concern and not DrawerKit.

@popei69 popei69 closed this as completed Mar 20, 2019
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