android - Espresso, scrolling not working when NestedScrollView or RecyclerView is in CoordinatorLayout -
it looks coordinatorlayout
breaks behaviour of espresso actions such scrollto()
or recyclerviewactions.scrolltoposition()
.
issue nestedscrollview
for layout one:
<android.support.design.widget.coordinatorlayout android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v4.widget.nestedscrollview android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_view_behavior"> ... </android.support.v4.widget.nestedscrollview> <android.support.design.widget.appbarlayout android:layout_width="match_parent" android:layout_height="wrap_content" > ... </android.support.design.widget.appbarlayout> </android.support.design.widget.coordinatorlayout>
if try scroll view inside nestedscrollview
using viewactions.scrollto()
first problem find performexception
. because action supports scrollview
, nestedscrollview
doesn't extend it. workaround problem explained here, can copy code in scrollto()
, change constrains support nestedscrollview
. seems work if nestedscrollview
not in coordinatorlayout
put inside coordinatorlayout
scrolling action fails.
issue recyclerview
for same layout, if replace nestedscrollview
recyclerview
there problems the scrolling.
in case i'm using recyclerviewaction.scrolltoposition(position)
. unlike nestedscrollview
, here can see scrolling happening. however, looks scrolls wrong position. example, if scroll last position, makes visible second last not last one. when move recyclerview
out of coordinatorlayout
scrolling works should.
at moment can't write espresso test screens use coordinatorlayout
due issues. experiencing same problems or knows workaround?
this happening because espresso scrollto() method explicitly checks layout class , works scrollview & horizontalscrollview. internally it's using view.requestrectangleonscreen(...) i'd expect work fine many layouts.
my workaround nestedscrollview take scrolltoaction , modify constraint. modified action worked fine nestedscrollview change.
changed method in scrolltoaction class:
public matcher<view> getconstraints() { return allof(witheffectivevisibility(visibility.visible), isdescendantofa(anyof( isassignablefrom(scrollview.class), isassignablefrom(horizontalscrollview.class), isassignablefrom(nestedscrollview.class)))); }
convenience method:
public static viewaction betterscrollto() { return viewactions.actionwithassertions(new nestedscrolltoaction()); }
Comments
Post a Comment