Created
October 19, 2020 07:43
-
-
Save huuphuoc1396/e1a89cbdf39ef8e9015044973c741fdc to your computer and use it in GitHub Desktop.
NestedScrollView scrolling via Kotlin Delegation (refs: https://medium.com/@devasierra/espresso-nestedscrollview-scrolling-via-kotlin-delegation-5e7f0aa64c09)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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