def scroll_to_top_or_bottom(direction)
current_screen_state = query("%_Current_screen_name%") - some label etc
begin
prev_screen_state = current_screen_state
case direction
when :up
scroll("#{$scroll_view}", :up) - based on how it calls in your app: CustomRecyclerView, RecyclerView etc
when :down
scroll("#{$scroll_view}", :down) - based on how it calls in your app: CustomRecyclerView, RecyclerView etc
end
current_screen_state = query("%_Current_screen_name%") - the same line from the beginning of method
end while (current_screen_state != prev_screen_state)
end