mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
db5994980d
Summary: We noticed a repro-able crash in Ride in T52804960 on Android Q due to NaN being passed into setCameraDistance on View see Oleg's related post: https://fb.workplace.com/groups/rn.support/permalink/2682537011794897/ It looks like a generic fix or wrapper around View setCameraDistance might be planned in T48580247 But in the meantime, it kind of maybe seems reasonable-ish to say, ~~if the value of an input node is NaN, don't use it in the math for this node?~~ if a one of the inputs for this node evaluates to NaN, update that input node first? But I'm not super familiar with the Animations library so maybe that's not a good idea, idk. From what I can tell in our specific error, it's coming from an InterpolatedNode A based off an AdditionNode B which tried to add a ValueNode C + a InterpolatedNode D, but D had only just been created and not had it's first update, so it's value was NaN, and so when B runs it's update value of C + NaN means B's new values is also NaN, and A's subsequent update based on that now comes out to NaN. Atleast that's what it seems like based on Log statements. Reviewed By: olegbl Differential Revision: D16960177 fbshipit-source-id: 99c8ca35be4b5e99f7c21db6733ebd622ae39d07
63 lines
1.5 KiB
Java
63 lines
1.5 KiB
Java
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* <p>This source code is licensed under the MIT license found in the LICENSE file in the root
|
|
* directory of this source tree.
|
|
*/
|
|
package com.facebook.react.animated;
|
|
|
|
import androidx.annotation.Nullable;
|
|
import com.facebook.react.bridge.ReadableMap;
|
|
|
|
/**
|
|
* Basic type of animated node that maps directly from {@code Animated.Value(x)} of Animated.js
|
|
* library.
|
|
*/
|
|
/*package*/ class ValueAnimatedNode extends AnimatedNode {
|
|
/*package*/ Object mAnimatedObject = null;
|
|
/*package*/ double mValue = Double.NaN;
|
|
/*package*/ double mOffset = 0;
|
|
private @Nullable AnimatedNodeValueListener mValueListener;
|
|
|
|
public ValueAnimatedNode() {
|
|
// empty constructor that can be used by subclasses
|
|
}
|
|
|
|
public ValueAnimatedNode(ReadableMap config) {
|
|
mValue = config.getDouble("value");
|
|
mOffset = config.getDouble("offset");
|
|
}
|
|
|
|
public double getValue() {
|
|
if (Double.isNaN(mOffset + mValue)) {
|
|
this.update();
|
|
}
|
|
return mOffset + mValue;
|
|
}
|
|
|
|
public Object getAnimatedObject() {
|
|
return mAnimatedObject;
|
|
}
|
|
|
|
public void flattenOffset() {
|
|
mValue += mOffset;
|
|
mOffset = 0;
|
|
}
|
|
|
|
public void extractOffset() {
|
|
mOffset += mValue;
|
|
mValue = 0;
|
|
}
|
|
|
|
public void onValueUpdate() {
|
|
if (mValueListener == null) {
|
|
return;
|
|
}
|
|
mValueListener.onValueUpdate(getValue());
|
|
}
|
|
|
|
public void setValueListener(@Nullable AnimatedNodeValueListener listener) {
|
|
mValueListener = listener;
|
|
}
|
|
}
|