Skip to main content
Version: 0.4.x

Custom Header

Custom Header Props

PropertyTypeRequiredDefaultDescription
backgroundReactNodeNo-This renders background component
backgroundColorstringYes""Header background color
backgroundImageImageSourcePropTypeNo-This renders background image instead of background component
bouncesbooleanNotrueBounces on swiping up
childrenReactNodeNo-This renders all the children inside the component
contentContainerStylesStyleProp<ViewStyle>No-Set scroll view body styles
decelerationRate"fast" or "normal"No"fast"A floating-point number that determines how quickly the scroll view decelerates after the user lifts their finger.
foregroundReactNodeYes-This renders foreground component
headerReactNodeYes-This renders header component
headerHeightnumberNo92Sets height of folded header
headerSize(h: LayoutRectangle): voidNo-Handler that is called when header's size changes
initialPagenumberNo0Set initial page of tab bar
keyboardShouldPersistTapsboolean, "always", "never", "handled"NoSet keyboard persist taps method
onChangeTab({ i, ref, from }: { from: number; i: number; ref: any; }) => void;No-Tab change event
onEndReached() => voidNo-Reached end event
onTopReached() => voidNo-Reached top event
onMomentumScrollBegin(event: NativeSyntheticEvent<NativeScrollEvent>) => voidNoCalled when the momentum scroll starts (scroll which occurs as the ScrollView starts gliding)
onMomentumScrollEnd(event: NativeSyntheticEvent<NativeScrollEvent>) => voidNoCalled when the momentum scroll ends (scroll which occurs as the ScrollView glides to a stop)
onRef(t: null, StickyParallaxHeaderComponent) => voidNoObtain ref for StickyParallaxHeaderComponent
parallaxHeightnumberNoSet parallax header height
refreshControlelementNoA RefreshControl component, used to provide pull-to-refresh functionality
rememberTabScrollPositionboolNofalseWhen switching between tabs remember current scroll position
scrollEvent (event: NativeSyntheticEvent<NativeScrollEvent>) => voidNoReturns offset of header to apply custom animations. Fires at most once per frame during scrolling (Used in custom animations)
scrollRef(t: ScrollView) => void | MutableRefObject<ScrollView>NoGet inner ScrollView ref
snapStartThresholdnumberNo-Set start value Threshold of snap
snapStopThresholdnumberNo-Set stop value Threshold of snap
snapToEdgebooleanNotrueBoolean to fire the function for snap To Edge
snapValuenumberNo-Set value where header is closed
tabTextActiveStyleTextStyleNo{}Text styles of active tab
tabTextContainerActiveStyleViewStyleNo{}Container styles of active tab
tabTextContainerStyleViewStyleNo{}Container styles of tab
tabTextStyleTextStyleNo{}Text styles of tab
tabWrapperStyleViewStyleNo{}Tabs Wrapper styles
tabs{ content: ReactElement; title: string; }[]No-Array of tab names
tabsContainerBackgroundColorViewStyleNo-Background color of tab bar container
tabsContainerStyleViewStyleNo-Set whole tab bar container style
transparentHeaderbooleanNofalseSet header transparency to render custom header

Usage

Here is a basic example of how you can create a custom header

import * as React from 'react'
import { Text, View, Animated, StyleSheet } from 'react-native'
import StickyParallaxHeader from 'react-native-sticky-parallax-header'
const styles = StyleSheet.create({
content: {
height: 1000,
marginTop: 50
},
foreground: {
flex: 1,
justifyContent: 'flex-end'
},
message: {
color: 'white',
fontSize: 40,
paddingTop: 24,
paddingBottom: 7
},
headerWrapper: {
backgroundColor: 'green',
width: '100%',
paddingHorizontal: 24,
paddingBottom: 25,
flexDirection: 'row',
alignItems: 'center'
},
headerTitle: {
fontSize: 16,
color: 'white',
margin: 12
},
tabsWrapper: {
paddingVertical: 12
},
tabTextContainerStyle: {
backgroundColor: 'transparent',
borderRadius: 18
},
tabTextContainerActiveStyle: {
backgroundColor: 'lightgreen'
},
tabText: {
fontSize: 16,
lineHeight: 20,
paddingHorizontal: 12,
paddingVertical: 8,
color: 'white'
}
})
class TabScreen extends React.Component {
state = {
scroll: new Animated.Value(0)
}

componentDidMount() {
const { scroll } = this.state
scroll.addListener(({ value }) => (this._value = value))
}

renderContent = (label) => (
<View style={styles.content}>
<Text>{label}</Text>
</View>
)

renderForeground = () => {
const { scroll } = this.state
const titleOpacity = scroll.interpolate({
inputRange: [0, 106, 154],
outputRange: [1, 1, 0],
extrapolate: 'clamp'
})

return (
<View style={styles.foreground}>
<Animated.View style={{ opacity: titleOpacity }}>
<Text style={styles.message}>STICKY HEADER</Text>
</Animated.View>
</View>
)
}

renderHeader = () => {
const { scroll } = this.state
const opacity = scroll.interpolate({
inputRange: [0, 160, 210],
outputRange: [0, 0, 1],
extrapolate: 'clamp'
})

return (
<View style={styles.headerWrapper}>
<Animated.View style={{ opacity }}>
<Text style={styles.headerTitle}>STICKY HEADER</Text>
</Animated.View>
</View>
)
}

render() {
const { scroll } = this.state

return (
<StickyParallaxHeader
foreground={this.renderForeground()}
header={this.renderHeader()}
parallaxHeight={200}
headerHeight={90}
headerSize={() => {}}
onEndReached={() => {}}
scrollEvent={Animated.event([{ nativeEvent: { contentOffset: { y: scroll } } }])}
tabs={[
{
title: 'First Tab',
content: this.renderContent('FIRST TAB')
},
{
title: 'Second Tab',
content: this.renderContent('SECOND TAB')
},
{
title: 'Third Tab',
content: this.renderContent('THIRD TAB')
},
{
title: 'Fourth Tab',
content: this.renderContent('FOURTH TAB')
},
{
title: 'Fifth Tab',
content: this.renderContent('FIFTH TAB')
}
]}
tabTextStyle={styles.tabText}
tabTextContainerStyle={styles.tabTextContainerStyle}
tabTextContainerActiveStyle={styles.tabTextContainerActiveStyle}
tabsContainerBackgroundColor={'green'}
tabsWrapperStyle={styles.tabsWrapper}
>
</StickyParallaxHeader>
)
}
}