Skip to content

Commit 35d39c3

Browse files
committed
fix: update docs
1 parent 353fdce commit 35d39c3

File tree

6 files changed

+229
-11
lines changed

6 files changed

+229
-11
lines changed

example/app/src/pages/tinder/index.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ import Animated, {
99
import Carousel from "react-native-reanimated-carousel";
1010

1111
import { window } from "../../constants";
12-
import { TAnimationStyle } from "../../../../../src/layouts/BaseLayout";
1312
import { getImages } from "../../utils/get-images";
13+
import { TAnimationStyle } from "../../../../../src/components/BaseLayout";
1414

1515
const data = getImages()
1616

@@ -46,8 +46,9 @@ function Index() {
4646

4747
const zIndex = interpolate(
4848
value,
49-
[-1, 0],
50-
[100, 0]
49+
[0, 1, 2, 3, 4],
50+
[0, 1, 2, 3, 4].map((v) => (data.length - v) * 10),
51+
Extrapolate.CLAMP
5152
)
5253

5354
const scale = interpolate(
9.83 MB
Loading

example/website/pages/Examples/normal.mdx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,14 @@ import { SafeAreaView } from "react-native-safe-area-context";
4949
import { SBItem } from "../../components/SBItem";
5050
import SButton from "../../components/SButton";
5151
import { ElementsText, window } from "../../constants";
52+
import { useWindowDimensions } from "react-native";
53+
import { useSharedValue } from "react-native-reanimated";
5254

5355
const PAGE_WIDTH = window.width;
5456

5557
function Index() {
58+
const windowWidth = useWindowDimensions().width;
59+
5660
const [data, setData] = React.useState([...new Array(4).keys()]);
5761
const [isVertical, setIsVertical] = React.useState(false);
5862
const [isFast, setIsFast] = React.useState(false);
@@ -63,26 +67,31 @@ function Index() {
6367
const baseOptions = isVertical
6468
? ({
6569
vertical: true,
66-
width: PAGE_WIDTH,
70+
width: windowWidth,
6771
height: PAGE_WIDTH / 2,
6872
} as const)
6973
: ({
7074
vertical: false,
71-
width: PAGE_WIDTH,
75+
width: windowWidth,
7276
height: PAGE_WIDTH / 2,
7377
} as const);
7478

79+
const a = useSharedValue<number>(0);
80+
7581
return (
7682
<SafeAreaView edges={["bottom"]} style={{ flex: 1 }}>
7783
<Carousel
7884
{...baseOptions}
7985
loop
86+
enabled // Default is true, just for demo
8087
ref={ref}
88+
defaultScrollOffsetValue={a}
8189
testID={"xxx"}
8290
style={{ width: "100%" }}
8391
autoPlay={isAutoPlay}
8492
autoPlayInterval={isFast ? 100 : 2000}
8593
data={data}
94+
onConfigurePanGesture={g => g.enabled(false)}
8695
pagingEnabled={isPagingEnabled}
8796
onSnapToItem={index => console.log("current index:", index)}
8897
renderItem={({ index }) => <SBItem key={index} index={index} />}
@@ -121,7 +130,7 @@ function Index() {
121130
setIsPagingEnabled(!isPagingEnabled);
122131
}}
123132
>
124-
PagingEnabled:{isPagingEnabled.toString()}
133+
PagingEnabled:{isPagingEnabled.toString()}
125134
</SButton>
126135
<SButton
127136
onPress={() => {
@@ -135,7 +144,7 @@ function Index() {
135144
console.log(ref.current?.getCurrentIndex());
136145
}}
137146
>
138-
Log current index
147+
Log current index
139148
</SButton>
140149
<SButton
141150
onPress={() => {
@@ -146,21 +155,21 @@ function Index() {
146155
);
147156
}}
148157
>
149-
Change data length to:{data.length === 6 ? 8 : 6}
158+
Change data length to:{data.length === 6 ? 8 : 6}
150159
</SButton>
151160
<SButton
152161
onPress={() => {
153162
ref.current?.scrollTo({ count: -1, animated: true });
154163
}}
155164
>
156-
prev
165+
prev
157166
</SButton>
158167
<SButton
159168
onPress={() => {
160169
ref.current?.scrollTo({ count: 1, animated: true });
161170
}}
162171
>
163-
next
172+
next
164173
</SButton>
165174
</ScrollView>
166175
</SafeAreaView>

example/website/pages/Examples/parallax.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ function Index() {
9191
<Carousel
9292
{...baseOptions}
9393
style={{
94-
width: PAGE_WIDTH * 0.86,
94+
width: PAGE_WIDTH,
9595
}}
9696
loop
9797
pagingEnabled={pagingEnabled}

example/website/pages/Examples/summary.mdx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,4 +312,16 @@ import { Cards } from 'nextra/components'
312312
<div style={{ maxHeight: 200 }}>![tear](../../../app/src/pages/tear/preview.gif)</div>
313313
</Cards.Card>
314314

315+
316+
<Cards.Card
317+
image
318+
arrow
319+
title="tinder"
320+
id="summary-item"
321+
href="/Examples/tinder"
322+
style={{ maxHeight: 240 }}
323+
>
324+
<div style={{ maxHeight: 200 }}>![tinder](../../../app/src/pages/tinder/preview.gif)</div>
325+
</Cards.Card>
326+
315327
</Cards>
Lines changed: 196 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,196 @@
1+
---
2+
id: tinder
3+
title: Tinder
4+
sidebar_label: Tinder
5+
description: Tinder animation
6+
keywords:
7+
- tinder
8+
- carousel animation
9+
- carousel animation tinder
10+
- react-native-reanimated-carousel
11+
- reanimated-carousel
12+
- reanimated carousel
13+
- react-native
14+
- snap-carousel
15+
- react native
16+
- snap carousel
17+
- ios
18+
- android
19+
- carousel
20+
- snap
21+
- reanimated
22+
image:
23+
slug: /examples/tinder
24+
---
25+
26+
{/*
27+
28+
=========================================================================
29+
=========================================================================
30+
This page generated by /scripts/gen-pages.mjs, Don't update it manually
31+
=========================================================================
32+
=========================================================================
33+
34+
*/}
35+
36+
Here is a `tinder` animation example. You can see the source code of this page [here](https://github.com/dohooo/react-native-reanimated-carousel/blob/main/example/app/src/pages/tinder/index.tsx).
37+
38+
import Page from '../../components/Page'
39+
40+
<Page page='tinder' />
41+
42+
```tsx copy
43+
import * as React from "react";
44+
import { Image, ImageSourcePropType, View } from "react-native";
45+
import Animated, {
46+
Extrapolate,
47+
FadeInDown,
48+
interpolate,
49+
useSharedValue,
50+
} from "react-native-reanimated";
51+
import Carousel from "react-native-reanimated-carousel";
52+
53+
import { window } from "../../constants";
54+
import { TAnimationStyle } from "../../../../../src/layouts/BaseLayout";
55+
import { getImages } from "../../utils/get-images";
56+
57+
const data = getImages()
58+
59+
function Index() {
60+
const headerHeight = 100;
61+
const PAGE_WIDTH = window.width;
62+
const PAGE_HEIGHT = window.height - headerHeight;
63+
64+
const directionAnimVal = useSharedValue(0);
65+
66+
const animationStyle: TAnimationStyle = React.useCallback(
67+
(value: number) => {
68+
"worklet";
69+
const translateY = interpolate(
70+
value,
71+
[0, 1],
72+
[0, -18],
73+
);
74+
75+
const translateX = interpolate(
76+
value,
77+
[-1, 0],
78+
[PAGE_WIDTH, 0],
79+
Extrapolate.CLAMP
80+
) * directionAnimVal.value;
81+
82+
const rotateZ = interpolate(
83+
value,
84+
[-1, 0],
85+
[15, 0],
86+
Extrapolate.CLAMP
87+
) * directionAnimVal.value;
88+
89+
const zIndex = interpolate(
90+
value,
91+
[-1, 0],
92+
[100, 0]
93+
)
94+
95+
const scale = interpolate(
96+
value,
97+
[0, 1],
98+
[1, 0.95]
99+
);
100+
101+
const opacity = interpolate(
102+
value,
103+
[-1, -0.8, 0, 1],
104+
[0, 0.9, 1, 0.85],
105+
Extrapolate.EXTEND
106+
);
107+
108+
return {
109+
transform: [
110+
{ translateY },
111+
{ translateX },
112+
{ rotateZ: `${rotateZ}deg` },
113+
{ scale },
114+
],
115+
zIndex,
116+
opacity,
117+
};
118+
},
119+
[PAGE_HEIGHT, PAGE_WIDTH],
120+
);
121+
122+
return (
123+
<View style={{ flex: 1 }}>
124+
<Carousel
125+
loop={false}
126+
style={{
127+
width: PAGE_WIDTH,
128+
height: PAGE_HEIGHT,
129+
justifyContent: "center",
130+
alignItems: "center",
131+
backgroundColor: "white",
132+
}}
133+
defaultIndex={0}
134+
vertical={false}
135+
width={PAGE_WIDTH}
136+
height={PAGE_HEIGHT}
137+
data={data}
138+
onConfigurePanGesture={g => {
139+
g.onChange(e => {
140+
directionAnimVal.value = Math.sign(e.translationX)
141+
})
142+
}}
143+
fixedDirection="negative"
144+
renderItem={({ index, item }) => (
145+
<Item
146+
key={index}
147+
img={item}
148+
/>
149+
)}
150+
customAnimation={animationStyle}
151+
windowSize={5}
152+
/>
153+
</View>
154+
);
155+
}
156+
157+
const Item: React.FC<{ img: ImageSourcePropType }> = ({ img }) => {
158+
const width = window.width * 0.7;
159+
const height = window.height * 0.5;
160+
161+
return (
162+
<Animated.View entering={FadeInDown.duration(300)} style={{ flex: 1, alignItems: "center", justifyContent: "center" }}>
163+
<View
164+
style={{
165+
width,
166+
height,
167+
borderWidth: 1,
168+
borderColor: "black",
169+
borderRadius: 20,
170+
justifyContent: "center",
171+
alignItems: "center",
172+
backgroundColor: "white",
173+
174+
shadowColor: "#000000d1",
175+
shadowOffset: {
176+
width: 0,
177+
height: 10,
178+
},
179+
shadowOpacity: 0.51,
180+
shadowRadius: 13.16,
181+
elevation: 20,
182+
}}
183+
>
184+
<Image source={img} style={{
185+
width,
186+
height,
187+
borderRadius: 20,
188+
}} />
189+
</View>
190+
</Animated.View>
191+
);
192+
};
193+
194+
export default Index;
195+
196+
```

0 commit comments

Comments
 (0)