ReactiveCircus / FlowBinding

Kotlin Coroutines Flow binding APIs for Android's platform and unbundled UI widgets, inspired by RxBinding.
https://reactivecircus.github.io/FlowBinding/
Apache License 2.0
901 stars 42 forks source link

Why doesn't clicks() return the Flow<View> #122

Closed Zengyonghao closed 3 years ago

Zengyonghao commented 3 years ago

I want to merge multiple click events, but Flow prevents me from distinguishing the source of the events merge(binding.actionWechat.clicks(), binding.actionFacebook.clicks(), binding.actionTwitter.clicks(), binding.actionWhatapp.clicks()) .onEach { }

Zengyonghao commented 3 years ago

like this val listener = View.OnClickListener { safeOffer(it) }

ychescale9 commented 3 years ago

Does this work?

class ClickEvent(val view: View)

merge(
  binding.actionWechat.clicks().map { ClickEvent(binding.actionWechat) },
  binding.actionFacebook.clicks().map { ClickEvent(binding.actionFacebook) },
  binding.actionTwitter.clicks().map { ClickEvent(binding.actionTwitter) },
  binding.actionWhatapp.clicks().map { ClickEvent(binding.actionWhatapp) },
).onEach {
  // event.view
}
Zengyonghao commented 3 years ago

Does this work?

class ClickEvent(val view: View)

merge(
  binding.actionWechat.clicks().map { ClickEvent(binding.actionWechat) },
  binding.actionFacebook.clicks().map { ClickEvent(binding.actionFacebook) },
  binding.actionTwitter.clicks().map { ClickEvent(binding.actionTwitter) },
  binding.actionWhatapp.clicks().map { ClickEvent(binding.actionWhatapp) },
).onEach {
  // event.view
}

thanks. This can solve the problem