From 56e90300d3ff5960d37ebc52d8ce0d2dc613b7d7 Mon Sep 17 00:00:00 2001 From: Ilya Lim Date: Thu, 7 May 2020 17:21:23 +0700 Subject: [PATCH] Add NestedScrollView support in scrollTo() --- .../agoda/kakao/common/actions/BaseActions.kt | 2 +- .../common/actions/NestedScrollToAction.kt | 33 +++++++++++++++++++ .../com/agoda/sample/TestActivityTest.kt | 4 +++ .../agoda/sample/screen/TestActivityScreen.kt | 1 + sample/src/main/res/layout/activity_test.xml | 12 +++++++ 5 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 kakao/src/main/kotlin/com/agoda/kakao/common/actions/NestedScrollToAction.kt diff --git a/kakao/src/main/kotlin/com/agoda/kakao/common/actions/BaseActions.kt b/kakao/src/main/kotlin/com/agoda/kakao/common/actions/BaseActions.kt index 110c7200..e90f4f3d 100644 --- a/kakao/src/main/kotlin/com/agoda/kakao/common/actions/BaseActions.kt +++ b/kakao/src/main/kotlin/com/agoda/kakao/common/actions/BaseActions.kt @@ -82,7 +82,7 @@ interface BaseActions { * Scrolls to the view, if possible */ fun scrollTo() { - view.perform(ViewActions.scrollTo()) + view.perform(NestedScrollToAction()) } /** diff --git a/kakao/src/main/kotlin/com/agoda/kakao/common/actions/NestedScrollToAction.kt b/kakao/src/main/kotlin/com/agoda/kakao/common/actions/NestedScrollToAction.kt new file mode 100644 index 00000000..9c649ef6 --- /dev/null +++ b/kakao/src/main/kotlin/com/agoda/kakao/common/actions/NestedScrollToAction.kt @@ -0,0 +1,33 @@ +package com.agoda.kakao.common.actions + +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.ScrollToAction +import androidx.test.espresso.matcher.ViewMatchers +import androidx.test.espresso.matcher.ViewMatchers.isAssignableFrom +import androidx.test.espresso.matcher.ViewMatchers.isDescendantOfA +import androidx.test.espresso.matcher.ViewMatchers.withEffectiveVisibility +import org.hamcrest.Matcher +import org.hamcrest.Matchers.allOf +import org.hamcrest.Matchers.anyOf + +/** + * Scrolls to a given view with [NestedScrollView] support. + */ +class NestedScrollToAction : ViewAction by ScrollToAction() { + override fun getConstraints(): Matcher = allOf( + withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE), + isDescendantOfA( + anyOf( + isAssignableFrom(ScrollView::class.java), + isAssignableFrom(HorizontalScrollView::class.java), + isAssignableFrom(NestedScrollView::class.java), + isAssignableFrom(ListView::class.java) + ) + ) + ) +} diff --git a/sample/src/androidTest/kotlin/com/agoda/sample/TestActivityTest.kt b/sample/src/androidTest/kotlin/com/agoda/sample/TestActivityTest.kt index 5433fa8c..7b81d8ee 100644 --- a/sample/src/androidTest/kotlin/com/agoda/sample/TestActivityTest.kt +++ b/sample/src/androidTest/kotlin/com/agoda/sample/TestActivityTest.kt @@ -150,6 +150,10 @@ class TestActivityTest { swipeSwitchThumb(RIGHT) isChecked() } + + nestedTextView { + scrollTo() + } } } } diff --git a/sample/src/androidTest/kotlin/com/agoda/sample/screen/TestActivityScreen.kt b/sample/src/androidTest/kotlin/com/agoda/sample/screen/TestActivityScreen.kt index ab1e1e64..0c481740 100644 --- a/sample/src/androidTest/kotlin/com/agoda/sample/screen/TestActivityScreen.kt +++ b/sample/src/androidTest/kotlin/com/agoda/sample/screen/TestActivityScreen.kt @@ -44,6 +44,7 @@ open class TestActivityScreen : Screen() { val seekbar: KSeekBar = KSeekBar { withId(R.id.seek_bar) } val switch: KSwitch = KSwitch { withId(R.id.switch_view) } val switchCompat: KSwitch = KSwitch { withId(R.id.switch_compat) } + val nestedTextView: KTextView = KTextView { withId(R.id.nested_scroll_text_view) } val snackbar: KSnackbar = KSnackbar() } diff --git a/sample/src/main/res/layout/activity_test.xml b/sample/src/main/res/layout/activity_test.xml index ac7dcf77..0b35f216 100644 --- a/sample/src/main/res/layout/activity_test.xml +++ b/sample/src/main/res/layout/activity_test.xml @@ -158,6 +158,18 @@ android:paddingRight="32dp" android:text="Switch compat" /> + + + + + +