Files
react-native/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeAnimatedModuleSpec.java
T
Janic DuplessisandFacebook Github Bot 686ab49107 Don't restore default values when components unmount (#26978)
Summary:
There are some cases where restoring default values on component unmount is not desirable. For example in react-native-screens we want to keep the native view displayed after react has unmounted them. Restoring default values causes an issue there because it will change props controlled my native animated back to their default value instead of keeping whatever value they had been animated to.

Restoring default values is only needed for updates anyway, where removing a prop controlled by native animated need to be reset to its default value since react no longer tracks its value.

This splits restoring default values and disconnecting from views in 2 separate native methods, this way we can restore default values only on component update and not on unmount. This takes care of being backwards compatible for JS running with the older native code.

## Changelog

[General] [Fixed] - NativeAnimated - Don't restore default values when components unmount
Pull Request resolved: https://github.com/facebook/react-native/pull/26978

Test Plan:
- Tested in an app using react-native-screens to make sure native views that are kept after their underlying component has been unmount don't change. Also tested in RNTester animated example.

- Tested that new JS works with old native code

Reviewed By: mmmulani

Differential Revision: D18197735

Pulled By: JoshuaGross

fbshipit-source-id: 20fa0f31a3edf1bc57ccb03df9d1486aba83edc4
2019-11-04 15:40:09 -08:00

88 lines
2.6 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.
*
* <p>Generated by an internal genrule from Flow types.
*
* @generated
* @nolint
*/
package com.facebook.fbreact.specs;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReactModuleWithSpec;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
public abstract class NativeAnimatedModuleSpec extends ReactContextBaseJavaModule implements ReactModuleWithSpec, TurboModule {
public NativeAnimatedModuleSpec(ReactApplicationContext reactContext) {
super(reactContext);
}
@ReactMethod
public abstract void dropAnimatedNode(double tag);
@ReactMethod
public abstract void connectAnimatedNodes(double parentTag, double childTag);
@ReactMethod
public abstract void stopAnimation(double animationId);
@ReactMethod
public abstract void removeListeners(double count);
@ReactMethod
public abstract void disconnectAnimatedNodeFromView(double nodeTag, double viewTag);
@ReactMethod
public abstract void removeAnimatedEventFromView(double viewTag, String eventName,
double animatedNodeTag);
@ReactMethod
public abstract void flattenAnimatedNodeOffset(double nodeTag);
@ReactMethod
public abstract void extractAnimatedNodeOffset(double nodeTag);
@ReactMethod
public abstract void disconnectAnimatedNodes(double parentTag, double childTag);
@ReactMethod
public abstract void setAnimatedNodeValue(double nodeTag, double value);
@ReactMethod
public abstract void setAnimatedNodeOffset(double nodeTag, double offset);
@ReactMethod
public abstract void restoreDefaultValues(double nodeTag);
@ReactMethod
public abstract void startAnimatingNode(double animationId, double nodeTag, ReadableMap config,
Callback endCallback);
@ReactMethod
public abstract void stopListeningToAnimatedNodeValue(double tag);
@ReactMethod
public abstract void addAnimatedEventToView(double viewTag, String eventName,
ReadableMap eventMapping);
@ReactMethod
public abstract void createAnimatedNode(double tag, ReadableMap config);
@ReactMethod
public abstract void startListeningToAnimatedNodeValue(double tag);
@ReactMethod
public abstract void connectAnimatedNodeToView(double nodeTag, double viewTag);
@ReactMethod
public abstract void addListener(String eventName);
}