-
Notifications
You must be signed in to change notification settings - Fork 187
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
related: #28
- Loading branch information
Showing
4 changed files
with
116 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
example/src/CollapsibleTabViewScrollOnHeaderExample.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
import * as React from 'react'; | ||
import { StyleSheet, View, Text } from 'react-native'; | ||
import { SceneMap } from 'react-native-tab-view'; | ||
|
||
import { | ||
CollapsibleTabView, | ||
useCollapsibleScene, | ||
CollapsibleTabViewProps, | ||
} from 'react-native-collapsible-tab-view'; | ||
|
||
import { AnimatedAlbums } from './Shared/Albums'; | ||
import { AnimatedArticle } from './Shared/Article'; | ||
import { AnimatedContacts } from './Shared/Contacts'; | ||
import { ExampleComponentType } from './types'; | ||
|
||
type Route = { | ||
key: string; | ||
title: string; | ||
}; | ||
|
||
export const ContactsScene = () => { | ||
const scenePropsAndRef = useCollapsibleScene('contacts'); | ||
return <AnimatedContacts {...scenePropsAndRef} />; | ||
}; | ||
|
||
export const ArticleScene = () => { | ||
const scenePropsAndRef = useCollapsibleScene('article'); | ||
return <AnimatedArticle {...scenePropsAndRef} />; | ||
}; | ||
|
||
export const AlbumsScene = () => { | ||
const scenePropsAndRef = useCollapsibleScene('albums'); | ||
return <AnimatedAlbums {...scenePropsAndRef} />; | ||
}; | ||
|
||
export const HEADER_HEIGHT = 550; | ||
|
||
const renderHeader = () => ( | ||
<View pointerEvents="none" style={styles.header}> | ||
<Text style={styles.headerText}> | ||
You can set pointerEvents="none" | "box-none" to allow | ||
scrolling on the header. It works as expected, but you can also consider | ||
using disableSnap if your header is too large (like in this example). | ||
</Text> | ||
</View> | ||
); | ||
|
||
const renderScene = SceneMap({ | ||
albums: AlbumsScene, | ||
contacts: ContactsScene, | ||
article: ArticleScene, | ||
}); | ||
|
||
const CollapsibleTabViewExample: ExampleComponentType<Partial< | ||
Partial<CollapsibleTabViewProps<Route>> | ||
>> = (props) => { | ||
const [index, setIndex] = React.useState(0); | ||
const [routes] = React.useState<Route[]>([ | ||
{ key: 'article', title: 'Article' }, | ||
{ key: 'contacts', title: 'Contacts' }, | ||
{ key: 'albums', title: 'Albums' }, | ||
]); | ||
|
||
const handleIndexChange = (index: number) => { | ||
setIndex(index); | ||
}; | ||
|
||
return ( | ||
<CollapsibleTabView<Route> | ||
navigationState={{ index, routes }} | ||
renderScene={renderScene} | ||
onIndexChange={handleIndexChange} | ||
renderHeader={renderHeader} | ||
headerHeight={HEADER_HEIGHT} | ||
disableSnap | ||
{...props} | ||
/> | ||
); | ||
}; | ||
|
||
CollapsibleTabViewExample.title = 'Scroll on header'; | ||
CollapsibleTabViewExample.backgroundColor = '#2196f3'; | ||
CollapsibleTabViewExample.appbarElevation = 0; | ||
|
||
export default CollapsibleTabViewExample; | ||
|
||
const styles = StyleSheet.create({ | ||
header: { | ||
height: HEADER_HEIGHT, | ||
backgroundColor: '#2196f3', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
elevation: 4, | ||
}, | ||
headerText: { | ||
color: 'white', | ||
fontSize: 18, | ||
padding: 16, | ||
textAlign: 'center', | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters