-
-
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
can not read property 'Basic' of undefined #613
Comments
The error "cannot read property 'Basic' of undefined" occurs because the Here is the corrected code snippet: import { View, Dimensions } from 'react-native';
import React, { useRef } from 'react';
import Carousel, { Pagination } from 'react-native-reanimated-carousel';
import { campaigns } from '../../constants/campaigns';
import CampaignCard from './CampaignCard';
import { useSharedValue } from 'react-native-reanimated';
const CampaignCarousel = () => {
const width = Dimensions.get('window').width;
const ref = useRef(null);
const progress = useSharedValue(0);
const onPressPagination = index => {
ref.current?.scrollTo({
count: index - progress.value,
animated: true,
});
};
return (
<View>
<Carousel
ref={ref}
width={width}
height={width / 2}
data={campaigns}
onProgressChange={progress}
renderItem={({ item }) => <CampaignCard villa={item} />}
/>
<Pagination.Basic
progress={progress}
data={campaigns}
dotStyle={{ backgroundColor: 'rgba(0,0,0,0.2)', borderRadius: 50 }}
containerStyle={{ gap: 5, marginTop: 10 }}
onPress={onPressPagination}
/>
</View>
);
};
export default CampaignCarousel; Ensure you have the correct import statements: import { View, Dimensions } from 'react-native';
import React, { useRef } from 'react';
import Carousel, { Pagination } from 'react-native-reanimated-carousel';
import { campaigns } from '../../constants/campaigns';
import CampaignCard from './CampaignCard';
import { useSharedValue } from 'react-native-reanimated'; If the issue persists, make sure yarn add react-native-reanimated@~3.3.0 After installing, rebuild your project: yarn start --reset-cache
yarn android # or yarn ios Also, ensure your module.exports = {
presets: ['module:metro-react-native-babel-preset'],
plugins: [
'react-native-reanimated/plugin',
],
}; This should resolve the issue with the
|
Same problem here, trying all the method above, still not working, and i noticed that there are no Pagination exported from react-native-reanimated-carousel index.tsx file |
@dosu still not working |
The issue arises because the Here's an example of how you can create a custom pagination component: import { View, Dimensions, TouchableOpacity, StyleSheet } from 'react-native';
import React, { useRef } from 'react';
import Carousel from 'react-native-reanimated-carousel';
import { campaigns } from '../../constants/campaigns';
import CampaignCard from './CampaignCard';
import { useSharedValue } from 'react-native-reanimated';
const CustomPagination = ({ data, progress, onPress }) => {
return (
<View style={styles.paginationContainer}>
{data.map((_, index) => {
const isActive = Math.round(progress.value) === index;
return (
<TouchableOpacity
key={index}
style={[styles.dot, isActive && styles.activeDot]}
onPress={() => onPress(index)}
/>
);
})}
</View>
);
};
const CampaignCarousel = () => {
const width = Dimensions.get('window').width;
const ref = useRef(null);
const progress = useSharedValue(0);
const onPressPagination = index => {
ref.current?.scrollTo({
count: index - progress.value,
animated: true,
});
};
return (
<View>
<Carousel
ref={ref}
width={width}
height={width / 2}
data={campaigns}
onProgressChange={progress}
renderItem={({ item }) => <CampaignCard villa={item} />}
/>
<CustomPagination
progress={progress}
data={campaigns}
onPress={onPressPagination}
/>
</View>
);
};
const styles = StyleSheet.create({
paginationContainer: {
flexDirection: 'row',
justifyContent: 'center',
marginTop: 10,
},
dot: {
width: 10,
height: 10,
borderRadius: 5,
backgroundColor: 'rgba(0,0,0,0.2)',
marginHorizontal: 5,
},
activeDot: {
backgroundColor: 'black',
},
});
export default CampaignCarousel; This custom pagination component should work as a replacement for the missing @ghost, could you help with this?
|
@sawane8 this works for me import { View, Dimensions, TouchableOpacity, StyleSheet } from 'react-native'; const CustomPagination = ({ data, currentIndex, onPress }) => { const onProgressChange = (_, absoluteProgress) => { const onPressPagination = index => { export default CampaignCarousel; const styles = StyleSheet.create({ |
My friend, Pagination was added on v4.0.0-alpha.11 (https://github.com/dohooo/react-native-reanimated-carousel/releases/tag/v4.0.0-alpha.11) |
Installing latest version of React Native Reanimated Carousel did worked for me. |
import { View, Dimensions } from 'react-native';
import React, { useRef } from 'react';
import Carousel, { Pagination } from 'react-native-reanimated-carousel';
import { campaigns } from '../../constants/campaigns';
import CampaignCard from './CampaignCard';
import { useSharedValue } from 'react-native-reanimated';
const CampaignCarousel = () => {
const width = Dimensions.get('window').width;
const ref = useRef(null);
const progress = useSharedValue(0);
const onPressPagination = index => {
ref.current?.scrollTo({
/**
* Calculate the difference between the current index and the target index
* to ensure that the carousel scrolls to the nearest index
*/
count: index - progress.value,
animated: true,
});
};
return (
<Carousel
ref={ref}
width={width}
height={width / 2}
data={campaigns}
onProgressChange={progress}
// mode="parallax"
// scrollAnimationDuration={1000}
renderItem={({ item }) => }
/>
<Pagination.Basic
progress={progress}
data={campaigns}
dotStyle={{ backgroundColor: 'rgba(0,0,0,0.2)', borderRadius: 50 }}
containerStyle={{ gap: 5, marginTop: 10 }}
onPress={onPressPagination}
/>
);
};
export default CampaignCarousel;
although i am using last version 3.5.1, it gives this error.
The text was updated successfully, but these errors were encountered: