Dispatch native handled events to JS

Summary:
When native events where handled they were not sent to JS as an optimization but this caused some issues. One of the major one is touches are not handled properly inside a ScrollView with an Animated.event because it doesn't receive scroll events so it can't cancel the touch if the user scrolled.
Closes https://github.com/facebook/react-native/pull/10981

Differential Revision: D4226403

Pulled By: astreet

fbshipit-source-id: 41278d3ed4b684af142d9e273b11b974eb679879
This commit is contained in:
Janic Duplessis
2016-11-23 05:35:34 -08:00
committed by Facebook Github Bot
parent dad520476e
commit b49e7afe47
6 changed files with 9 additions and 33 deletions

View File

@@ -314,10 +314,10 @@ import javax.annotation.Nullable;
}
@Override
public boolean onEventDispatch(Event event) {
public void onEventDispatch(Event event) {
// Only support events dispatched from the UI thread.
if (!UiThreadUtil.isOnUiThread()) {
return false;
return;
}
if (!mEventDrivers.isEmpty()) {
@@ -332,11 +332,8 @@ import javax.annotation.Nullable;
if (eventDriver != null) {
event.dispatch(eventDriver);
mUpdatedNodes.put(eventDriver.mValueNode.mTag, eventDriver.mValueNode);
return true;
}
}
return false;
}
/**

View File

@@ -114,16 +114,8 @@ public class EventDispatcher implements LifecycleEventListener {
public void dispatchEvent(Event event) {
Assertions.assertCondition(event.isInitialized(), "Dispatched event hasn't been initialized");
boolean eventHandled = false;
for (EventDispatcherListener listener : mListeners) {
if (listener.onEventDispatch(event)) {
eventHandled = true;
}
}
// If the event was handled by one of the event listener don't send it to JS.
if (eventHandled) {
return;
listener.onEventDispatch(event);
}
synchronized (mEventsStagingLock) {

View File

@@ -10,7 +10,6 @@ public interface EventDispatcherListener {
* Called on every time an event is dispatched using {#link EventDispatcher#dispatchEvent}. Will be
* called from the same thread that the event is being dispatched from.
* @param event Event that was dispatched
* @return If the event was handled. If true the event won't be sent to JS.
*/
boolean onEventDispatch(Event event);
void onEventDispatch(Event event);
}