将复活的 1 转换为 2
convert reanimated 1 to 2
这相当于什么:
const scrollViewStyle = useMemo(
() => [
{
opacity: interpolate(animatedIndex, {
inputRange: [0, 1],
outputRange: [0, 1],
extrapolate: Extrapolate.CLAMP,
}),
},
],
[animatedIndex]
);
在复活 2 中?
您仍然可以使用插值。只需使用 animatedIndex.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,
}),
}
},
);
这相当于什么:
const scrollViewStyle = useMemo(
() => [
{
opacity: interpolate(animatedIndex, {
inputRange: [0, 1],
outputRange: [0, 1],
extrapolate: Extrapolate.CLAMP,
}),
},
],
[animatedIndex]
);
在复活 2 中?
您仍然可以使用插值。只需使用 animatedIndex.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,
}),
}
},
);