meliorence / meliorence/react-native-snap-carousel
Android RTL wrong slide displayed during dynamical adding new slides
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10.5k
- Forks
- 2.3k
- PR merge metrics
- No merged PRs in 30d
Description
Is this a bug report, a feature request, or a question?
Bug report
Have you followed the required steps before opening a bug report?
(Check the step you've followed - put an x character between the square brackets ([]).)
- I have read the guidelines regarding bug report.
- I have reviewed the documentation in its entirety, including the dedicated documentations 📚.
- I have searched for existing issues and made sure that the problem hasn't already been reported.
- I am using the latest plugin version.
- I am following the issue template closely in order to produce a useful bug report.
Have you made sure that it wasn't a React Native bug?
Yes
Is the bug specific to iOS or Android? Or can it be reproduced on both platforms?
Android 9.0
Is the bug reproducible

in a production environment (not a debug one)?
Both
Environment
Environment:
React: 16.8.6
React native: 0.60.5
react-native-snap-carousel: 3.8.4
Target Platform:
Android (9.0)
Expected Behavior
The initial slide should be displayed when dynamically adding new slides to carousel.
Actual Behavior
On Android RTL the carousel is scrolling to the end and the last slide is displayed
Reproducible Demo
The isssue is not reproducible on snack, but occurs on empty project.
Steps to Reproduce
import React from 'react';
import { View, Text } from 'react-native';
import Carousel, { getInputRangeFromIndexes } from 'react-native-snap-carousel';
import { isAndroidRtl } from '../../../core/utils';
export class TestCarousel extends React.Component {
constructor(props) {
super(props);
this.state = {
data: ['first']
};
}
componentDidMount() {
setTimeout(() => {
this.setState({
data: ['first', 'second']
});
}, 3000);
setTimeout(() => {
this.setState({
data: ['first', 'second', 'third']
});
}, 5000);
}
scrollInterpolator = (index, carouselProps) => {
const range = [1, 0, -1];
const inputRange = getInputRangeFromIndexes(range, index, carouselProps);
return {
inputRange,
outputRange: range
};
};
animatedStyles = (index, animatedValue) => ({
transform: [{
scaleY: animatedValue.interpolate({
inputRange: [-1, 0, 1],
outputRange: [0.92, 1, 0.92]
})
},
]
});
renderItem = ({ item }) => (
<View style={{ margin: 10, padding: 10, width: 250, height: 50, justifyContent: 'center' }}>
<Text>
{item}
</Text>
</View>
);
render() {
const { data } = this.state;
const itemsToRenderProp = {};
itemsToRenderProp.initialNumToRender = data.length;
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Carousel
{...this.props}
{...itemsToRenderProp}
renderItem={this.renderItem}
scrollInterpolator={this.scrollInterpolator}
slideInterpolatedStyle={this.animatedStyles}
shouldOptimizeUpdates={false}
sliderWidth={400}
horizontal={true}
itemWidth={300}
useScrollView={false}
data={data}/>
</View>
);
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the supplied TestCarousel case in an Android RTL empty project, then inspect the carousel's RTL handling, including the core/utils isAndroidRtl entry point. The fix is done when dynamically adding slides keeps the initial slide displayed instead of scrolling to the last slide, with the behavior verified in production mode.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, react-native
- Domain
- internationalization, mobile
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100