Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import ScrollOnHeader from './ScrollOnHeader'
import ScrollableTabs from './ScrollableTabs'
import Snap from './Snap'
import StartOnSpecificTab from './StartOnSpecificTab'
import StretchableHeader from './StretchableHeader'
import UndefinedHeaderHeight from './UndefinedHeaderHeight'
import { ExampleComponentType } from './types'

Expand All @@ -49,6 +50,7 @@ const EXAMPLE_COMPONENTS: ExampleComponentType[] = [
DynamicTabs,
MinHeaderHeight,
AnimatedHeader,
StretchableHeader,
AndroidSharedPullToRefresh,
HeaderOverscrollExample,
]
Expand Down
65 changes: 65 additions & 0 deletions example/src/StretchableHeader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React from 'react'
import { StyleSheet, ImageBackground } from 'react-native'
import { useHeaderMeasurements } from 'react-native-collapsible-tab-view'
import Animated, { useAnimatedStyle } from 'react-native-reanimated'

import ExampleComponent from './Shared/ExampleComponent'
import { ExampleComponentType } from './types'

const title = 'Stretchable Header'
const HEADER_HEIGHT = 250

export const Header = () => {
const { top } = useHeaderMeasurements()

const backgroundStyle = useAnimatedStyle(() => {
return {
transform: [
{
translateY: Math.min(0, -top.value / 2),
},
{
scale: Math.max(1, (HEADER_HEIGHT + top.value) / HEADER_HEIGHT),
},
],
}
})

return (
<Animated.View style={[styles.root]} pointerEvents="none">
<Animated.View style={[styles.background, backgroundStyle]}>
<ImageBackground
style={styles.image}
source={require('../assets/album-art-2.jpg')}
/>
</Animated.View>
</Animated.View>
)
}

const Example: ExampleComponentType = () => {
return (
<ExampleComponent renderHeader={() => <Header />} allowHeaderOverscroll />
)
}

const styles = StyleSheet.create({
root: {
justifyContent: 'center',
alignItems: 'center',
height: HEADER_HEIGHT,
},
background: {
position: 'absolute',
width: '100%',
height: '100%',
},
image: {
width: '100%',
height: '100%',
},
})

Example.title = title

export default Example