To implement a fully custom header (e.g., adding a back button, close button, or custom animations), use the renderHeaderBar prop. This prop accepts a function that returns a component.
To create elements that react to the scroll position (like a title that fades in only when the header is collapsed), you can capture the vertical content offset via the onScroll prop and pass it to your custom header component using a Reanimated shared value.
// 1. Capture scroll value
const scrollValue = useSharedValue(0);
const onScroll = (e) => {
'worklet';
scrollValue.value = e.contentOffset.y;
};
// 2. Create custom header using the shared value
const HeaderBar = ({ scrollValue }) => {
const animatedStyle = useAnimatedStyle(() => ({
opacity: interpolate(scrollValue.value, [0, 60, 90], [0, 0, 1], Extrapolate.CLAMP)
}));
return (
<View>
<Animated.View style={animatedStyle}>
<Text>Custom Title</Text>
</Animated.View>
</View>
);
};
// 3. Pass to TabbedHeaderPager
<TabbedHeaderPager
onScroll={onScroll}
renderHeaderBar={() => <HeaderBar scrollValue={scrollValue} />}
{/* ... other props */}
/>