diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java index 11060918f2..ff7b2370bf 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationFragment.java @@ -212,6 +212,8 @@ public class ConversationFragment extends Fragment { this::handleReplyMessage ).attachToRecyclerView(list); + setupListLayoutListeners(); + this.conversationViewModel = ViewModelProviders.of(requireActivity(), new ConversationViewModel.Factory()).get(ConversationViewModel.class); conversationViewModel.getMessages().observe(this, list -> { if (getListAdapter() != null && !list.getDataSource().isInvalid()) { @@ -226,6 +228,22 @@ public class ConversationFragment extends Fragment { return view; } + private void setupListLayoutListeners() { + list.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> setListVerticalTranslation()); + + list.addOnChildAttachStateChangeListener(new RecyclerView.OnChildAttachStateChangeListener() { + @Override + public void onChildViewAttachedToWindow(@NonNull View view) { + setListVerticalTranslation(); + } + + @Override + public void onChildViewDetachedFromWindow(@NonNull View view) { + setListVerticalTranslation(); + } + }); + } + private void setListVerticalTranslation() { if (list.canScrollVertically(1) || list.canScrollVertically(-1) || list.getChildCount() == 0) { list.setTranslationY(0);