Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

useState in onSnapToItem breaks item display #559

Open
5 tasks done
nikitawolfik opened this issue Jul 31, 2019 · 4 comments
Open
5 tasks done

useState in onSnapToItem breaks item display #559

nikitawolfik opened this issue Jul 31, 2019 · 4 comments

Comments

@nikitawolfik
Copy link

nikitawolfik commented Jul 31, 2019

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, it is an explicit react-native-snap-carousel bug

Is the bug specific to iOS or Android? Or can it be reproduced on both platforms?

It is reproducible in Snack on iOS, iOS 12.2

Is the bug reproductible in a production environment (not a debug one)?

Yes

Environment

Environment:
React: 16.8.3
React native: 0.59.2
react-native-snap-carousel: 3.8.0

Target Platform:
iOS (12.2)

Expected Behavior

While snapping between items, the active item would appear bigger.

Actual Behavior

While using

onScroll={Animated.event([{
            nativeEvent: { contentOffset: { x: scrollValue.current } },
          }])}

with Animated in order to interpolate colors for custom indicator
and also onSnapToItem with hooks calls inside, the snapped item where hooks were called become permanently inactive in terms of bigger display.

Removing onScroll or hooks from onSnapToItem fixes the issue, but I need both methods.
snapbug

Reproducible Demo

This snack

(Paste the link to a Snack example in which the issue can be reproduced. Please follow the guidelines for providing a Minimal, Complete, and Verifiable example.)

Steps to Reproduce

(Write your steps so that anyone can reproduce the issue in the Snack demo you provided.)

  1. Open the Snack
  2. Swipe right, the back
  3. Done< the bug is here
@skoob13
Copy link

skoob13 commented Aug 1, 2019

I have the same issue with two items. When the first item is swiped by me, the interpolator won't work on any other swipe actions. I have downgraded a version to 3.7.5 and it works perfectly after that.

@omid-ebrahimi
Copy link

omid-ebrahimi commented Sep 22, 2019

Same issue for me on Android 6

@ghost
Copy link

ghost commented Oct 22, 2019

I confirm that using am useState hook inside onSnapToItem cause bug on carousel .

  const [carouselIndex, setIndex] = React.useState(initialIndex);

  const handleIndexChange = (index: number) => {
    setIndex(index);
  };

<Carousel
        data={productList}
        ref={refCarousel}
        style={fillContainer}
        sliderWidth={width}
        itemWidth={width}
        firstItem={initialIndex}
        onBeforeSnapToItem={handleIndexChange}
        keyboardShouldPersistTaps="always"
        renderItem={({ item, index }) => {
          return (
            <InventoryProductSheet
              key={item.id}
              productId={item.id}
              index={index}
              isFocused={index === carouselIndex}

            />
          );
        }}
      />

@dohooo

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants