0

What's the equivalent of this:

const scrollViewStyle = useMemo(
  () => [
    {
      opacity: interpolate(animatedIndex, {
        inputRange: [0, 1],
        outputRange: [0, 1],
        extrapolate: Extrapolate.CLAMP,
      }),
    },
  ],
  [animatedIndex]
);

in reanimated 2?

Ben
  • 2,957
  • 2
  • 27
  • 55

1 Answers1

1

You can still use interpolate. Just use animatedIndex.value, as it's now needs to be a shared value.

// somewhere earlier
const animatedIndex = useSharedValue(0)

// calculate style object
const scrollViewStyle = useAnimatedStyle(
  () => {
     return {
      opacity: interpolate(animatedIndex.value, {
        inputRange: [0, 1],
        outputRange: [0, 1],
        extrapolate: Extrapolate.CLAMP,
      }),
    }
  },
);
Dom
  • 658
  • 6
  • 10