-
-
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.
- Loading branch information
Showing
13 changed files
with
256 additions
and
20 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
8 changes: 8 additions & 0 deletions
8
example/ios/StickyItemExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist
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,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> | ||
<plist version="1.0"> | ||
<dict> | ||
<key>IDEDidComputeMac32BitWarning</key> | ||
<true/> | ||
</dict> | ||
</plist> |
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,77 @@ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
import React from 'react'; | ||
import Animated, { interpolate, Extrapolate } from 'react-native-reanimated'; | ||
import { transformOrigin } from 'react-native-redash'; | ||
import type { StickyItemContentProps } from '@gorhom/sticky-item'; | ||
import { styles } from './styles'; | ||
|
||
const BasicSticky = ({ | ||
x, | ||
threshold, | ||
itemWidth, | ||
itemHeight, | ||
stickyItemWidth, | ||
stickyItemHeight, | ||
separatorSize, | ||
borderRadius, | ||
}: StickyItemContentProps) => { | ||
const stickyScaleX = stickyItemWidth / itemWidth; | ||
const stickyScaleY = stickyItemHeight / itemHeight; | ||
const scaledSpaceX = (separatorSize * 2) / itemWidth; | ||
const scaledSpaceY = (separatorSize * 2) / itemHeight; | ||
const containerScaleX = stickyScaleX + scaledSpaceX; | ||
|
||
//#region plus | ||
const animatedPlusScale = interpolate(x, { | ||
inputRange: [0, threshold * 0.6], | ||
outputRange: [0, 1], | ||
extrapolate: Extrapolate.CLAMP, | ||
}); | ||
const plusStyle = [ | ||
styles.plus, | ||
{ | ||
width: stickyItemWidth, | ||
lineHeight: stickyItemHeight, | ||
paddingHorizontal: separatorSize, | ||
transform: transformOrigin( | ||
{ x: 0, y: 0 }, | ||
{ | ||
translateX: -separatorSize, | ||
translateY: itemHeight / 2 - stickyItemHeight / 2, | ||
scale: animatedPlusScale, | ||
} | ||
) as Animated.AnimatedTransform, | ||
}, | ||
]; | ||
//#endregion | ||
|
||
//#region text | ||
const animatedTextOpacity = interpolate(x, { | ||
inputRange: [0, threshold * 0.6], | ||
outputRange: [1, 0], | ||
extrapolate: Extrapolate.CLAMP, | ||
}); | ||
const textStyle = [ | ||
styles.text, | ||
{ | ||
opacity: animatedTextOpacity, | ||
paddingHorizontal: separatorSize, | ||
lineHeight: itemHeight, | ||
transform: [ | ||
{ | ||
translateY: 0, | ||
}, | ||
] as Animated.AnimatedTransform, | ||
}, | ||
]; | ||
//#endregion | ||
|
||
return ( | ||
<> | ||
<Animated.Text style={plusStyle}>+</Animated.Text> | ||
<Animated.Text style={textStyle}>Add</Animated.Text> | ||
</> | ||
); | ||
}; | ||
|
||
export default BasicSticky; |
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 './BasicSticky'; |
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,22 @@ | ||
import { StyleSheet } from 'react-native'; | ||
|
||
export const styles = StyleSheet.create({ | ||
plus: { | ||
position: 'absolute', | ||
textTransform: 'uppercase', | ||
textAlign: 'center', | ||
fontSize: 34, | ||
fontWeight: '500', | ||
color: 'white', | ||
}, | ||
text: { | ||
position: 'absolute', | ||
width: '100%', | ||
height: '100%', | ||
textTransform: 'uppercase', | ||
textAlign: 'center', | ||
fontSize: 24, | ||
fontWeight: '900', | ||
color: 'black', | ||
}, | ||
}); |
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,87 @@ | ||
import React from 'react'; | ||
import { | ||
StyleSheet, | ||
View, | ||
SafeAreaView, | ||
StatusBar, | ||
Text, | ||
Alert, | ||
} from 'react-native'; | ||
import StickyItemFlatList from '@gorhom/sticky-item'; | ||
import DummyItem from '../components/dummy-item'; | ||
import BasicSticky from '../components/basic-sticky'; | ||
import { useRoute } from '@react-navigation/native'; | ||
|
||
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 Basic = () => { | ||
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 = () => ( | ||
<DummyItem | ||
borderRadius={BORDER_RADIUS} | ||
width={STORY_WIDTH} | ||
height={STORY_HEIGHT} | ||
backgroundColor={'#dfdfdf'} | ||
/> | ||
); | ||
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} | ||
/> | ||
</View> | ||
</SafeAreaView> | ||
); | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
root: { | ||
flex: 1, | ||
flexDirection: 'column', | ||
justifyContent: 'center', | ||
backgroundColor: '#CACACD', | ||
}, | ||
text: { | ||
marginHorizontal: SEPARATOR_SIZE * 2, | ||
marginBottom: SEPARATOR_SIZE, | ||
fontSize: 43, | ||
fontWeight: '900', | ||
textTransform: 'uppercase', | ||
color: '#2d88ff', | ||
}, | ||
}); | ||
|
||
export default Basic; |
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
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