-
Notifications
You must be signed in to change notification settings - Fork 213
Feat/header touchables and horizontal scroll #254
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
tiagocorreiaalmeida
wants to merge
6
commits into
PedroBern:main
Choose a base branch
from
tiagocorreiaalmeida:feat/header-touchables-and-horizontal-scroll
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fe16dbc
feat(header): add pan gesture handler to allow touchable and scrollab…
tiagocorreiaalmeida a24469b
fix(example): remove invalid line
tiagocorreiaalmeida 9d37f13
feat(header): extra header and tabbar container from container file
tiagocorreiaalmeida 083dabd
feat(top-container): extract top container to new file
tiagocorreiaalmeida 0120e98
feat(header): ensure header properly syncs for snaps and reveal heade…
tiagocorreiaalmeida 1df25a7
fix(header): ensure all props are passed to top container
tiagocorreiaalmeida File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,90 @@ | ||
import React, { useMemo } from 'react' | ||
import { | ||
StyleSheet, | ||
View, | ||
FlatList, | ||
Text, | ||
Alert, | ||
TouchableOpacity, | ||
} from 'react-native' | ||
|
||
import { TabBarProps } from '../../src/types' | ||
import ExampleComponent from './Shared/ExampleComponent' | ||
import { ExampleComponentType } from './types' | ||
|
||
const title = 'Scroll On Header with Touchables' | ||
|
||
const SLIDER_ITEM_SIZE = 200 | ||
const HEADER_HEIGHT = SLIDER_ITEM_SIZE * 2 | ||
|
||
const data = Array.from({ length: 15 }).map((_, i) => i.toString()) | ||
|
||
const styles = StyleSheet.create({ | ||
item: { | ||
width: SLIDER_ITEM_SIZE, | ||
height: SLIDER_ITEM_SIZE, | ||
alignItems: 'center', | ||
justifyContent: 'center', | ||
}, | ||
itemButton: { | ||
padding: 16, | ||
backgroundColor: 'white', | ||
}, | ||
itemName: { | ||
fontSize: 48, | ||
color: 'black', | ||
}, | ||
itemSeparator: { width: 4 }, | ||
}) | ||
|
||
const Slider = ({ isReversed = false }) => { | ||
const config = useMemo( | ||
() => ({ | ||
data: isReversed ? [...data].reverse() : data, | ||
backgroundColor: isReversed ? 'purple' : 'orangered', | ||
}), | ||
[isReversed] | ||
) | ||
|
||
return ( | ||
<FlatList | ||
data={config.data} | ||
horizontal | ||
keyExtractor={(item) => item} | ||
showsHorizontalScrollIndicator={false} | ||
ItemSeparatorComponent={() => <View style={styles.itemSeparator} />} | ||
bounces={false} | ||
renderItem={({ item }) => ( | ||
<View | ||
style={[styles.item, { backgroundColor: config.backgroundColor }]} | ||
> | ||
<TouchableOpacity | ||
style={styles.itemButton} | ||
onPress={() => Alert.alert(`Touchable number ${item} pressed`)} | ||
> | ||
<Text style={styles.itemName}>{item}</Text> | ||
</TouchableOpacity> | ||
</View> | ||
)} | ||
/> | ||
) | ||
} | ||
|
||
const NewHeader: React.FC<TabBarProps> = () => { | ||
return ( | ||
<View> | ||
<Slider /> | ||
<Slider isReversed /> | ||
</View> | ||
) | ||
} | ||
|
||
const DefaultExample: ExampleComponentType = () => { | ||
return ( | ||
<ExampleComponent renderHeader={NewHeader} headerHeight={HEADER_HEIGHT} /> | ||
) | ||
} | ||
|
||
DefaultExample.title = title | ||
|
||
export default DefaultExample |
This file contains hidden or 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 hidden or 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,55 @@ | ||
import React from 'react' | ||
import { LayoutChangeEvent, StyleSheet, View } from 'react-native' | ||
|
||
import { useTabsContext } from './hooks' | ||
import { CollapsibleProps, TabBarProps, TabName } from './types' | ||
|
||
type HeaderContainerProps<T extends TabName = TabName> = Pick< | ||
CollapsibleProps, | ||
'renderHeader' | ||
> & | ||
Pick<TabBarProps<T>, 'containerRef' | 'onTabPress' | 'tabProps'> & { | ||
tabNamesArray: TabName[] | ||
} | ||
|
||
export const HeaderContainer: React.FC<HeaderContainerProps> = ({ | ||
renderHeader, | ||
containerRef, | ||
tabNamesArray, | ||
onTabPress, | ||
tabProps, | ||
}) => { | ||
const { headerHeight, focusedTab, index, indexDecimal } = useTabsContext() | ||
|
||
const getHeaderHeight = React.useCallback( | ||
(event: LayoutChangeEvent) => { | ||
const height = event.nativeEvent.layout.height | ||
if (headerHeight.value !== height) { | ||
headerHeight.value = height | ||
} | ||
}, | ||
[headerHeight] | ||
) | ||
|
||
return ( | ||
<View style={[styles.container]} onLayout={getHeaderHeight}> | ||
{renderHeader && | ||
renderHeader({ | ||
containerRef, | ||
index, | ||
tabNames: tabNamesArray, | ||
focusedTab, | ||
indexDecimal, | ||
onTabPress, | ||
tabProps, | ||
})} | ||
</View> | ||
) | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
zIndex: 2, | ||
flex: 1, | ||
}, | ||
}) |
This file contains hidden or 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,52 @@ | ||
import React from 'react' | ||
import { LayoutChangeEvent, StyleSheet, View } from 'react-native' | ||
|
||
import { useTabsContext } from './hooks' | ||
import { CollapsibleProps, TabBarProps, TabName } from './types' | ||
|
||
type TabBarContainerProps<T extends TabName = TabName> = Pick< | ||
CollapsibleProps, | ||
'renderTabBar' | 'width' | ||
> & | ||
Pick<TabBarProps<T>, 'onTabPress' | 'tabProps' | 'containerRef'> & { | ||
tabNamesArray: TabName[] | ||
} | ||
|
||
export const TabBarContainer: React.FC<TabBarContainerProps> = ({ | ||
renderTabBar, | ||
onTabPress, | ||
tabProps, | ||
tabNamesArray, | ||
containerRef, | ||
width, | ||
}) => { | ||
const { tabBarHeight, focusedTab, index, indexDecimal } = useTabsContext() | ||
|
||
const getTabBarHeight = React.useCallback( | ||
(event: LayoutChangeEvent) => { | ||
const height = event.nativeEvent.layout.height | ||
if (tabBarHeight.value !== height) tabBarHeight.value = height | ||
}, | ||
[tabBarHeight] | ||
) | ||
|
||
return ( | ||
<View style={[styles.container]} onLayout={getTabBarHeight}> | ||
{renderTabBar && | ||
renderTabBar({ | ||
containerRef, | ||
index, | ||
tabNames: tabNamesArray, | ||
focusedTab, | ||
indexDecimal, | ||
width, | ||
onTabPress, | ||
tabProps, | ||
})} | ||
</View> | ||
) | ||
} | ||
|
||
const styles = StyleSheet.create({ | ||
container: { flex: 1, zIndex: 1 }, | ||
}) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.