Browse files

Native Animated - Allow events that are dispatched from any thread

Instead of preventing events from working when not on the UI Thread we can just dispatch to it instead.

**Test plan**
Tested manually that animated events still work in RNTester
Closes #15953

Differential Revision: D5909816

Pulled By: shergin

fbshipit-source-id: 48d02b6aa9f2bc3bcb638e8852fccaac3f205276
  • Loading branch information...
janicduplessis authored and facebook-github-bot committed Sep 26, 2017
1 parent b694f96 commit 3cbc36138afd50bdbbdf2ad54b7a71a80b319bbc
@@ -239,11 +239,11 @@ - (void)animatedNode:(RCTValueAnimatedNode *)node didUpdateValue:(CGFloat)value
- (void)eventDispatcherWillDispatchEvent:(id<RCTEvent>)event
// Native animated events only work for events dispatched from the main queue.
if (!RCTIsMainQueue()) {
return [_nodesManager handleAnimatedEvent:event];
// Events can be dispatched from any queue so we have to make sure handleAnimatedEvent
// is run from the main queue.
[self->_nodesManager handleAnimatedEvent:event];
@@ -361,12 +361,22 @@ public void removeAnimatedEventFromView(int viewTag, String eventName, int anima
public void onEventDispatch(Event event) {
// Only support events dispatched from the UI thread.
if (!UiThreadUtil.isOnUiThread()) {
public void onEventDispatch(final Event event) {
// Events can be dispatched from any thread so we have to make sure handleEvent is run from the
// UI thread.
if (UiThreadUtil.isOnUiThread()) {
} else {
UiThreadUtil.runOnUiThread(new Runnable() {
public void run() {
private void handleEvent(Event event) {
if (!mEventDrivers.isEmpty()) {
// If the event has a different name in native convert it to it's JS name.
String eventName = mCustomEventNamesResolver.resolveCustomEventName(event.getEventName());

0 comments on commit 3cbc361

Please sign in to comment.