-
-
Notifications
You must be signed in to change notification settings - Fork 332
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
The card in the back shows in front of the front card. #671
Comments
To fix the issue where the card in the back shows in front of the front card when the card length is less than 5 in your Here's an example of how you can modify the import React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import Animated, { useAnimatedStyle } from 'react-native-reanimated';
const CustomCarousel: React.FC<CustomCarouselProps> = ({
visibleCardIndices,
obtainLogs,
learnerId,
academyId,
handleSwipedCarousel,
}) => {
const homeworks = [
{ id: 1, title: 'Homework 1', description: 'Description 1' },
{ id: 2, title: 'Homework 2', description: 'Description 2' },
{ id: 3, title: 'Homework 3', description: 'Description 3' },
// Uncomment these lines to test with more cards
// { id: 4, title: 'Homework 4', description: 'Description 4' },
// { id: 5, title: 'Homework 5', description: 'Description 5' },
];
const screenWidth = Dimensions.get('screen').width;
const currentIndex = useRef(homeworks.length - 1 - +visibleCardIndices[0]);
return (
<Carousel
style={{
width: '100%',
height: 352,
alignItems: 'flex-end',
justifyContent: 'center',
}}
width={screenWidth - 40}
height={320}
windowSize={homeworks.length >= 5 ? 5 : homeworks.length}
pagingEnabled={true}
snapEnabled={false}
mode={'vertical-stack'}
autoFillData={true}
loop={true}
data={homeworks}
modeConfig={{
snapDirection: 'right',
stackInterval: -40,
scaleInterval: 0.1,
opacityInterval: 0.01,
moveSize: screenWidth + 1000,
}}
defaultIndex={currentIndex.current}
customConfig={() => ({ type: 'negative', viewCount: 3 })}
onProgressChange={(offsetProgress: number, absoluteProgress: number) => {
const absIndex = Math.floor(absoluteProgress);
const newIndex = homeworks.length - 1 - absIndex;
console.log('newIndex', newIndex);
if (currentIndex.current !== newIndex) {
currentIndex.current = newIndex;
handleSwipedCarousel(homeworks.length, currentIndex.current);
}
}}
renderItem={({ index, item }) => {
const animatedStyle = useAnimatedStyle(() => {
const zIndex = homeworks.length - index; // Ensure the front card has the highest z-index
return {
zIndex,
};
});
return (
<Animated.View key={index} style={[styles.card, animatedStyle]}>
<Text>{item.title}</Text>
</Animated.View>
);
}}
/>
);
};
const styles = StyleSheet.create({
card: {
position: 'absolute',
width: '100%',
height: '100%',
backgroundColor: '#f2cfcf',
borderWidth: 1,
},
});
export default CustomCarousel; In this example, the |
I had the same issue; scrollAnimationDuration={100} solved the issue |
Describe the bug
[00:00] The card length is 5. It shows well according to the order.
[00:07] The card length is 4. The card in the back shows when it's not its order. it mask the front card.
This occurs when the card's length is less than 5.
To Reproduce
Steps to reproduce the behavior:
this is the code.
Expected behavior
However many length the cards have, I want the card shows according to the order.
Screenshots
If applicable, add screenshots to help explain your problem.
Screen_Recording_20240912_110457_TalkTree.mp4
Versions (please complete the following information):
"react": "18.2.0",
"react-native": "0.73.4",
"react-native-reanimated": "^3.15.1",
"react-native-reanimated-carousel": "4.0.0-canary.13",
"react-native-gesture-handler": "^2.16.2",
Smartphone (please complete the following information):
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: