-
-
Notifications
You must be signed in to change notification settings - Fork 329
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
33 changed files
with
1,149 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'react-native-reanimated-carousel': minor | ||
--- | ||
|
||
Support to fix the scroll direction through new API, fixedDirection. |
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,6 +1,9 @@ | ||
{ | ||
"extends": "@dohooo", | ||
"rules": { | ||
"@typescript-eslint/no-use-before-define": "off", | ||
} | ||
"@typescript-eslint/no-use-before-define": "off" | ||
}, | ||
"plugins": [ | ||
"jest" | ||
] | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
import * as React from "react"; | ||
import { Image, ImageSourcePropType, View } from "react-native"; | ||
import Animated, { | ||
Extrapolate, | ||
FadeInDown, | ||
interpolate, | ||
useSharedValue, | ||
} from "react-native-reanimated"; | ||
import Carousel from "react-native-reanimated-carousel"; | ||
|
||
import { window } from "../../constants"; | ||
import { TAnimationStyle } from "../../../../../src/layouts/BaseLayout"; | ||
import { getImages } from "../../utils/get-images"; | ||
|
||
const data = getImages() | ||
|
||
function Index() { | ||
const headerHeight = 100; | ||
const PAGE_WIDTH = window.width; | ||
const PAGE_HEIGHT = window.height - headerHeight; | ||
|
||
const directionAnimVal = useSharedValue(0); | ||
|
||
const animationStyle: TAnimationStyle = React.useCallback( | ||
(value: number) => { | ||
"worklet"; | ||
const translateY = interpolate( | ||
value, | ||
[0, 1], | ||
[0, -18], | ||
); | ||
|
||
const translateX = interpolate( | ||
value, | ||
[-1, 0], | ||
[PAGE_WIDTH, 0], | ||
Extrapolate.CLAMP | ||
) * directionAnimVal.value; | ||
|
||
const rotateZ = interpolate( | ||
value, | ||
[-1, 0], | ||
[15, 0], | ||
Extrapolate.CLAMP | ||
) * directionAnimVal.value; | ||
|
||
const zIndex = interpolate( | ||
value, | ||
[-1, 0], | ||
[100, 0] | ||
) | ||
|
||
const scale = interpolate( | ||
value, | ||
[0, 1], | ||
[1, 0.95] | ||
); | ||
|
||
const opacity = interpolate( | ||
value, | ||
[-1, -0.8, 0, 1], | ||
[0, 0.9, 1, 0.85], | ||
Extrapolate.EXTEND | ||
); | ||
|
||
return { | ||
transform: [ | ||
{ translateY }, | ||
{ translateX }, | ||
{ rotateZ: `${rotateZ}deg` }, | ||
{ scale }, | ||
], | ||
zIndex, | ||
opacity, | ||
}; | ||
}, | ||
[PAGE_HEIGHT, PAGE_WIDTH], | ||
); | ||
|
||
return ( | ||
<View style={{ flex: 1 }}> | ||
<Carousel | ||
loop={false} | ||
style={{ | ||
width: PAGE_WIDTH, | ||
height: PAGE_HEIGHT, | ||
justifyContent: "center", | ||
alignItems: "center", | ||
backgroundColor: "white", | ||
}} | ||
defaultIndex={0} | ||
vertical={false} | ||
width={PAGE_WIDTH} | ||
height={PAGE_HEIGHT} | ||
data={data} | ||
onConfigurePanGesture={g => { | ||
g.onChange(e => { | ||
directionAnimVal.value = Math.sign(e.translationX) | ||
}) | ||
}} | ||
fixedDirection="negative" | ||
renderItem={({ index, item }) => ( | ||
<Item | ||
key={index} | ||
img={item} | ||
/> | ||
)} | ||
customAnimation={animationStyle} | ||
windowSize={5} | ||
/> | ||
</View> | ||
); | ||
} | ||
|
||
const Item: React.FC<{ img: ImageSourcePropType }> = ({ img }) => { | ||
const width = window.width * 0.7; | ||
const height = window.height * 0.5; | ||
|
||
return ( | ||
<Animated.View entering={FadeInDown.duration(300)} style={{ flex: 1, alignItems: "center", justifyContent: "center" }}> | ||
<View | ||
style={{ | ||
width, | ||
height, | ||
borderWidth: 1, | ||
borderColor: "black", | ||
borderRadius: 20, | ||
justifyContent: "center", | ||
alignItems: "center", | ||
backgroundColor: "white", | ||
|
||
shadowColor: "#000000d1", | ||
shadowOffset: { | ||
width: 0, | ||
height: 10, | ||
}, | ||
shadowOpacity: 0.51, | ||
shadowRadius: 13.16, | ||
elevation: 20, | ||
}} | ||
> | ||
<Image source={img} style={{ | ||
width, | ||
height, | ||
borderRadius: 20, | ||
}} /> | ||
</View> | ||
</Animated.View> | ||
); | ||
}; | ||
|
||
export default Index; |
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,2 +1,6 @@ | ||
declare module "react-native-safe-area-context"; | ||
|
||
declare module "*.jpg" { | ||
const value: any; | ||
export default value; | ||
} |
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,24 @@ | ||
import { ImageSourcePropType } from "react-native" | ||
|
||
const img_0 = require('../../assets/bg-images/0.jpg') | ||
const img_1 = require('../../assets/bg-images/1.jpg') | ||
const img_2 = require('../../assets/bg-images/2.jpg') | ||
const img_3 = require('../../assets/bg-images/3.jpg') | ||
const img_4 = require('../../assets/bg-images/4.jpg') | ||
const img_5 = require('../../assets/bg-images/5.jpg') | ||
const img_6 = require('../../assets/bg-images/6.jpg') | ||
const img_7 = require('../../assets/bg-images/7.jpg') | ||
const img_8 = require('../../assets/bg-images/8.jpg') | ||
const img_9 = require('../../assets/bg-images/9.jpg') | ||
|
||
export function getImages(length: number = 10): ImageSourcePropType[] { | ||
if (length > 10) { | ||
length = 10 | ||
} | ||
|
||
if (length < 1) { | ||
length = 1 | ||
} | ||
|
||
return [img_0, img_1, img_2, img_3, img_4, img_5, img_6, img_7, img_8, img_9].slice(0, length - 1) | ||
} |
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
Oops, something went wrong.