mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-04-30 22:12:42 +08:00
Implement native Animated value listeners on Android
Summary: Adds support for `Animated.Value#addListener` for native driven nodes on Android. This is based on work by skevy in the exponent RN fork. Also adds a UIExplorer example. ** Test plan ** Run unit tests Tested that by adding a listener to a native driven animated node and checked that the listener callback is called properly. Also tested that it doesn't crash on iOS that doesn't support this yet. Closes https://github.com/facebook/react-native/pull/8844 Differential Revision: D3670906 fbshipit-source-id: 15700ed7b93db140d907ce80af4dae6be3102135
This commit is contained in:
committed by
Facebook Github Bot 7
parent
30677e7193
commit
158d435f36
@@ -11,13 +11,15 @@ package com.facebook.react.animated;
|
||||
|
||||
import com.facebook.react.bridge.ReadableMap;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Basic type of animated node that maps directly from {@code Animated.Value(x)} of Animated.js
|
||||
* library.
|
||||
*/
|
||||
/*package*/ class ValueAnimatedNode extends AnimatedNode {
|
||||
|
||||
/*package*/ double mValue = Double.NaN;
|
||||
private @Nullable AnimatedNodeValueListener mValueListener;
|
||||
|
||||
public ValueAnimatedNode() {
|
||||
// empty constructor that can be used by subclasses
|
||||
@@ -26,4 +28,15 @@ import com.facebook.react.bridge.ReadableMap;
|
||||
public ValueAnimatedNode(ReadableMap config) {
|
||||
mValue = config.getDouble("value");
|
||||
}
|
||||
|
||||
public void onValueUpdate() {
|
||||
if (mValueListener == null) {
|
||||
return;
|
||||
}
|
||||
mValueListener.onValueUpdate(mValue);
|
||||
}
|
||||
|
||||
public void setValueListener(@Nullable AnimatedNodeValueListener listener) {
|
||||
mValueListener = listener;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user