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: BottomSheetBehaviorWrapper
) : 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment