mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-19 09:01:46 +08:00
Native Animated - Restore default values when removing props on Android
Summary: Same as #11819 but for Android. I didn't notice the bug initially in my app because I was using different animations on Android which did not trigger this issue. **Test plan** Created a simple repro example and tested that this fixes it. https://gist.github.com/janicduplessis/0f3eb362dae63fedf99a0d3ee041796a Closes https://github.com/facebook/react-native/pull/12842 Differential Revision: D5556439 Pulled By: hramos fbshipit-source-id: d13f4ad258d03cca46c793751ebc49d942b99152
This commit is contained in:
committed by
Facebook Github Bot
parent
b4f91be647
commit
ac43548063
@@ -92,7 +92,7 @@ import javax.annotation.Nullable;
|
||||
} else if ("value".equals(type)) {
|
||||
node = new ValueAnimatedNode(config);
|
||||
} else if ("props".equals(type)) {
|
||||
node = new PropsAnimatedNode(config, this);
|
||||
node = new PropsAnimatedNode(config, this, mUIImplementation);
|
||||
} else if ("interpolation".equals(type)) {
|
||||
node = new InterpolationAnimatedNode(config);
|
||||
} else if ("addition".equals(type)) {
|
||||
@@ -289,11 +289,7 @@ import javax.annotation.Nullable;
|
||||
"of type " + PropsAnimatedNode.class.getName());
|
||||
}
|
||||
PropsAnimatedNode propsAnimatedNode = (PropsAnimatedNode) node;
|
||||
if (propsAnimatedNode.mConnectedViewTag != -1) {
|
||||
throw new JSApplicationIllegalArgumentException("Animated node " + animatedNodeTag + " is " +
|
||||
"already attached to a view");
|
||||
}
|
||||
propsAnimatedNode.mConnectedViewTag = viewTag;
|
||||
propsAnimatedNode.connectToView(viewTag);
|
||||
mUpdatedNodes.put(animatedNodeTag, node);
|
||||
}
|
||||
|
||||
@@ -308,11 +304,24 @@ import javax.annotation.Nullable;
|
||||
"of type " + PropsAnimatedNode.class.getName());
|
||||
}
|
||||
PropsAnimatedNode propsAnimatedNode = (PropsAnimatedNode) node;
|
||||
if (propsAnimatedNode.mConnectedViewTag != viewTag) {
|
||||
throw new JSApplicationIllegalArgumentException("Attempting to disconnect view that has " +
|
||||
"not been connected with the given animated node");
|
||||
propsAnimatedNode.disconnectFromView(viewTag);
|
||||
}
|
||||
|
||||
public void restoreDefaultValues(int animatedNodeTag, int viewTag) {
|
||||
AnimatedNode node = mAnimatedNodes.get(animatedNodeTag);
|
||||
// Restoring default values needs to happen before UIManager operations so it is
|
||||
// possible the node hasn't been created yet if it is being connected and
|
||||
// disconnected in the same batch. In that case we don't need to restore
|
||||
// default values since it will never actually update the view.
|
||||
if (node == null) {
|
||||
return;
|
||||
}
|
||||
propsAnimatedNode.mConnectedViewTag = -1;
|
||||
if (!(node instanceof PropsAnimatedNode)) {
|
||||
throw new JSApplicationIllegalArgumentException("Animated node connected to view should be" +
|
||||
"of type " + PropsAnimatedNode.class.getName());
|
||||
}
|
||||
PropsAnimatedNode propsAnimatedNode = (PropsAnimatedNode) node;
|
||||
propsAnimatedNode.restoreDefaultValues();
|
||||
}
|
||||
|
||||
public void addAnimatedEventToView(int viewTag, String eventName, ReadableMap eventMapping) {
|
||||
@@ -513,7 +522,7 @@ import javax.annotation.Nullable;
|
||||
if (nextNode instanceof PropsAnimatedNode) {
|
||||
// Send property updates to native view manager
|
||||
try {
|
||||
((PropsAnimatedNode) nextNode).updateView(mUIImplementation);
|
||||
((PropsAnimatedNode) nextNode).updateView();
|
||||
} catch (IllegalViewOperationException e) {
|
||||
// An exception is thrown if the view hasn't been created yet. This can happen because views are
|
||||
// created in batches. If this particular view didn't make it into a batch yet, the view won't
|
||||
|
||||
Reference in New Issue
Block a user