将复活的 1 转换为 2

问题描述

这相当于什么:

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

在重生2中?

解决方法

您仍然可以使用插值。只需使用 animationIndex.value,因为它现在需要是一个共享值。

// somewhere earlier
const animatedIndex = useSharedValue(0)

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