feat(mobile): add checkScrollToBottom functionality to SafeNavigationScrollView and integrate with TimelineSelectorList
Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -62,6 +62,14 @@ export const useRegisterNavigationScrollView = <T = unknown>(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<ScrollView>)
|
||||
}, [setAttachNavigationScrollViewRef, scrollViewRef, active, tabScreenIsFocused])
|
||||
|
||||
@@ -48,6 +48,9 @@ type SafeNavigationScrollViewProps = Omit<ScrollViewProps, "onScroll"> & {
|
||||
Header?: React.ReactNode
|
||||
} & PropsWithChildren
|
||||
|
||||
export interface ForwardedSafeNavigationScrollView extends ScrollView {
|
||||
checkScrollToBottom: () => void
|
||||
}
|
||||
export const SafeNavigationScrollView = forwardRef<ScrollView, SafeNavigationScrollViewProps>(
|
||||
(
|
||||
{
|
||||
@@ -74,7 +77,11 @@ export const SafeNavigationScrollView = forwardRef<ScrollView, SafeNavigationScr
|
||||
const screenCtxValue = useContext(ScreenItemContext)
|
||||
|
||||
const ref = useRef<ScrollView>(null)
|
||||
useImperativeHandle(forwardedRef, () => ref.current!)
|
||||
useImperativeHandle(forwardedRef, () => {
|
||||
return Object.assign({}, ref.current!, {
|
||||
checkScrollToBottom,
|
||||
})
|
||||
})
|
||||
const { opacity } = useContext(BottomTabBarBackgroundContext)
|
||||
|
||||
const inTabScreen = useInTabScreen()
|
||||
|
||||
@@ -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<NativeScrollEvent>) => {
|
||||
props.onScroll?.(e)
|
||||
|
||||
Reference in New Issue
Block a user