Skip to content

Commit b49e7af

Browse files
janicduplessisFacebook Github Bot
authored and
Facebook Github Bot
committed
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 #10981 Differential Revision: D4226403 Pulled By: astreet fbshipit-source-id: 41278d3ed4b684af142d9e273b11b974eb679879
1 parent dad5204 commit b49e7af

File tree

6 files changed

+9
-33
lines changed

6 files changed

+9
-33
lines changed

Libraries/NativeAnimation/RCTNativeAnimatedModule.m

+2-6
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,11 @@ - (void)animatedNode:(RCTValueAnimatedNode *)node didUpdateValue:(CGFloat)value
322322
body:@{@"tag": node.nodeTag, @"value": @(value)}];
323323
}
324324

325-
- (BOOL)eventDispatcherWillDispatchEvent:(id<RCTEvent>)event
325+
- (void)eventDispatcherWillDispatchEvent:(id<RCTEvent>)event
326326
{
327327
// Native animated events only work for events dispatched from the main queue.
328328
if (!RCTIsMainQueue() || _eventAnimationDrivers.count == 0) {
329-
return NO;
329+
return;
330330
}
331331

332332
NSString *key = [NSString stringWithFormat:@"%@%@", event.viewTag, event.eventName];
@@ -336,11 +336,7 @@ - (BOOL)eventDispatcherWillDispatchEvent:(id<RCTEvent>)event
336336
[driver updateWithEvent:event];
337337
[self updateViewsProps];
338338
[driver.valueNode cleanupAnimationUpdate];
339-
340-
return YES;
341339
}
342-
343-
return NO;
344340
}
345341

346342
- (void)updateViewsProps

React/Base/RCTEventDispatcher.h

+2-3
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,9 @@ RCT_EXTERN NSString *RCTNormalizeInputEventName(NSString *eventName);
5858

5959
/**
6060
* Called before dispatching an event, on the same thread the event was
61-
* dispatched from. Return YES if the event was handled and must not be
62-
* sent to JS.
61+
* dispatched from.
6362
*/
64-
- (BOOL)eventDispatcherWillDispatchEvent:(id<RCTEvent>)event;
63+
- (void)eventDispatcherWillDispatchEvent:(id<RCTEvent>)event;
6564

6665
@end
6766

React/Base/RCTEventDispatcher.m

+1-8
Original file line numberDiff line numberDiff line change
@@ -146,19 +146,12 @@ - (void)sendEvent:(id<RCTEvent>)event
146146
{
147147
[_observersLock lock];
148148

149-
BOOL eventHandled = NO;
150149
for (id<RCTEventDispatcherObserver> observer in _observers) {
151-
if ([observer eventDispatcherWillDispatchEvent:event]) {
152-
eventHandled = YES;
153-
}
150+
[observer eventDispatcherWillDispatchEvent:event];
154151
}
155152

156153
[_observersLock unlock];
157154

158-
if (eventHandled) {
159-
return;
160-
}
161-
162155
[_eventQueueLock lock];
163156

164157
NSNumber *eventID = RCTGetEventID(event);

ReactAndroid/src/main/java/com/facebook/react/animated/NativeAnimatedNodesManager.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -314,10 +314,10 @@ public void removeAnimatedEventFromView(int viewTag, String eventName) {
314314
}
315315

316316
@Override
317-
public boolean onEventDispatch(Event event) {
317+
public void onEventDispatch(Event event) {
318318
// Only support events dispatched from the UI thread.
319319
if (!UiThreadUtil.isOnUiThread()) {
320-
return false;
320+
return;
321321
}
322322

323323
if (!mEventDrivers.isEmpty()) {
@@ -332,11 +332,8 @@ public boolean onEventDispatch(Event event) {
332332
if (eventDriver != null) {
333333
event.dispatch(eventDriver);
334334
mUpdatedNodes.put(eventDriver.mValueNode.mTag, eventDriver.mValueNode);
335-
return true;
336335
}
337336
}
338-
339-
return false;
340337
}
341338

342339
/**

ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcher.java

+1-9
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,8 @@ public EventDispatcher(ReactApplicationContext reactContext) {
114114
public void dispatchEvent(Event event) {
115115
Assertions.assertCondition(event.isInitialized(), "Dispatched event hasn't been initialized");
116116

117-
boolean eventHandled = false;
118117
for (EventDispatcherListener listener : mListeners) {
119-
if (listener.onEventDispatch(event)) {
120-
eventHandled = true;
121-
}
122-
}
123-
124-
// If the event was handled by one of the event listener don't send it to JS.
125-
if (eventHandled) {
126-
return;
118+
listener.onEventDispatch(event);
127119
}
128120

129121
synchronized (mEventsStagingLock) {

ReactAndroid/src/main/java/com/facebook/react/uimanager/events/EventDispatcherListener.java

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ public interface EventDispatcherListener {
1010
* Called on every time an event is dispatched using {#link EventDispatcher#dispatchEvent}. Will be
1111
* called from the same thread that the event is being dispatched from.
1212
* @param event Event that was dispatched
13-
* @return If the event was handled. If true the event won't be sent to JS.
1413
*/
15-
boolean onEventDispatch(Event event);
14+
void onEventDispatch(Event event);
1615
}

0 commit comments

Comments
 (0)