-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:: Add pagination component to onboarding screen
- Loading branch information
1 parent
d66ca73
commit e258073
Showing
5 changed files
with
104 additions
and
1 deletion.
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
30 changes: 30 additions & 0 deletions
30
examples/common_expo/components/Onboarding/Pagination/Pagination.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,30 @@ | ||
import { FC } from 'react'; | ||
import { StyleSheet, View } from 'react-native'; | ||
import { SharedValue } from 'react-native-reanimated'; | ||
|
||
import { PaginationItem } from './PaginationItem'; | ||
|
||
type PaginationProps = { | ||
length: number; | ||
offsetX: SharedValue<number>; | ||
}; | ||
|
||
export const Pagination: FC<PaginationProps> = ({ length, offsetX }) => ( | ||
<View style={styles.container}> | ||
{[...Array(length).keys()].map((_, index) => ( | ||
<PaginationItem | ||
key={index.toString()} | ||
itemIndex={index} | ||
offsetX={offsetX} | ||
/> | ||
))} | ||
</View> | ||
); | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
alignItems: 'center', | ||
flexDirection: 'row', | ||
justifyContent: 'center', | ||
}, | ||
}); |
60 changes: 60 additions & 0 deletions
60
examples/common_expo/components/Onboarding/Pagination/PaginationItem.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,60 @@ | ||
import { FC } from 'react'; | ||
import { StyleSheet, useWindowDimensions } from 'react-native'; | ||
import Animated, { | ||
Extrapolation, | ||
interpolate, | ||
interpolateColor, | ||
SharedValue, | ||
useAnimatedStyle, | ||
} from 'react-native-reanimated'; | ||
|
||
type PaginationItemProps = { | ||
itemIndex: number; | ||
offsetX: SharedValue<number>; | ||
}; | ||
|
||
export const PaginationItem: FC<PaginationItemProps> = ({ | ||
itemIndex, | ||
offsetX, | ||
}) => { | ||
const { width: SCREEN_WIDTH } = useWindowDimensions(); | ||
|
||
const animatedItemStyle = useAnimatedStyle(() => { | ||
const backgroundColor = interpolateColor( | ||
offsetX.value, | ||
[ | ||
(itemIndex - 1) * SCREEN_WIDTH, | ||
itemIndex * SCREEN_WIDTH, | ||
(itemIndex + 1) * SCREEN_WIDTH, | ||
], | ||
['#e2e2e2', 'blue', '#e2e2e2'], | ||
); | ||
|
||
const width = interpolate( | ||
offsetX.value, | ||
[ | ||
(itemIndex - 1) * SCREEN_WIDTH, | ||
itemIndex * SCREEN_WIDTH, | ||
(itemIndex + 1) * SCREEN_WIDTH, | ||
], | ||
[32, 16, 32], | ||
Extrapolation.CLAMP, | ||
); | ||
|
||
return { | ||
width, | ||
backgroundColor, | ||
}; | ||
}); | ||
|
||
return <Animated.View style={[styles.item, animatedItemStyle]} />; | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
item: { | ||
borderRadius: 5, | ||
height: 10, | ||
marginHorizontal: 4, | ||
width: 32, | ||
}, | ||
}); |
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 * from './Pagination'; |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './NextButton'; | ||
export * from './OnboardingListItem'; | ||
export * from './OnboardingWrapper'; | ||
export * from './Pagination'; |