From 7fbd2d72080cd94c9af2224651f3f901301d3ece Mon Sep 17 00:00:00 2001 From: Stephen Zhou <38493346+hyoban@users.noreply.github.com> Date: Sat, 1 Mar 2025 07:34:03 +0800 Subject: [PATCH] fix(mobile): player tab animation (#2918) --- .../src/components/layouts/tabbar/Tabbar.tsx | 4 +- .../src/modules/player/PlayerTabBar.tsx | 69 +++++++++++-------- 2 files changed, 42 insertions(+), 31 deletions(-) diff --git a/apps/mobile/src/components/layouts/tabbar/Tabbar.tsx b/apps/mobile/src/components/layouts/tabbar/Tabbar.tsx index c8341d29b..7355ff8c3 100644 --- a/apps/mobile/src/components/layouts/tabbar/Tabbar.tsx +++ b/apps/mobile/src/components/layouts/tabbar/Tabbar.tsx @@ -44,7 +44,7 @@ export const Tabbar: FC = (props) => { return ( = (props) => { > - + {routes.map((route, index) => { const focused = index === state.index const { options } = descriptors[route.key]! diff --git a/apps/mobile/src/modules/player/PlayerTabBar.tsx b/apps/mobile/src/modules/player/PlayerTabBar.tsx index 4846b608e..8da9fbfcd 100644 --- a/apps/mobile/src/modules/player/PlayerTabBar.tsx +++ b/apps/mobile/src/modules/player/PlayerTabBar.tsx @@ -1,8 +1,14 @@ import { cn } from "@follow/utils" import { Image } from "expo-image" import { router, usePathname } from "expo-router" +import { useEffect } from "react" import { Pressable, Text, View } from "react-native" -import Animated, { SlideInDown, SlideOutDown } from "react-native-reanimated" +import Animated, { + interpolate, + useAnimatedStyle, + useSharedValue, + withTiming, +} from "react-native-reanimated" import { useActiveTrack } from "@/src/lib/player" import { usePrefetchImageColors } from "@/src/store/image/hooks" @@ -14,39 +20,44 @@ const allowedRoutes = new Set(["/", "/subscriptions", "/player"]) export function PlayerTabBar({ className }: { className?: string }) { const activeTrack = useActiveTrack() const pathname = usePathname() + const isVisible = !!activeTrack && allowedRoutes.has(pathname) + const isVisibleSV = useSharedValue(isVisible ? 1 : 0) + useEffect(() => { + isVisibleSV.value = withTiming(isVisible ? 1 : 0) + }, [pathname, isVisible]) + const animatedStyle = useAnimatedStyle(() => { + return { + opacity: isVisibleSV.value, + height: interpolate(isVisibleSV.value, [0, 1], [0, 56]), + overflow: "hidden", + } + }) usePrefetchImageColors(activeTrack?.artwork) - if (!activeTrack || !allowedRoutes.has(pathname)) { - return null - } - return ( - - + { + router.push("/player") + }} > - { - router.push("/player") - }} - > - - - - - {activeTrack.title} - - - - - - + + + + + {activeTrack?.title ?? ""} + - - - + + + + + + + ) }