|
27 | 27 | import com.facebook.react.uimanager.UIManagerHelper;
|
28 | 28 | import com.facebook.react.uimanager.common.UIManagerType;
|
29 | 29 | import com.facebook.react.uimanager.common.ViewUtil;
|
| 30 | +import com.facebook.react.uimanager.events.EventDispatcher; |
30 | 31 | import java.util.Collections;
|
31 | 32 | import java.util.Set;
|
32 | 33 | import java.util.WeakHashMap;
|
@@ -107,20 +108,28 @@ private static void emitScrollEvent(
|
107 | 108 |
|
108 | 109 | ReactContext reactContext = (ReactContext) scrollView.getContext();
|
109 | 110 | int surfaceId = UIManagerHelper.getSurfaceId(reactContext);
|
110 |
| - UIManagerHelper.getEventDispatcherForReactTag(reactContext, scrollView.getId()) |
111 |
| - .dispatchEvent( |
112 |
| - ScrollEvent.obtain( |
113 |
| - surfaceId, |
114 |
| - scrollView.getId(), |
115 |
| - scrollEventType, |
116 |
| - scrollView.getScrollX(), |
117 |
| - scrollView.getScrollY(), |
118 |
| - xVelocity, |
119 |
| - yVelocity, |
120 |
| - contentView.getWidth(), |
121 |
| - contentView.getHeight(), |
122 |
| - scrollView.getWidth(), |
123 |
| - scrollView.getHeight())); |
| 111 | + |
| 112 | + // It's possible for the EventDispatcher to go away - for example, |
| 113 | + // if there's a crash initiated from JS and we tap on a ScrollView |
| 114 | + // around teardown of RN, this will cause a NPE. We can safely ignore |
| 115 | + // this since the crash is usually a red herring. |
| 116 | + EventDispatcher eventDispatcher = |
| 117 | + UIManagerHelper.getEventDispatcherForReactTag(reactContext, scrollView.getId()); |
| 118 | + if (eventDispatcher != null) { |
| 119 | + eventDispatcher.dispatchEvent( |
| 120 | + ScrollEvent.obtain( |
| 121 | + surfaceId, |
| 122 | + scrollView.getId(), |
| 123 | + scrollEventType, |
| 124 | + scrollView.getScrollX(), |
| 125 | + scrollView.getScrollY(), |
| 126 | + xVelocity, |
| 127 | + yVelocity, |
| 128 | + contentView.getWidth(), |
| 129 | + contentView.getHeight(), |
| 130 | + scrollView.getWidth(), |
| 131 | + scrollView.getHeight())); |
| 132 | + } |
124 | 133 | }
|
125 | 134 |
|
126 | 135 | /** This is only for Java listeners. onLayout events emitted to JS are handled elsewhere. */
|
|
0 commit comments