From e7e3d94add2e30a3e2fa5e51c2a782c87c9f6497 Mon Sep 17 00:00:00 2001 From: FineFindus <63370021+FineFindus@users.noreply.github.com> Date: Sun, 29 Jan 2023 21:31:15 +0100 Subject: [PATCH] feat(composeButton): hide when scrolling in profile --- .../android/fragments/ProfileFragment.java | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java index a1f36ac80..a76d0a4da 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/ProfileFragment.java @@ -142,7 +142,7 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList private WindowInsets childInsets; private PhotoViewer currentPhotoViewer; private boolean editModeLoading; - private boolean isScrollingUp = false; + protected int scrollDiff = 0; public ProfileFragment(){ super(R.layout.loader_fragment_overlay_toolbar); @@ -730,6 +730,36 @@ public class ProfileFragment extends LoaderFragment implements OnBackPressedList if(currentPhotoViewer!=null){ currentPhotoViewer.offsetView(0, oldScrollY-scrollY); } + + int dy = scrollY - oldScrollY; + + if (dy > 0 && fab.getVisibility() == View.VISIBLE) { + TranslateAnimation animate = new TranslateAnimation( + 0, + 0, + 0, + fab.getHeight() * 2); + animate.setDuration(300); + animate.setFillAfter(true); + fab.startAnimation(animate); + fab.setVisibility(View.INVISIBLE); + scrollDiff = 0; + } else if (dy < 0 && fab.getVisibility() != View.VISIBLE) { + if (scrollDiff > 400) { + fab.setVisibility(View.VISIBLE); + TranslateAnimation animate = new TranslateAnimation( + 0, + 0, + fab.getHeight() * 2, + 0); + animate.setDuration(300); + animate.setFillAfter(true); + fab.startAnimation(animate); + scrollDiff = 0; + } else { + scrollDiff += Math.abs(dy); + } + } } private Fragment getFragmentForPage(int page){