From 6bea10bdac90df487068cf77ad80a345665cd70f Mon Sep 17 00:00:00 2001 From: sk Date: Fri, 13 Jan 2023 05:46:43 +0100 Subject: [PATCH] add pager title transition --- .../android/fragments/HomeTabFragment.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java index d6ef6734a..7cf66d435 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeTabFragment.java @@ -74,6 +74,7 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab private ViewPager2 pager; private final List fragments = new ArrayList<>(); private final List tabViews = new ArrayList<>(); + private View switcher; private FrameLayout toolbarFrame; private ImageView timelineIcon; private ImageView collapsedChevron; @@ -136,7 +137,7 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab timelineIcon = toolbarFrame.findViewById(R.id.timeline_icon); timelineTitle = toolbarFrame.findViewById(R.id.timeline_title); collapsedChevron = toolbarFrame.findViewById(R.id.collapsed_chevron); - View switcher = toolbarFrame.findViewById(R.id.switcher_btn); + switcher = toolbarFrame.findViewById(R.id.switcher_btn); switcherPopup = new PopupMenu(getContext(), switcher); switcherPopup.inflate(R.menu.home_switcher); switcherPopup.setOnMenuItemClickListener(this::onSwitcherItemSelected); @@ -166,6 +167,16 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab } }); + if (!GlobalUserPreferences.reduceMotion) { + pager.setPageTransformer((v, pos) -> { + if (tabViews.get(pager.getCurrentItem()) != v) return; + float scaleFactor = Math.max(0.85f, 1 - Math.abs(pos) * 0.06f); + switcher.setScaleY(scaleFactor); + switcher.setScaleX(scaleFactor); + switcher.setAlpha(Math.max(0.65f, 1 - Math.abs(pos))); + }); + } + updateToolbarLogo(); if(GithubSelfUpdater.needSelfUpdating()){ @@ -225,6 +236,8 @@ public class HomeTabFragment extends MastodonToolbarFragment implements Scrollab // centering button by applying the same space on the left int padding = toolbar.getWidth() - toolbarFrame.getWidth(); ((FrameLayout) toolbarShowNewPostsBtn.getParent()).setPadding(padding, 0, 0, 0); + switcher.setPivotX(V.dp(28)); // padding + half of icon + switcher.setPivotY(switcher.getHeight() / 2f); }); if(newPostsBtnShown){