Skip to content

Instantly share code, notes, and snippets.

@huuphuoc1396
Created October 19, 2020 07:43
Show Gist options
  • Save huuphuoc1396/e1a89cbdf39ef8e9015044973c741fdc to your computer and use it in GitHub Desktop.
Save huuphuoc1396/e1a89cbdf39ef8e9015044973c741fdc to your computer and use it in GitHub Desktop.
import android.view.View
import android.widget.HorizontalScrollView
import android.widget.ListView
import android.widget.ScrollView
import androidx.core.widget.NestedScrollView
import androidx.test.espresso.ViewAction
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.matcher.ViewMatchers.*
import org.hamcrest.Matcher
import org.hamcrest.Matchers
class NestedScrollViewAction(
scrollToAction: ViewAction = ViewActions.scrollTo()
) : ViewAction by scrollToAction {
override fun getConstraints(): Matcher<View> {
return Matchers.allOf(
withEffectiveVisibility(Visibility.VISIBLE),
isDescendantOfA(
Matchers.anyOf(
isAssignableFrom(NestedScrollView::class.java),
isAssignableFrom(ScrollView::class.java),
isAssignableFrom(HorizontalScrollView::class.java),
isAssignableFrom(ListView::class.java)
)
)
)
}
companion object {
fun nestedScrollTo(): NestedScrollViewAction {
return NestedScrollViewAction()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment