meliorence / react-native-snap-carousel

Swiper/carousel component for React Native featuring previews, multiple layouts, parallax images, performant handling of huge numbers of items, and more. Compatible with Android & iOS.
BSD 3-Clause "New" or "Revised" License
10.37k stars 2.29k forks source link

activeSlideAlignment not updated immediately ? #869

Open SolidTears opened 3 years ago

SolidTears commented 3 years ago

Is this a bug report, a feature request, or a question?

question

so, i have a case where i need to dynamically change activeSlideAlignment for the carousel, while it work, but the carousel didn't actively recognized the changed activeSlideAlignment on the fly, it need to finish the previous activeSlideAlignment first, then move immediately to the changed activeSlideAlignment, for example, it goes to "start" first, then immediately blink to the changed activeSlideAlignment "end"

the transition feels jaring and jerky, is this intended behaviour, or is there something i need to do to make it smooth ?, for context, i change the activeSlideAlignment based on index, thus i also use onBeforeSnapToItem to check the index, setState, then check the state index, then change the activeSlideAlignment on props

code example

<Carousel ref={(c) => { this._carousel = c; }} data={this.props.data} renderItem={this.smallCardView} sliderWidth={sliderWidth } itemWidth={itemWidth} enableSnap={true} inactiveSlideOpacity={1} inactiveSlideScale={0.95} onBeforeSnapToItem={(index) => this.setState({ index: index })} activeSlideAlignment={this.props.data.length > 1 ? (this.state.index=== 1 ? 'center' : 'start') : 'center'} />

dohooo commented 3 years ago

@Solid-Metal Sorry, please allow me to advertise for my open source library! ~ I think this library react-native-reanimated-carousel will solve your problem. It is a high performance and very simple component, complete with React-Native reanimated 2