Created
March 3, 2020 08:39
-
-
Save samuel22gj/e914707bf353d85343e7836d2ffeda39 to your computer and use it in GitHub Desktop.
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
object RecyclerViewUtils { | |
fun <VH : RecyclerView.ViewHolder> scrollToHolderWithFallback( | |
recyclerViewMatcher: Matcher<View>, | |
viewHolderMatcher: Matcher<VH>, | |
failureViewAction: ViewAction, | |
maxRetryCount: Int | |
) { | |
var count = maxRetryCount | |
while (count > 0) { | |
if (scrollToHolderAndReturnResult(recyclerViewMatcher, viewHolderMatcher)) { | |
break | |
} else { | |
onView(recyclerViewMatcher) | |
.perform(failureViewAction) | |
} | |
count-- | |
} | |
} | |
private fun <VH : RecyclerView.ViewHolder> scrollToHolderAndReturnResult( | |
recyclerViewMatcher: Matcher<View>, | |
viewHolderMatcher: Matcher<VH> | |
): Boolean { | |
var result = true | |
onView(recyclerViewMatcher) | |
.withFailureHandler { error, viewMatcher -> result = false } | |
.perform(RecyclerViewActions.scrollToHolder(viewHolderMatcher)) | |
return result | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment