From 31a8701d2c65374a98e80eaf20a6ebafbcd9f07d Mon Sep 17 00:00:00 2001 From: Innei Date: Mon, 14 Apr 2025 19:45:58 +0800 Subject: [PATCH] feat(mobile): add checkScrollToBottom functionality to SafeNavigationScrollView and integrate with TimelineSelectorList Signed-off-by: Innei --- apps/mobile/src/components/layouts/tabbar/hooks.ts | 8 ++++++++ .../layouts/views/SafeNavigationScrollView.tsx | 9 ++++++++- apps/mobile/src/modules/screen/TimelineSelectorList.tsx | 9 ++++++++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/apps/mobile/src/components/layouts/tabbar/hooks.ts b/apps/mobile/src/components/layouts/tabbar/hooks.ts index 2eafaa968..79020196f 100644 --- a/apps/mobile/src/components/layouts/tabbar/hooks.ts +++ b/apps/mobile/src/components/layouts/tabbar/hooks.ts @@ -62,6 +62,14 @@ export const useRegisterNavigationScrollView = (active = true) => { if (!active) return if (!setAttachNavigationScrollViewRef) return if (!tabScreenIsFocused) return + if ( + scrollViewRef.current && + typeof scrollViewRef.current === "object" && + "checkScrollToBottom" in scrollViewRef.current && + typeof scrollViewRef.current.checkScrollToBottom === "function" + ) { + scrollViewRef.current.checkScrollToBottom() + } setAttachNavigationScrollViewRef(scrollViewRef as unknown as RefObject) }, [setAttachNavigationScrollViewRef, scrollViewRef, active, tabScreenIsFocused]) diff --git a/apps/mobile/src/components/layouts/views/SafeNavigationScrollView.tsx b/apps/mobile/src/components/layouts/views/SafeNavigationScrollView.tsx index ba649340d..8d3bc1303 100644 --- a/apps/mobile/src/components/layouts/views/SafeNavigationScrollView.tsx +++ b/apps/mobile/src/components/layouts/views/SafeNavigationScrollView.tsx @@ -48,6 +48,9 @@ type SafeNavigationScrollViewProps = Omit & { Header?: React.ReactNode } & PropsWithChildren +export interface ForwardedSafeNavigationScrollView extends ScrollView { + checkScrollToBottom: () => void +} export const SafeNavigationScrollView = forwardRef( ( { @@ -74,7 +77,11 @@ export const SafeNavigationScrollView = forwardRef(null) - useImperativeHandle(forwardedRef, () => ref.current!) + useImperativeHandle(forwardedRef, () => { + return Object.assign({}, ref.current!, { + checkScrollToBottom, + }) + }) const { opacity } = useContext(BottomTabBarBackgroundContext) const inTabScreen = useInTabScreen() diff --git a/apps/mobile/src/modules/screen/TimelineSelectorList.tsx b/apps/mobile/src/modules/screen/TimelineSelectorList.tsx index 166a4321a..d759588c5 100644 --- a/apps/mobile/src/modules/screen/TimelineSelectorList.tsx +++ b/apps/mobile/src/modules/screen/TimelineSelectorList.tsx @@ -8,7 +8,7 @@ import type { import { FlashList, MasonryFlashList } from "@shopify/flash-list" import * as Haptics from "expo-haptics" import type { ElementRef, RefObject } from "react" -import { forwardRef, useCallback, useContext, useImperativeHandle, useRef } from "react" +import { forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useRef } from "react" import type { NativeScrollEvent, NativeSyntheticEvent } from "react-native" import { findNodeHandle, RefreshControl } from "react-native" import { useSafeAreaInsets } from "react-native-safe-area-context" @@ -17,6 +17,7 @@ import { useColor } from "react-native-uikit-colors" import { BottomTabBarBackgroundContext } from "@/src/components/layouts/tabbar/contexts/BottomTabBarBackgroundContext" import { useBottomTabBarHeight } from "@/src/components/layouts/tabbar/hooks" import { isScrollToEnd } from "@/src/lib/native" +import { useTabScreenIsFocused } from "@/src/lib/navigation/bottom-tab/hooks" import { ScreenItemContext } from "@/src/lib/navigation/ScreenItemContext" import { useHeaderHeight } from "@/src/modules/screen/hooks/useHeaderHeight" import { usePrefetchSubscription } from "@/src/store/subscription/hooks" @@ -51,6 +52,12 @@ export const TimelineSelectorList = forwardRef< opacity.value = isEnd ? 0 : 1 }) }, [opacity]) + const tabScreenIsFocus = useTabScreenIsFocused() + useEffect(() => { + if (tabScreenIsFocus) { + checkScrollToBottom() + } + }, [checkScrollToBottom, tabScreenIsFocus]) const onScroll = useCallback( (e: NativeSyntheticEvent) => { props.onScroll?.(e)