mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Fix (#4430): Use separate hooks for shell mode animated styles (#4451)

* Fix (#4430): Use separate hooks for shell mode animated styles

* Consolidate in one file

---------

Co-authored-by: Dan Abramov <dan.abramov@gmail.com>

authored by

Francesco Lodovici
Dan Abramov
and committed by
GitHub
b688da8d fd03ea3f

+74 -61
-45
src/lib/hooks/useMinimalShellMode.tsx
··· 1 - import {interpolate, useAnimatedStyle} from 'react-native-reanimated' 2 - import {useMinimalShellMode as useMinimalShellModeState} from '#/state/shell/minimal-mode' 3 - import {useShellLayout} from '#/state/shell/shell-layout' 4 - 5 - export function useMinimalShellMode() { 6 - const mode = useMinimalShellModeState() 7 - const {footerHeight, headerHeight} = useShellLayout() 8 - 9 - const footerMinimalShellTransform = useAnimatedStyle(() => { 10 - return { 11 - pointerEvents: mode.value === 0 ? 'auto' : 'none', 12 - opacity: Math.pow(1 - mode.value, 2), 13 - transform: [ 14 - { 15 - translateY: interpolate(mode.value, [0, 1], [0, footerHeight.value]), 16 - }, 17 - ], 18 - } 19 - }) 20 - const headerMinimalShellTransform = useAnimatedStyle(() => { 21 - return { 22 - pointerEvents: mode.value === 0 ? 'auto' : 'none', 23 - opacity: Math.pow(1 - mode.value, 2), 24 - transform: [ 25 - { 26 - translateY: interpolate(mode.value, [0, 1], [0, -headerHeight.value]), 27 - }, 28 - ], 29 - } 30 - }) 31 - const fabMinimalShellTransform = useAnimatedStyle(() => { 32 - return { 33 - transform: [ 34 - { 35 - translateY: interpolate(mode.value, [0, 1], [-44, 0]), 36 - }, 37 - ], 38 - } 39 - }) 40 - return { 41 - footerMinimalShellTransform, 42 - headerMinimalShellTransform, 43 - fabMinimalShellTransform, 44 - } 45 - }
+58
src/lib/hooks/useMinimalShellTransform.ts
··· 1 + import {interpolate, useAnimatedStyle} from 'react-native-reanimated' 2 + 3 + import {useMinimalShellMode} from '#/state/shell/minimal-mode' 4 + import {useShellLayout} from '#/state/shell/shell-layout' 5 + 6 + // Keep these separated so that we only pay for useAnimatedStyle that gets used. 7 + 8 + export function useMinimalShellHeaderTransform() { 9 + const mode = useMinimalShellMode() 10 + const {headerHeight} = useShellLayout() 11 + 12 + const headerTransform = useAnimatedStyle(() => { 13 + return { 14 + pointerEvents: mode.value === 0 ? 'auto' : 'none', 15 + opacity: Math.pow(1 - mode.value, 2), 16 + transform: [ 17 + { 18 + translateY: interpolate(mode.value, [0, 1], [0, -headerHeight.value]), 19 + }, 20 + ], 21 + } 22 + }) 23 + 24 + return headerTransform 25 + } 26 + 27 + export function useMinimalShellFooterTransform() { 28 + const mode = useMinimalShellMode() 29 + const {footerHeight} = useShellLayout() 30 + 31 + const footerTransform = useAnimatedStyle(() => { 32 + return { 33 + pointerEvents: mode.value === 0 ? 'auto' : 'none', 34 + opacity: Math.pow(1 - mode.value, 2), 35 + transform: [ 36 + { 37 + translateY: interpolate(mode.value, [0, 1], [0, footerHeight.value]), 38 + }, 39 + ], 40 + } 41 + }) 42 + return footerTransform 43 + } 44 + 45 + export function useMinimalShellFabTransform() { 46 + const mode = useMinimalShellMode() 47 + 48 + const fabTransform = useAnimatedStyle(() => { 49 + return { 50 + transform: [ 51 + { 52 + translateY: interpolate(mode.value, [0, 1], [-44, 0]), 53 + }, 54 + ], 55 + } 56 + }) 57 + return fabTransform 58 + }
+2 -2
src/view/com/home/HomeHeaderLayout.web.tsx
··· 11 11 import {CogIcon} from '#/lib/icons' 12 12 import {useSession} from '#/state/session' 13 13 import {useShellLayout} from '#/state/shell/shell-layout' 14 - import {useMinimalShellMode} from 'lib/hooks/useMinimalShellMode' 14 + import {useMinimalShellHeaderTransform} from 'lib/hooks/useMinimalShellTransform' 15 15 import {usePalette} from 'lib/hooks/usePalette' 16 16 import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' 17 17 import {Logo} from '#/view/icons/Logo' ··· 39 39 tabBarAnchor: JSX.Element | null | undefined 40 40 }) { 41 41 const pal = usePalette('default') 42 - const {headerMinimalShellTransform} = useMinimalShellMode() 42 + const headerMinimalShellTransform = useMinimalShellHeaderTransform() 43 43 const {headerHeight} = useShellLayout() 44 44 const {hasSession} = useSession() 45 45 const {_} = useLingui()
+2 -2
src/view/com/home/HomeHeaderLayoutMobile.tsx
··· 10 10 import {useSetDrawerOpen} from '#/state/shell/drawer-open' 11 11 import {useShellLayout} from '#/state/shell/shell-layout' 12 12 import {HITSLOP_10} from 'lib/constants' 13 - import {useMinimalShellMode} from 'lib/hooks/useMinimalShellMode' 13 + import {useMinimalShellHeaderTransform} from 'lib/hooks/useMinimalShellTransform' 14 14 import {usePalette} from 'lib/hooks/usePalette' 15 15 import {isWeb} from 'platform/detection' 16 16 import {Logo} from '#/view/icons/Logo' ··· 30 30 const {_} = useLingui() 31 31 const setDrawerOpen = useSetDrawerOpen() 32 32 const {headerHeight} = useShellLayout() 33 - const {headerMinimalShellTransform} = useMinimalShellMode() 33 + const headerMinimalShellTransform = useMinimalShellHeaderTransform() 34 34 const {hasSession} = useSession() 35 35 36 36 const onPressAvi = React.useCallback(() => {
+2 -2
src/view/com/util/ViewHeader.tsx
··· 8 8 9 9 import {useSetDrawerOpen} from '#/state/shell' 10 10 import {useAnalytics} from 'lib/analytics/analytics' 11 - import {useMinimalShellMode} from 'lib/hooks/useMinimalShellMode' 11 + import {useMinimalShellHeaderTransform} from 'lib/hooks/useMinimalShellTransform' 12 12 import {usePalette} from 'lib/hooks/usePalette' 13 13 import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' 14 14 import {NavigationProp} from 'lib/routes/types' ··· 197 197 showBorder?: boolean 198 198 }) { 199 199 const pal = usePalette('default') 200 - const {headerMinimalShellTransform} = useMinimalShellMode() 200 + const headerMinimalShellTransform = useMinimalShellHeaderTransform() 201 201 202 202 if (!hideOnScroll) { 203 203 return (
+2 -2
src/view/com/util/fab/FABInner.tsx
··· 4 4 import {useSafeAreaInsets} from 'react-native-safe-area-context' 5 5 import {LinearGradient} from 'expo-linear-gradient' 6 6 7 - import {useMinimalShellMode} from '#/lib/hooks/useMinimalShellMode' 7 + import {useMinimalShellFabTransform} from '#/lib/hooks/useMinimalShellTransform' 8 8 import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries' 9 9 import {clamp} from '#/lib/numbers' 10 10 import {gradients} from '#/lib/styles' ··· 20 20 export function FABInner({testID, icon, ...props}: FABProps) { 21 21 const insets = useSafeAreaInsets() 22 22 const {isMobile, isTablet} = useWebMediaQueries() 23 - const {fabMinimalShellTransform} = useMinimalShellMode() 23 + const fabMinimalShellTransform = useMinimalShellFabTransform() 24 24 const { 25 25 state: pressed, 26 26 onIn: onPressIn,
+2 -2
src/view/com/util/load-latest/LoadLatestBtn.tsx
··· 6 6 import {useMediaQuery} from 'react-responsive' 7 7 8 8 import {HITSLOP_20} from '#/lib/constants' 9 - import {useMinimalShellMode} from '#/lib/hooks/useMinimalShellMode' 9 + import {useMinimalShellFabTransform} from '#/lib/hooks/useMinimalShellTransform' 10 10 import {usePalette} from '#/lib/hooks/usePalette' 11 11 import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries' 12 12 import {clamp} from '#/lib/numbers' ··· 30 30 const pal = usePalette('default') 31 31 const {hasSession} = useSession() 32 32 const {isDesktop, isTablet, isMobile, isTabletOrMobile} = useWebMediaQueries() 33 - const {fabMinimalShellTransform} = useMinimalShellMode() 33 + const fabMinimalShellTransform = useMinimalShellFabTransform() 34 34 const insets = useSafeAreaInsets() 35 35 36 36 // move button inline if it starts overlapping the left nav
+2 -2
src/view/screens/PostThread.tsx
··· 14 14 import {useSession} from '#/state/session' 15 15 import {useSetMinimalShellMode} from '#/state/shell' 16 16 import {useComposerControls} from '#/state/shell/composer' 17 - import {useMinimalShellMode} from 'lib/hooks/useMinimalShellMode' 17 + import {useMinimalShellFabTransform} from 'lib/hooks/useMinimalShellTransform' 18 18 import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' 19 19 import {CommonNavigatorParams, NativeStackScreenProps} from 'lib/routes/types' 20 20 import {makeRecordUri} from 'lib/strings/url-helpers' ··· 26 26 export function PostThreadScreen({route}: Props) { 27 27 const queryClient = useQueryClient() 28 28 const {hasSession} = useSession() 29 - const {fabMinimalShellTransform} = useMinimalShellMode() 29 + const fabMinimalShellTransform = useMinimalShellFabTransform() 30 30 const setMinimalShellMode = useSetMinimalShellMode() 31 31 const {openComposer} = useComposerControls() 32 32 const safeAreaInsets = useSafeAreaInsets()
+2 -2
src/view/shell/bottom-bar/BottomBar.tsx
··· 10 10 import {useAnalytics} from '#/lib/analytics/analytics' 11 11 import {useHaptics} from '#/lib/haptics' 12 12 import {useDedupe} from '#/lib/hooks/useDedupe' 13 - import {useMinimalShellMode} from '#/lib/hooks/useMinimalShellMode' 13 + import {useMinimalShellFooterTransform} from '#/lib/hooks/useMinimalShellTransform' 14 14 import {useNavigationTabState} from '#/lib/hooks/useNavigationTabState' 15 15 import {usePalette} from '#/lib/hooks/usePalette' 16 16 import {clamp} from '#/lib/numbers' ··· 66 66 useNavigationTabState() 67 67 const numUnreadNotifications = useUnreadNotifications() 68 68 const numUnreadMessages = useUnreadMessageCount() 69 - const {footerMinimalShellTransform} = useMinimalShellMode() 69 + const footerMinimalShellTransform = useMinimalShellFooterTransform() 70 70 const {data: profile} = useProfileQuery({did: currentAccount?.did}) 71 71 const {requestSwitchToAccount} = useLoggedOutViewControls() 72 72 const closeAllActiveElements = useCloseAllActiveElements()
+2 -2
src/view/shell/bottom-bar/BottomBarWeb.tsx
··· 6 6 import {useLingui} from '@lingui/react' 7 7 import {useNavigationState} from '@react-navigation/native' 8 8 9 - import {useMinimalShellMode} from '#/lib/hooks/useMinimalShellMode' 9 + import {useMinimalShellFooterTransform} from '#/lib/hooks/useMinimalShellTransform' 10 10 import {usePalette} from '#/lib/hooks/usePalette' 11 11 import {clamp} from '#/lib/numbers' 12 12 import {getCurrentRoute, isTab} from '#/lib/routes/helpers' ··· 50 50 const pal = usePalette('default') 51 51 const safeAreaInsets = useSafeAreaInsets() 52 52 const gate = useGate() 53 - const {footerMinimalShellTransform} = useMinimalShellMode() 53 + const footerMinimalShellTransform = useMinimalShellFooterTransform() 54 54 const {requestSwitchToAccount} = useLoggedOutViewControls() 55 55 const closeAllActiveElements = useCloseAllActiveElements() 56 56 const iconWidth = 26