mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Check for double dispose when sending touch event
Summary: Makes new touch processing path check for double dispose on touch events. Old event dispatcher has a race condition which makes it double-dispose some events, so we need to make sure it also processes touches correctly. Changelog: [Internal] Check for double dispose when sending touch event Reviewed By: cortinico Differential Revision: D32110250 fbshipit-source-id: d6a12cbac60f9ff5e836cfaca5a47c467bea06c7
This commit is contained in:
committed by
Facebook GitHub Bot
parent
aa515450fe
commit
deb6fbd929
@@ -182,21 +182,17 @@ public class TouchEvent extends Event<TouchEvent> {
|
||||
|
||||
@Override
|
||||
public void dispatch(RCTEventEmitter rctEventEmitter) {
|
||||
if (!hasMotionEvent()) {
|
||||
ReactSoftExceptionLogger.logSoftException(
|
||||
TAG,
|
||||
new IllegalStateException(
|
||||
"Cannot dispatch a TouchEvent that has no MotionEvent; the TouchEvent has been recycled"));
|
||||
return;
|
||||
if (verifyMotionEvent()) {
|
||||
TouchesHelper.sendTouchEvent(rctEventEmitter, this);
|
||||
}
|
||||
|
||||
TouchesHelper.sendTouchEvent(rctEventEmitter, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispatchModern(RCTModernEventEmitter rctEventEmitter) {
|
||||
if (ReactFeatureFlags.useUpdatedTouchPreprocessing) {
|
||||
TouchesHelper.sendTouchEventModern(rctEventEmitter, this, /* useDispatchV2 */ false);
|
||||
if (verifyMotionEvent()) {
|
||||
TouchesHelper.sendTouchEventModern(rctEventEmitter, this, /* useDispatchV2 */ false);
|
||||
}
|
||||
} else {
|
||||
dispatch(rctEventEmitter);
|
||||
}
|
||||
@@ -205,7 +201,9 @@ public class TouchEvent extends Event<TouchEvent> {
|
||||
@Override
|
||||
public void dispatchModernV2(RCTModernEventEmitter rctEventEmitter) {
|
||||
if (ReactFeatureFlags.useUpdatedTouchPreprocessing) {
|
||||
TouchesHelper.sendTouchEventModern(rctEventEmitter, this, /* useDispatchV2 */ true);
|
||||
if (verifyMotionEvent()) {
|
||||
TouchesHelper.sendTouchEventModern(rctEventEmitter, this, /* useDispatchV2 */ true);
|
||||
}
|
||||
} else {
|
||||
dispatch(rctEventEmitter);
|
||||
}
|
||||
@@ -237,8 +235,15 @@ public class TouchEvent extends Event<TouchEvent> {
|
||||
return mMotionEvent;
|
||||
}
|
||||
|
||||
private boolean hasMotionEvent() {
|
||||
return mMotionEvent != null;
|
||||
private boolean verifyMotionEvent() {
|
||||
if (mMotionEvent == null) {
|
||||
ReactSoftExceptionLogger.logSoftException(
|
||||
TAG,
|
||||
new IllegalStateException(
|
||||
"Cannot dispatch a TouchEvent that has no MotionEvent; the TouchEvent has been recycled"));
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public TouchEventType getTouchEventType() {
|
||||
|
||||
Reference in New Issue
Block a user