react-native - 如何在 React Native 中前后播放交错动画?
问题描述
我有一组动画在React Native
用户单击按钮时播放,但在第二次单击时我想stagger
向后播放动画。
这是我的代码
const mode = useMemo(() => new Animated.Value(0));
const bottom = useMemo(() => new Animated.Value(0));
const saleOpacityAnim = useMemo(() => new Animated.Value(0));
const sizeSale = useMemo(() => new Animated.Value(0));
const opacityText = useMemo(() => new Animated.Value(0));
const onAddPress = () => {
Animated.stagger(100, [
Animated.timing(bottom, {
toValue: bottom._value === 0 ? 1 : 0,
useNativeDriver: false
}),
Animated.timing(mode, {
toValue: mode._value === 0 ? 1 : 0,
useNativeDriver: false,
speed: 1
}),
Animated.timing(sizeSale, {
toValue: sizeSale._value === 0 ? 1 : 0,
useNativeDriver: false,
}),
Animated.timing(saleOpacityAnim, {
toValue: saleOpacityAnim._value === 0 ? 1 : 0,
useNativeDriver: false,
delay: 150,
duration: 300
}),
Animated.timing(opacityText, {
toValue: opacityText._value === 0 ? 1 : 0,
useNativeDriver: false,
}),
]).start()
}
const viewWidth = mode.interpolate({
inputRange: [0, 1],
outputRange: [0, 150],
});
const viewHeight = mode.interpolate({
inputRange: [0, 1],
outputRange: [0, styles.animationHeight.height],
});
const saleWidth = sizeSale.interpolate({
inputRange: [0, 1],
outputRange: [0, 150],
});
const saleHeight = sizeSale.interpolate({
inputRange: [0, 1],
outputRange: [0, styles.animationHeight.height],
});
const viewOpacity = bottom.interpolate({
inputRange: [0, 1],
outputRange: [0, 1],
});
const saleOpacity = saleOpacityAnim.interpolate({
inputRange: [0, 1],
outputRange: [0, 1],
});
const adoptBottom = bottom.interpolate({
inputRange: [0, 1],
outputRange: [0, 62],
});
const saleBottom = bottom.interpolate({
inputRange: [0, 1],
outputRange: [0, 124],
});
const textOpacity = opacityText.interpolate({
inputRange: [0, 1],
outputRange: [0, 1],
});
有没有道具可以做到这一点?否则怎么办?
解决方案
推荐阅读
- java - Java Batik 将 SVG 调整为面板大小,保持纵横比
- xamarin.forms - 想在数据库 MVVM 中添加一些东西
- ios - 适用于 iOS 7+ 的 swift 版本
- makefile - 为什么 make 命令在这里失败
- bokeh - Bokeh MultiLine p.add_tools(HoverTool(), renderers = [multiline]) 不工作
- angular - 如何在 Angular 6 中编辑材料日期选择器中的日期格式?
- javascript - lint 双逗号数组
- dialogflow-es - 当我的对话流培训页面充满 GOOGLE_ASSISTANT_WELCOME 时是否正常?
- mysql - 如何仅返回列的特定部分?
- python - macOS 中导入 PycURL 报错