-
-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* chore: make separator memoized (#9) * chore: allow to override ItemSeparatorComponent * docs: updated readme file * chore: added BasicCustomSeparator to example Co-authored-by: Hirbod <Hirbod@users.noreply.github.com>
- Loading branch information
Showing
8 changed files
with
192 additions
and
16 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
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,118 @@ | ||
import React from 'react'; | ||
import { | ||
StyleSheet, | ||
View, | ||
SafeAreaView, | ||
StatusBar, | ||
Text, | ||
Alert, | ||
Platform, | ||
ListRenderItemInfo, | ||
} from 'react-native'; | ||
import { TouchableOpacity } from 'react-native-gesture-handler'; | ||
import { useRoute } from '@react-navigation/native'; | ||
import StickyItemFlatList from '@gorhom/sticky-item'; | ||
import DummyItem from '../components/dummy-item'; | ||
import BasicSticky from '../components/basic-sticky'; | ||
|
||
const data = [...Array(20)] | ||
.fill(0) | ||
.map((_, index) => ({ id: `item-${index}` })); | ||
|
||
export const STORY_WIDTH = 200; | ||
export const STORY_HEIGHT = 100; | ||
const SEPARATOR_SIZE = 10; | ||
const BORDER_RADIUS = 0; | ||
|
||
const BasicCustomSeparator = () => { | ||
const { params } = useRoute(); | ||
// @ts-ignore | ||
const { title } = params; | ||
|
||
// styles | ||
const containerStyle = { | ||
paddingVertical: SEPARATOR_SIZE * 2, | ||
backgroundColor: 'white', | ||
}; | ||
|
||
// methods | ||
const handleStickyItemPress = () => Alert.alert('Sticky Item Pressed'); | ||
|
||
// render | ||
const renderItem = ({ index }: ListRenderItemInfo<{}>) => ( | ||
<TouchableOpacity onPress={() => Alert.alert(`Item ${index} Pressed`)}> | ||
<DummyItem | ||
index={index} | ||
borderRadius={BORDER_RADIUS} | ||
width={STORY_WIDTH} | ||
height={STORY_HEIGHT} | ||
backgroundColor={'#dfdfdf'} | ||
/> | ||
</TouchableOpacity> | ||
); | ||
|
||
const renderSeparator = ({ size }: { size: number }) => { | ||
return ( | ||
<View style={{ width: size }}> | ||
<View style={styles.separatorLine} /> | ||
</View> | ||
); | ||
}; | ||
return ( | ||
<SafeAreaView style={styles.root}> | ||
<StatusBar barStyle="dark-content" /> | ||
<Text style={styles.text}>{title}</Text> | ||
<View style={containerStyle}> | ||
<StickyItemFlatList | ||
itemWidth={STORY_WIDTH} | ||
itemHeight={STORY_HEIGHT} | ||
separatorSize={SEPARATOR_SIZE} | ||
borderRadius={BORDER_RADIUS} | ||
stickyItemWidth={36} | ||
stickyItemHeight={36} | ||
stickyItemBackgroundColors={['#F8F8FA', '#2d88ff']} | ||
stickyItemContent={BasicSticky} | ||
onStickyItemPress={handleStickyItemPress} | ||
data={data} | ||
renderItem={renderItem} | ||
ItemSeparatorComponent={renderSeparator} | ||
/> | ||
</View> | ||
</SafeAreaView> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
root: { | ||
flex: 1, | ||
flexDirection: 'column', | ||
justifyContent: 'flex-start', | ||
backgroundColor: '#CACACD', | ||
}, | ||
text: { | ||
marginHorizontal: SEPARATOR_SIZE * 2, | ||
marginBottom: SEPARATOR_SIZE, | ||
fontSize: 43, | ||
fontWeight: Platform.OS === 'ios' ? '900' : 'bold', | ||
textTransform: 'uppercase', | ||
color: '#2d88ff', | ||
}, | ||
buttons: { | ||
marginTop: SEPARATOR_SIZE, | ||
marginHorizontal: SEPARATOR_SIZE * 2, | ||
flexDirection: 'row', | ||
justifyContent: 'space-between', | ||
alignContent: 'space-between', | ||
}, | ||
separatorLine: { | ||
position: 'absolute', | ||
left: '50%', | ||
top: '25%', | ||
height: '50%', | ||
width: 1, | ||
opacity: 0.5, | ||
backgroundColor: '#CACACD', | ||
}, | ||
}); | ||
|
||
export default BasicCustomSeparator; |
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
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,13 @@ | ||
import React, { memo } from 'react'; | ||
import { View } from 'react-native'; | ||
import { SeparatorConfig } from '../../types'; | ||
|
||
interface SeparatorProps extends SeparatorConfig {} | ||
|
||
const SeparatorComponent = ({ size }: SeparatorProps) => { | ||
return <View style={{ width: size }} />; | ||
}; | ||
|
||
const Separator = memo(SeparatorComponent); | ||
|
||
export default Separator; |
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 @@ | ||
export { default } from './Separator'; |
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