react-native-reanimated-carousel icon indicating copy to clipboard operation
react-native-reanimated-carousel copied to clipboard

Ability to pause or stop animation

Open i8ramin opened this issue 3 years ago • 2 comments

Is your feature request related to a problem? Please describe. I am using the carousel to auto play and loop through items when the carousel is "in view". I would like to stop or pause the animation when the carousel leaves the viewport, but I cannot find a way to do this using the current methods available on the carousel ref.

Describe the solution you'd like It would be great if there was a stopAnimation() or equivalent available on the carousel ref.

Describe alternatives you've considered I've tried changing the value of autoPlay from true to false, but that does not seem to do the trick

Additional context My component looks like this:

<Carousel
  loop={hasEnoughItems}
  autoPlay={isInView && hasEnoughItems}
  snapEnabled={false}
  pagingEnabled={false}
  enabled={false}
  withAnimation={{
    type: 'timing',
    config: {
      duration: 25000,
      easing: Easing.linear,
    },
  }}
  autoPlayInterval={0}
  windowSize={Dimensions.get('window').width}
  width={142}
  height={175}
  style={{
    width: Dimensions.get('window').width,
  }}
  data={collection?.collection_items || []}
  renderItem={({ item: ci }) => (
    <DiscoveryCollectionCardImage item={ci.cart_item?.item} />
  )}
/>

i8ramin avatar Jul 09 '22 14:07 i8ramin

I've tried changing the value of autoPlay from true to false, but that does not seem to do the trick

Emm, If it doesn't work, maybe it's a bug. I'll check it.

dohooo avatar Jul 09 '22 16:07 dohooo

I've tried changing the value of autoPlay from true to false, but that does not seem to do the trick

Hi, I have a minimal example, But it seems to work normally. I noticed you have hasEnoughItems, Can you log it?

// it's work
function App() {
  const [isAutoPlay, setIsAutoPlay] = useState(true);
    return (
        <View style={styles.container}>
          <Button title="auto play" onPress={() => {
            setIsAutoPlay(!isAutoPlay)
          }} />
            <Carousel
                autoPlay={isAutoPlay}
                width={300}
                height={150}
                style={styles.c}
                data={[1, 2, 3]}
                renderItem={({ item }) => <Text style={styles.t}>{item}</Text>}
            />
        </View>
    );
}

imyuanx avatar Jul 13 '22 11:07 imyuanx

I have tried that and it works normally. Maybe your state hasEnoughItems is wrong?

dohooo avatar Aug 12 '22 03:08 dohooo

I'll reopen this issue If you have any other questions.

dohooo avatar Aug 18 '22 06:08 dohooo