Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Defines the “glue” between a BottomSheetCallback and the Espresso IdlingResource framework.
abstract class BottomSheetResource(
private val bottomSheetBehavior: BottomSheetBehavior<View>
) : IdlingResource, BottomSheetBehavior.BottomSheetCallback() {
private var isIdle: Boolean = false
private var resourceCallback: IdlingResource.ResourceCallback? = null
override fun onSlide(bottomSheet: View, slideOffset: Float) {}
override fun onStateChanged(bottomSheet: View, newState: Int) {
val wasIdle = isIdle
isIdle = isDesiredState(newState)
if (!wasIdle && isIdle) {
override fun isIdleNow(): Boolean {
return isIdle
override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback) {
resourceCallback = callback
val state = bottomSheetBehavior.state
isIdle = isDesiredState(state)
if (isIdle) {
} else {
abstract fun isDesiredState(@BottomSheetBehavior.State state: Int): Boolean
Copy link

daniellAlgar commented May 17, 2021

May I ask what the BottomSheetBehaviourWrapper looks like?

Copy link

cmathew commented May 24, 2021

May I ask what the BottomSheetBehaviourWrapper looks like?

Oh, that's a simple wrapper class we use for Mock-ability in unit tests. But the standard BottomSheetBehavior will suffice for this example - I updated the gist to use that.

Copy link

daniellAlgar commented May 31, 2021

Thank you kindest!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment