Skip to content
This repository has been archived by the owner on May 26, 2021. It is now read-only.

Commit

Permalink
Merge pull request #210 from Unlimity/nested-scroll-view-support
Browse files Browse the repository at this point in the history
Add NestedScrollView support in scrollTo()
  • Loading branch information
Vacxe committed May 7, 2020
2 parents b270917 + 56e9030 commit bdb99f4
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 1 deletion.
Expand Up @@ -82,7 +82,7 @@ interface BaseActions {
* Scrolls to the view, if possible
*/
fun scrollTo() {
view.perform(ViewActions.scrollTo())
view.perform(NestedScrollToAction())
}

/**
Expand Down
@@ -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<View> = allOf(
withEffectiveVisibility(ViewMatchers.Visibility.VISIBLE),
isDescendantOfA(
anyOf(
isAssignableFrom(ScrollView::class.java),
isAssignableFrom(HorizontalScrollView::class.java),
isAssignableFrom(NestedScrollView::class.java),
isAssignableFrom(ListView::class.java)
)
)
)
}
Expand Up @@ -150,6 +150,10 @@ class TestActivityTest {
swipeSwitchThumb(RIGHT)
isChecked()
}

nestedTextView {
scrollTo()
}
}
}
}
Expand Up @@ -44,6 +44,7 @@ open class TestActivityScreen : Screen<TestActivityScreen>() {
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()
}
12 changes: 12 additions & 0 deletions sample/src/main/res/layout/activity_test.xml
Expand Up @@ -158,6 +158,18 @@
android:paddingRight="32dp"
android:text="Switch compat" />

<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content" >

<TextView
android:id="@+id/nested_scroll_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text in a nested scroll view" />

</androidx.core.widget.NestedScrollView>

</LinearLayout>
</ScrollView>

Expand Down

0 comments on commit bdb99f4

Please sign in to comment.