meliorence / meliorence/react-native-snap-carousel

Android RTL wrong slide displayed during dynamical adding new slides

Open
#669 1 comment 0 reactions 0 assignees View on GitHub

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 ([]).)

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

ezgif com-video-to-gif
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.