-
-
Notifications
You must be signed in to change notification settings - Fork 338
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to show on the carousel a piece of the previous and next slide? #717
Comments
สวัสดีครับ @Nakinthorn! I'm here to help you with any coding bugs, answer your questions, and assist you in becoming a contributor. Let's tackle this together! If you have any questions, feel free to ask. To display a portion of the previous and next slides on a carousel using import * as React from "react";
import { View, Text } from "react-native";
import { interpolate } from "react-native-reanimated";
import Carousel from "react-native-reanimated-carousel";
import { window } from "@/constants/sizes";
function Index() {
const scale = 0.9;
const RIGHT_OFFSET = window.width * (1 - scale);
const ITEM_WIDTH = window.width * scale;
const ITEM_HEIGHT = 120;
const animationStyle = React.useCallback(
(value: number) => {
"worklet";
const translateY = interpolate(value, [-1, 0, 1], [-ITEM_HEIGHT, 0, ITEM_HEIGHT]);
const right = interpolate(value, [-1, -0.2, 1], [RIGHT_OFFSET / 2, RIGHT_OFFSET, RIGHT_OFFSET / 3]);
return {
transform: [{ translateY }],
right,
};
},
[RIGHT_OFFSET],
);
return (
<View style={{ flex: 1, backgroundColor: "black" }}>
<Carousel
loop
vertical
style={{
justifyContent: "center",
width: window.width,
height: window.height - 100, // Adjust height as needed
}}
width={ITEM_WIDTH}
pagingEnabled={false}
height={ITEM_HEIGHT}
data={[...new Array(10).keys()]}
renderItem={({ index }) => (
<View key={index} style={{ flex: 1, padding: 10 }}>
<View
style={{
alignItems: "flex-start",
flex: 1,
justifyContent: "space-between",
flexDirection: "row",
borderRadius: 20,
}}
>
<Text style={{ color: "white" }}>Slide {index}</Text>
</View>
</View>
)}
customAnimation={animationStyle}
/>
</View>
);
}
export default Index; This example uses the |
I have been using this for a long time, and it works.
|
How to show on the carousel a piece of the next slide?
The text was updated successfully, but these errors were encountered: