Skip to content

Commit

Permalink
fix ref.measureLayout must be called with a ref to a native component
Browse files Browse the repository at this point in the history
  • Loading branch information
HarshaR1642 committed Sep 13, 2024
1 parent 4a10d39 commit e2acb05
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-snap-carousel",
"version": "4.0.0",
"version": "4.1.0",
"description": "Swiper/carousel component for React Native with previews, multiple layouts, parallax images, performant handling of huge numbers of items, and RTL support. Compatible with Android & iOS.",
"main": "src/index.js",
"repository": {
Expand Down
29 changes: 20 additions & 9 deletions src/carousel/Carousel.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, { Component } from 'react';
import { Animated, Easing, FlatList, I18nManager, Platform, ScrollView, View } from 'react-native';
import { Animated, Easing, FlatList, I18nManager, Platform, ScrollView, StyleSheet, View } from 'react-native';
import PropTypes from 'prop-types';
import shallowCompare from 'react-addons-shallow-compare';
import {
Expand All @@ -12,6 +12,12 @@ import {
tinderScrollInterpolator
} from '../utils/animations';

const styles = StyleSheet.create({
container: {
flex: 1
}
})

const IS_IOS = Platform.OS === 'ios',

/*
Expand Down Expand Up @@ -1257,7 +1263,7 @@ export default class Carousel extends Component {

parallaxProps = hasParallaxImages ? {
scrollPosition: this._scrollPos,
carouselRef: this._carouselRef,
carouselRef: this._parentRef,
vertical,
sliderWidth,
sliderHeight,
Expand Down Expand Up @@ -1400,14 +1406,19 @@ export default class Carousel extends Component {

ScrollViewComponent = typeof useScrollView === 'function' ? useScrollView : AnimatedScrollView;

return this._needsScrollView() ? (
<ScrollViewComponent {...props}>
return (
<View style = {styles.container} ref = {(c) => this._parentRef = c}>
{
this._getCustomData().map((item, index) => this._renderItem({ item, index }))
this._needsScrollView() ? (
<ScrollViewComponent {...props}>
{
this._getCustomData().map((item, index) => this._renderItem({ item, index }))
}
</ScrollViewComponent>
) :
< AnimatedFlatList {...props} />
}
</ScrollViewComponent>
) : (
<AnimatedFlatList {...props} />
);
</View>
)
}
}

0 comments on commit e2acb05

Please sign in to comment.