Native Animated - Allow events that are dispatched from any thread

Summary:
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 https://github.com/facebook/react-native/pull/15953

Differential Revision: D5909816

Pulled By: shergin

fbshipit-source-id: 48d02b6aa9f2bc3bcb638e8852fccaac3f205276
This commit is contained in:
Janic Duplessis 2017-09-25 23:07:01 -07:00 коммит произвёл Facebook Github Bot
Родитель b694f96762
Коммит 3cbc36138a
2 изменённых файлов: 19 добавлений и 9 удалений

Просмотреть файл

@ -239,11 +239,11 @@ RCT_EXPORT_METHOD(removeAnimatedEventFromView:(nonnull NSNumber *)viewTag
- (void)eventDispatcherWillDispatchEvent:(id<RCTEvent>)event - (void)eventDispatcherWillDispatchEvent:(id<RCTEvent>)event
{ {
// Native animated events only work for events dispatched from the main queue. // Events can be dispatched from any queue so we have to make sure handleAnimatedEvent
if (!RCTIsMainQueue()) { // is run from the main queue.
return; RCTExecuteOnMainQueue(^{
} [self->_nodesManager handleAnimatedEvent:event];
return [_nodesManager handleAnimatedEvent:event]; });
} }
@end @end

Просмотреть файл

@ -361,12 +361,22 @@ import javax.annotation.Nullable;
} }
@Override @Override
public void onEventDispatch(Event event) { public void onEventDispatch(final Event event) {
// Only support events dispatched from the UI thread. // Events can be dispatched from any thread so we have to make sure handleEvent is run from the
if (!UiThreadUtil.isOnUiThread()) { // UI thread.
return; if (UiThreadUtil.isOnUiThread()) {
handleEvent(event);
} else {
UiThreadUtil.runOnUiThread(new Runnable() {
@Override
public void run() {
handleEvent(event);
}
});
} }
}
private void handleEvent(Event event) {
if (!mEventDrivers.isEmpty()) { if (!mEventDrivers.isEmpty()) {
// If the event has a different name in native convert it to it's JS name. // If the event has a different name in native convert it to it's JS name.
String eventName = mCustomEventNamesResolver.resolveCustomEventName(event.getEventName()); String eventName = mCustomEventNamesResolver.resolveCustomEventName(event.getEventName());