Does FlowBinding already supports clicks inside dialog
is it currently supported? *I'm unable to find the related docs in readme, might've missed that
currently we're manually using callbackFlow to achieve this
We don't have dialog bindings in the flowbinding-android library.
We do however have bindings for MaterialDatePickers:
// MaterialDatePicker
fun <S> MaterialDatePicker<S>.cancels(): Flow<Unit>
fun <S> MaterialDatePicker<S>.dismisses(): Flow<Unit>
fun <S> MaterialDatePicker<S>.negativeButtonClicks(): Flow<Unit>
fun <S> MaterialDatePicker<S>.positiveButtonClicks(): Flow<S>
Is this something you like to see in the platform bindings (flowbinding-android)?
currently we're using BottomSheetDialogFragment to be precise but the MaterialDatePicker is interesting, might take a look at your implementation code for our references~
FYI, previously we're trying with this approach:
private val dialogBinding by viewBinding(DialogInboxBinding::inflate) // using https://github.com/kirich1409/ViewBindingPropertyDelegate
private val updateStateIntent: Flow<UpdateInboxIntent>
get() = dialogBinding.btnUpdate.clicks {} // View.clicks from FlowBinding
EDITED: but the clicks event never triggers it, unless we're using manual approach something like this:
// OurActivity.kt
typealias UpdateClickListener = (Param1) -> Unit
var updateClickListener: UpdateClickListener? = null
private val updateStateIntent: Flow<UpdateInboxIntent>
get() = updatesClicks.map { param1 -> }
// somewhere in the code
dialogBinding.btnUpdate.setOnClickListener {
updateClickListener?.invoke(param1) // manually calls this
}
// extensions.kt
val OurActivity.updatesClicks: Flow<Param1>
get() = callbackFlow {
val listener: UpdateClickListener = { param1 ->
safeOffer(param1)
Unit
}
updateClickListener = listener
awaitClose { updateClickListener = null }
}.conflate().debounce(200)
@ychescale9
I've never needed this myself but happy to accept a PR if you have a generic implementation 😃
We've edited the previous comments with codes example, or do u have any suggestion for simpler approach rather than manually creating callbackFlow or are we missing something?
How are you collection the flow? do you have a single collector in your activity or do you have another one in your BottomSheetDialogFragment?
Each fragment and activity has its own LifecycleScope so sharing can be tricky. In this case does it make sense to communicate between your dialog and the host activity (assuming that's what you're trying to achieve) with a SharedFlow which is injected to both?
before typing comment reply, is it okay to continue discussion here or should I use discussion in this repo? @ychescale9
Sure let's try out discussion!