Add support for animated events

Summary:
This adds support for `Animated.event` driven natively. This is WIP and would like feedback on how this is implemented.

At the moment, it works by providing a mapping between a view tag, an event name, an event path and an animated value when a view has a prop with a `AnimatedEvent` object. Then we can hook into `EventDispatcher`, check for events that target our view + event name and update the animated value using the event path.

For now it works with the onScroll event but it should be generic enough to work with anything.
Closes https://github.com/facebook/react-native/pull/9253

Differential Revision: D3759844

Pulled By: foghina

fbshipit-source-id: 86989c705847955bd65e6cf5a7d572ec7ccd3eb4
This commit is contained in:
Janic Duplessis
2016-09-19 04:07:36 -07:00
committed by Facebook Github Bot 9
parent 19d0429a76
commit 6565929358
13 changed files with 527 additions and 34 deletions

View File

@@ -25,7 +25,6 @@ import com.facebook.react.module.annotations.ReactModule;
import com.facebook.react.modules.core.DeviceEventManagerModule;
import com.facebook.react.uimanager.GuardedChoreographerFrameCallback;
import com.facebook.react.uimanager.ReactChoreographer;
import com.facebook.react.uimanager.UIImplementation;
import com.facebook.react.uimanager.UIManagerModule;
import java.util.ArrayList;
@@ -95,11 +94,9 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
mReactChoreographer = ReactChoreographer.getInstance();
ReactApplicationContext reactCtx = getReactApplicationContext();
UIImplementation uiImplementation =
reactCtx.getNativeModule(UIManagerModule.class).getUIImplementation();
UIManagerModule uiManager = reactCtx.getNativeModule(UIManagerModule.class);
final NativeAnimatedNodesManager nodesManager =
new NativeAnimatedNodesManager(uiImplementation);
final NativeAnimatedNodesManager nodesManager = new NativeAnimatedNodesManager(uiManager);
mAnimatedFrameCallback = new GuardedChoreographerFrameCallback(reactCtx) {
@Override
protected void doFrameGuarded(final long frameTimeNanos) {
@@ -312,4 +309,24 @@ public class NativeAnimatedModule extends ReactContextBaseJavaModule implements
}
});
}
@ReactMethod
public void addAnimatedEventToView(final int viewTag, final String eventName, final ReadableMap eventMapping) {
mOperations.add(new UIThreadOperation() {
@Override
public void execute(NativeAnimatedNodesManager animatedNodesManager) {
animatedNodesManager.addAnimatedEventToView(viewTag, eventName, eventMapping);
}
});
}
@ReactMethod
public void removeAnimatedEventFromView(final int viewTag, final String eventName) {
mOperations.add(new UIThreadOperation() {
@Override
public void execute(NativeAnimatedNodesManager animatedNodesManager) {
animatedNodesManager.removeAnimatedEventFromView(viewTag, eventName);
}
});
}
}