joh*_*doe 6 javascript react-native
我在React Native中收到警告,我已经缩小到一行,我不知道为什么.
我已经构建了一个辅助函数来为类似的系列中的颜色和值设置动画:
animate([this, "textColor", 250, "#fff1cc"]);
animate([this, "rise", 250, 25], [this, "rise", 250, 0]);
Run Code Online (Sandbox Code Playgroud)
而且该功能非常简单,请注意导致错误的注释行:
// React Modules
import { Animated } from "react-native";
// Export
export default function func() {
step(0, arguments);
}
// Extras
function step(index, args, delay = 0) {
if (args[index]) {
let argument = args[index];
index++;
handle(argument, delay, () => {
step(index, args);
});
}
}
function handle(argument, delay = 0, callback) {
let that = argument[0];
let label = argument[1];
let duration = argument[2];
let endColor = argument[3];
let startColor = argument[4];
if (!that.interpolations) {
that.interpolations = {};
}
if (!that.animations) {
that.animations = {};
}
if (!that.animations[label]) {
that.animations[label] = new Animated.Value(0);
}
if (typeof endColor == "string") {
if (!startColor) {
if (that.interpolations[label]) {
startColor = JSON.stringify(that.interpolations[label]);
} else {
startColor = "#ffffff";
}
}
that.interpolations[label] = that.animations[label].interpolate({
inputRange: [0, 100],
outputRange: [startColor, endColor]
});
startValue = 0;
endValue = 100;
} else {
startValue = startColor || that.animations[label] || 0;
// setting this to that.animations[label] causes the warning
endValue = endColor;
}
Animated.timing(that.animations[label], { // warning triggered when
// Animated.timing() executes while startValue is set to that.animations[label]
toValue: startValue,
duration: 0
}).start();
Animated.timing(that.animations[label], {
toValue: endValue,
duration: duration || 500
}).start(callback);
}
Run Code Online (Sandbox Code Playgroud)
除了那个警告,代码完美地按预期工作.我讨厌忽略一个我不明白的警告.我应该将此报告为React Native回购的错误,还是需要警告?堆栈跟踪,感兴趣的人.
好吧,我不确定百分百,因为我无法重现您的错误。根据您的堆栈跟踪,在L193中我们有:
singleValue.stopTracking();
Run Code Online (Sandbox Code Playgroud)
这有一系列操作试图取消跟踪动画值。
它将传递给的值视为Animated.timingan ,然后到达尝试分离动画的子节点AnimatedValue的点。我发现的唯一原因是您发送的值不是动画值,而是普通的原语。AnimatedWithChildrenValue
因此,如果您遵循官方文档的任何示例,您将看到startValue应该new Animated.Value(0)而不是0。因此,跟踪、分离和所有动画流程都可以在该值上正常工作。
仅在应用程序的一部分中,您将分配that.animations[label],即 a new Animated.Value,但在其他应用程序中,您直接分配一个整数,如startValue = 0;
| 归档时间: |
|
| 查看次数: |
333 次 |
| 最近记录: |