fix: improve header height and scroll behavior for timeline and subscriptions
Signed-off-by: Innei <tukon479@gmail.com>
This commit is contained in:
@@ -86,12 +86,12 @@ export const SafeNavigationScrollView: FC<SafeNavigationScrollViewProps> = ({
|
||||
|
||||
export const NavigationBlurEffectHeader = ({
|
||||
blurThreshold = 0,
|
||||
headerHideableBottomHeight = 50,
|
||||
|
||||
headerHideableBottom,
|
||||
...props
|
||||
}: NativeStackNavigationOptions & {
|
||||
blurThreshold?: number
|
||||
headerHideableBottomHeight?: number
|
||||
|
||||
headerHideableBottom?: () => React.ReactNode
|
||||
}) => {
|
||||
const label = useColor("label")
|
||||
@@ -105,23 +105,28 @@ export const NavigationBlurEffectHeader = ({
|
||||
const opacityAnimated = useSharedValue(0)
|
||||
|
||||
const originalDefaultHeaderHeight = useDefaultHeaderHeight()
|
||||
const largeDefaultHeaderHeight = originalDefaultHeaderHeight + headerHideableBottomHeight
|
||||
|
||||
const largeHeaderHeight = useSharedValue(largeDefaultHeaderHeight)
|
||||
|
||||
const lastScrollY = useRef(0)
|
||||
|
||||
const largeDefaultHeaderHeightRef = useRef(originalDefaultHeaderHeight)
|
||||
const largeHeaderHeight = useSharedValue(originalDefaultHeaderHeight)
|
||||
|
||||
useEffect(() => {
|
||||
const id = scrollY.addListener(({ value }) => {
|
||||
opacityAnimated.value = Math.max(0, Math.min(1, (value + blurThreshold) / 10))
|
||||
if (headerHideableBottom && value > 0) {
|
||||
if (value > lastScrollY.current) {
|
||||
largeHeaderHeight.value = withTiming(originalDefaultHeaderHeight)
|
||||
} else {
|
||||
largeHeaderHeight.value = withTiming(largeDefaultHeaderHeight)
|
||||
}
|
||||
lastScrollY.current = value
|
||||
if (!headerHideableBottom) {
|
||||
return
|
||||
}
|
||||
const largeDefaultHeaderHeight = largeDefaultHeaderHeightRef.current
|
||||
|
||||
if (value <= 100) {
|
||||
largeHeaderHeight.value = withTiming(largeDefaultHeaderHeight)
|
||||
} else if (value > lastScrollY.current) {
|
||||
largeHeaderHeight.value = withTiming(originalDefaultHeaderHeight)
|
||||
} else {
|
||||
largeHeaderHeight.value = withTiming(largeDefaultHeaderHeight)
|
||||
}
|
||||
lastScrollY.current = value
|
||||
})
|
||||
|
||||
return () => {
|
||||
@@ -129,12 +134,11 @@ export const NavigationBlurEffectHeader = ({
|
||||
}
|
||||
}, [
|
||||
blurThreshold,
|
||||
scrollY,
|
||||
headerHideableBottom,
|
||||
largeHeaderHeight,
|
||||
originalDefaultHeaderHeight,
|
||||
largeDefaultHeaderHeight,
|
||||
opacityAnimated,
|
||||
originalDefaultHeaderHeight,
|
||||
scrollY,
|
||||
])
|
||||
|
||||
const style = useAnimatedStyle(() => ({
|
||||
@@ -176,8 +180,18 @@ export const NavigationBlurEffectHeader = ({
|
||||
</View>
|
||||
|
||||
<Header title={options.title ?? ""} {...options} headerBackground={() => null} />
|
||||
{hideableBottom && (
|
||||
<View
|
||||
onLayout={(e) => {
|
||||
const { height } = e.nativeEvent.layout
|
||||
|
||||
{hideableBottom}
|
||||
largeDefaultHeaderHeightRef.current = height + originalDefaultHeaderHeight
|
||||
largeHeaderHeight.value = withTiming(largeDefaultHeaderHeightRef.current)
|
||||
}}
|
||||
>
|
||||
{hideableBottom}
|
||||
</View>
|
||||
)}
|
||||
</Animated.View>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import {
|
||||
HomeSharedRightAction,
|
||||
UnreadOnlyActionButton,
|
||||
} from "@/src/modules/screen/action"
|
||||
import { headerHideableBottomHeight } from "@/src/modules/screen/hooks/useHeaderHeight"
|
||||
import { TimelineViewSelector } from "@/src/modules/screen/TimelineViewSelector"
|
||||
import { getFeed } from "@/src/store/feed/getter"
|
||||
|
||||
@@ -69,9 +68,6 @@ export function TimelineSelectorProvider({ children }: { children: React.ReactNo
|
||||
)
|
||||
return
|
||||
}, [isFeed, view, isTimeline, isSubscriptions, params])}
|
||||
headerHideableBottomHeight={
|
||||
isTimeline || isSubscriptions ? headerHideableBottomHeight : undefined
|
||||
}
|
||||
headerHideableBottom={isTimeline || isSubscriptions ? TimelineViewSelector : undefined}
|
||||
/>
|
||||
{children}
|
||||
|
||||
@@ -8,7 +8,7 @@ export const useHeaderHeight = () => {
|
||||
const screenType = useEntryListContext().type
|
||||
const originalDefaultHeaderHeight = useDefaultHeaderHeight()
|
||||
const headerHeight =
|
||||
screenType === "timeline"
|
||||
screenType === "timeline" || screenType === "subscriptions"
|
||||
? originalDefaultHeaderHeight + headerHideableBottomHeight
|
||||
: originalDefaultHeaderHeight
|
||||
|
||||
|
||||
Reference in New Issue
Block a user