react-animated-slider icon indicating copy to clipboard operation
react-animated-slider copied to clipboard

Infinite and AutoPlay does not work with 2 slides

Open Shreerang opened this issue 6 years ago • 1 comments

I see that there is an exact same issue https://github.com/erichbehrens/react-animated-slider/issues/80 but is closed, when it is pretty much reproducible.

Shreerang avatar Feb 20 '19 22:02 Shreerang

A workaround that ended up solving this for me was to check if there are 2 slides, and if yes duplicate them to make it 4. Example - where slide elems are passed as children:

constructor(props) {
    super(props);
    if (React.Children.count(props.children) === 2) {
      // slider breaks if there are exactly 2 items, so we make it 4
      this.children = []
      React.Children.map(props.children, (child, index) => {
        this.children.push(child);
      });
      React.Children.map(props.children, (child, index) => {
        this.children.push(child);
      });
    } else {
      this.children = props.children;
    }
}

z2s8 avatar May 15 '19 12:05 z2s8