Fix and simplify Y translation calculation for Conversation.

This commit is contained in:
Alex Hart 2020-03-02 08:55:53 -04:00
parent c24d285cd3
commit b06152ba58

View File

@ -236,20 +236,14 @@ public class ConversationFragment extends Fragment
} }
private void setListVerticalTranslation() { private void setListVerticalTranslation() {
int heightOfChildren = 0; if (list.canScrollVertically(1) || list.canScrollVertically(-1) || list.getChildCount() == 0) {
for (int i = 0; i < list.getChildCount(); i++) {
heightOfChildren += list.getChildAt(i).getMeasuredHeight();
}
Log.i(TAG, "Height of children: " + heightOfChildren + " my height: " + list.getMeasuredHeight());
if (heightOfChildren > list.getMeasuredHeight()) {
list.setTranslationY(0); list.setTranslationY(0);
list.setOverScrollMode(RecyclerView.OVER_SCROLL_IF_CONTENT_SCROLLS); list.setOverScrollMode(RecyclerView.OVER_SCROLL_IF_CONTENT_SCROLLS);
} else { } else {
list.setTranslationY(heightOfChildren - list.getMeasuredHeight()); int chTop = list.getChildAt(list.getChildCount() - 1).getTop();
list.setTranslationY(Math.min(0, -chTop));
list.setOverScrollMode(RecyclerView.OVER_SCROLL_NEVER); list.setOverScrollMode(RecyclerView.OVER_SCROLL_NEVER);
} }
listener.onListVerticalTranslationChanged(list.getTranslationY()); listener.onListVerticalTranslationChanged(list.getTranslationY());
} }