import { useTypeScriptHappyCallback } from "@follow/hooks" import { useAtomValue } from "jotai" import type { FC } from "react" import { useContext, useState } from "react" import { useWindowDimensions, View } from "react-native" import type { SharedValue } from "react-native-reanimated" import Animated, { interpolate, runOnJS, useAnimatedReaction, useAnimatedStyle, useSharedValue, withTiming, } from "react-native-reanimated" import { useUISettingKey } from "@/src/atoms/settings/ui" import { DefaultHeaderBackButton } from "@/src/components/layouts/header/NavigationHeader" import { NavigationBlurEffectHeaderView } from "@/src/components/layouts/views/SafeNavigationScrollView" import { ScreenItemContext } from "@/src/lib/navigation/ScreenItemContext" import { useEntry } from "@/src/store/entry/hooks" import { useHeaderHeight } from "../screen/hooks/useHeaderHeight" import { EntryContentContext } from "./ctx" import { EntryContentHeaderRightActions } from "./EntryContentHeaderRightActions" import { EntryReadHistory } from "./EntryReadHistory" export const EntryNavigationHeader: FC<{ entryId: string }> = ({ entryId }) => { const opacityAnimatedValue = useSharedValue(0) const headerHeight = useHeaderHeight() const title = useEntry(entryId, (entry) => { return entry.title }) const [isHeaderTitleVisible, setIsHeaderTitleVisible] = useState(true) const reanimatedScrollY = useContext(ScreenItemContext).reAnimatedScrollY const ctxValue = useContext(EntryContentContext) const titleHeight = useAtomValue(ctxValue.titleHeightAtom) useAnimatedReaction( () => reanimatedScrollY.value, (value) => { if (value > titleHeight + headerHeight) { opacityAnimatedValue.value = withTiming(1, { duration: 100 }) runOnJS(setIsHeaderTitleVisible)(true) } else { opacityAnimatedValue.value = withTiming(0, { duration: 100 }) runOnJS(setIsHeaderTitleVisible)(false) } }, ) const headerBarWidth = useWindowDimensions().width return ( ( ), [entryId], )} headerRight={ } headerTitle={ {title} } /> ) } interface EntryLeftGroupProps { canGoBack: boolean entryId: string titleOpacityShareValue: SharedValue } const EntryLeftGroup = ({ canGoBack, entryId, titleOpacityShareValue }: EntryLeftGroupProps) => { const hideRecentReader = useUISettingKey("hideRecentReader") const animatedOpacity = useAnimatedStyle(() => { return { opacity: interpolate(titleOpacityShareValue.value, [0, 1], [1, 0]), } }) return ( {!hideRecentReader && ( )} ) }