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

Does FlowBinding already supports clicks inside dialog #116

Open
mochadwi opened this issue Dec 11, 2020 · 8 comments
Open

Does FlowBinding already supports clicks inside dialog #116

mochadwi opened this issue Dec 11, 2020 · 8 comments

Comments

@mochadwi
Copy link

mochadwi commented Dec 11, 2020

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

@mochadwi mochadwi changed the title Support clicks inside dialog binding FlowBinding already supports clicks inside dialog Dec 11, 2020
@mochadwi mochadwi changed the title FlowBinding already supports clicks inside dialog Does FlowBinding already supports clicks inside dialog Dec 11, 2020
@ychescale9
Copy link
Member

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)?

@mochadwi
Copy link
Author

mochadwi commented Dec 11, 2020

currently we're using BottomSheetDialogFragment to be precise but the MaterialDatePicker is interesting, might take a look at your implementation code for our references~

@mochadwi
Copy link
Author

mochadwi commented Dec 11, 2020

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

@ychescale9
Copy link
Member

I've never needed this myself but happy to accept a PR if you have a generic implementation 😃

@mochadwi
Copy link
Author

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?

@ychescale9
Copy link
Member

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?

@mochadwi
Copy link
Author

mochadwi commented Dec 11, 2020

before typing comment reply, is it okay to continue discussion here or should I use discussion in this repo? @ychescale9

@ychescale9
Copy link
Member

Sure let's try out discussion!

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