【发布时间】:2023-01-09 23:22:13
【问题描述】:
我正在使用 react-native-reanimated 并想为我的 expo-linear-gradient 设置动画颜色。不幸的是,什么都没有改变。我还创建了一个Expo Snack。
import * as React from 'react';
import { View, Button } from 'react-native';
import Animated, {
interpolateColor,
useAnimatedProps,
useSharedValue,
withTiming,
} from 'react-native-reanimated';
import { LinearGradient } from 'expo-linear-gradient';
const AnimatedLinearGradient = Animated.createAnimatedComponent(LinearGradient);
export default function App() {
const colorsValue = useSharedValue(1);
const animatedProps = useAnimatedProps(() => {
return {
colors: [
interpolateColor(colorsValue.value, [0, 1], ['#FFFFFF', '#000000']),
interpolateColor(colorsValue.value, [0, 1], ['#FFFFFF', '#00ff00']),
],
};
});
return (
<View>
<AnimatedLinearGradient
animatedProps={animatedProps}
style={{ height: 400, width: '100%' }}
/>
<Button
title="Change colors"
onPress={() => (colorsValue.value = withTiming(0, { duration: 2000 }))}
/>
</View>
);
}
我在这里错误地使用了 animatedProps 吗?任何帮助将不胜感激。
【问题讨论】:
标签: react-native expo react-native-reanimated react-native-reanimated-v2