mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Part 2: Make CatalystInstanceImpl.getNativeModule Nullable
Summary: This is the codemod portion of the parent diff. I modified all call-sites to `ReactContext.getNativeModule` to do a null check on the returned NativeModule. Changelog: [Android][Fixed] - Check if NativeModules returned from CatalystInstanceImpl.getNativeModule are null before using them. Reviewed By: JoshuaGross Differential Revision: D21272028 fbshipit-source-id: 6bd16c6bf30605f2dfdf4c481352063712965342
This commit is contained in:
committed by
Facebook GitHub Bot
parent
1cef72af04
commit
9263eb5d38
@@ -470,7 +470,9 @@ public class ReactInstanceManager {
|
||||
} else {
|
||||
DeviceEventManagerModule deviceEventManagerModule =
|
||||
reactContext.getNativeModule(DeviceEventManagerModule.class);
|
||||
deviceEventManagerModule.emitHardwareBackPressed();
|
||||
if (deviceEventManagerModule != null) {
|
||||
deviceEventManagerModule.emitHardwareBackPressed();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -497,7 +499,9 @@ public class ReactInstanceManager {
|
||||
|| NfcAdapter.ACTION_NDEF_DISCOVERED.equals(action))) {
|
||||
DeviceEventManagerModule deviceEventManagerModule =
|
||||
currentContext.getNativeModule(DeviceEventManagerModule.class);
|
||||
deviceEventManagerModule.emitNewIntentReceived(uri);
|
||||
if (deviceEventManagerModule != null) {
|
||||
deviceEventManagerModule.emitNewIntentReceived(uri);
|
||||
}
|
||||
}
|
||||
currentContext.onNewIntent(mCurrentActivity, intent);
|
||||
}
|
||||
@@ -775,9 +779,12 @@ public class ReactInstanceManager {
|
||||
|
||||
ReactContext currentReactContext = getCurrentReactContext();
|
||||
if (currentReactContext != null) {
|
||||
currentReactContext
|
||||
.getNativeModule(AppearanceModule.class)
|
||||
.onConfigurationChanged(updatedContext);
|
||||
AppearanceModule appearanceModule =
|
||||
currentReactContext.getNativeModule(AppearanceModule.class);
|
||||
|
||||
if (appearanceModule != null) {
|
||||
appearanceModule.onConfigurationChanged(updatedContext);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -200,9 +200,12 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
|
||||
return;
|
||||
}
|
||||
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
|
||||
EventDispatcher eventDispatcher =
|
||||
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
||||
mJSTouchDispatcher.onChildStartedNativeGesture(androidEvent, eventDispatcher);
|
||||
UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
|
||||
|
||||
if (uiManager != null) {
|
||||
EventDispatcher eventDispatcher = uiManager.getEventDispatcher();
|
||||
mJSTouchDispatcher.onChildStartedNativeGesture(androidEvent, eventDispatcher);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -285,9 +288,12 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
|
||||
return;
|
||||
}
|
||||
ReactContext reactContext = mReactInstanceManager.getCurrentReactContext();
|
||||
EventDispatcher eventDispatcher =
|
||||
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
||||
mJSTouchDispatcher.handleTouchEvent(event, eventDispatcher);
|
||||
UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
|
||||
|
||||
if (uiManager != null) {
|
||||
EventDispatcher eventDispatcher = uiManager.getEventDispatcher();
|
||||
mJSTouchDispatcher.handleTouchEvent(event, eventDispatcher);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -749,10 +755,12 @@ public class ReactRootView extends FrameLayout implements RootView, ReactRoot {
|
||||
}
|
||||
|
||||
private void emitUpdateDimensionsEvent() {
|
||||
mReactInstanceManager
|
||||
.getCurrentReactContext()
|
||||
.getNativeModule(DeviceInfoModule.class)
|
||||
.emitUpdateDimensionsEvent();
|
||||
DeviceInfoModule deviceInfo =
|
||||
mReactInstanceManager.getCurrentReactContext().getNativeModule(DeviceInfoModule.class);
|
||||
|
||||
if (deviceInfo != null) {
|
||||
deviceInfo.emitUpdateDimensionsEvent();
|
||||
}
|
||||
}
|
||||
|
||||
private WritableMap createKeyboardEventPayload(
|
||||
|
||||
@@ -130,7 +130,8 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec
|
||||
// TODO T59412313 Implement this API on FabricUIManager to use in bridgeless mode
|
||||
if (reactApplicationContext != null && !reactApplicationContext.isBridgeless()) {
|
||||
reactApplicationContext.addLifecycleEventListener(this);
|
||||
UIManagerModule uiManager = reactApplicationContext.getNativeModule(UIManagerModule.class);
|
||||
UIManagerModule uiManager =
|
||||
Assertions.assertNotNull(reactApplicationContext.getNativeModule(UIManagerModule.class));
|
||||
uiManager.addUIManagerListener(this);
|
||||
}
|
||||
}
|
||||
@@ -191,7 +192,9 @@ public class NativeAnimatedModule extends NativeAnimatedModuleSpec
|
||||
ReactApplicationContext reactApplicationContext = getReactApplicationContextIfActiveOrWarn();
|
||||
|
||||
if (reactApplicationContext != null) {
|
||||
UIManagerModule uiManager = reactApplicationContext.getNativeModule(UIManagerModule.class);
|
||||
UIManagerModule uiManager =
|
||||
Assertions.assertNotNull(
|
||||
reactApplicationContext.getNativeModule(UIManagerModule.class));
|
||||
mNodesManager = new NativeAnimatedNodesManager(uiManager);
|
||||
}
|
||||
}
|
||||
|
||||
+15
-12
@@ -962,19 +962,22 @@ public abstract class DevSupportManagerBase
|
||||
return;
|
||||
}
|
||||
JSCHeapCapture heapCapture = mCurrentContext.getNativeModule(JSCHeapCapture.class);
|
||||
heapCapture.captureHeap(
|
||||
mApplicationContext.getCacheDir().getPath(),
|
||||
new JSCHeapCapture.CaptureCallback() {
|
||||
@Override
|
||||
public void onSuccess(File capture) {
|
||||
responder.respond(capture.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(JSCHeapCapture.CaptureException error) {
|
||||
responder.error(error.toString());
|
||||
}
|
||||
});
|
||||
if (heapCapture != null) {
|
||||
heapCapture.captureHeap(
|
||||
mApplicationContext.getCacheDir().getPath(),
|
||||
new JSCHeapCapture.CaptureCallback() {
|
||||
@Override
|
||||
public void onSuccess(File capture) {
|
||||
responder.respond(capture.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(JSCHeapCapture.CaptureException error) {
|
||||
responder.error(error.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void updateLastErrorInfo(
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
package com.facebook.react.fabric;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.JSIModuleProvider;
|
||||
import com.facebook.react.bridge.JavaScriptContextHolder;
|
||||
import com.facebook.react.bridge.ReactApplicationContext;
|
||||
@@ -83,7 +84,8 @@ public class FabricJSIModuleProvider implements JSIModuleProvider<UIManager> {
|
||||
private FabricUIManager createUIManager(@NonNull EventBeatManager eventBeatManager) {
|
||||
Systrace.beginSection(
|
||||
Systrace.TRACE_TAG_REACT_JAVA_BRIDGE, "FabricJSIModuleProvider.createUIManager");
|
||||
UIManagerModule nativeModule = mReactApplicationContext.getNativeModule(UIManagerModule.class);
|
||||
UIManagerModule nativeModule =
|
||||
Assertions.assertNotNull(mReactApplicationContext.getNativeModule(UIManagerModule.class));
|
||||
EventDispatcher eventDispatcher = nativeModule.getEventDispatcher();
|
||||
FabricUIManager fabricUIManager =
|
||||
new FabricUIManager(
|
||||
|
||||
+2
-1
@@ -75,7 +75,8 @@ public class FpsDebugFrameCallback extends ChoreographerCompat.FrameCallback {
|
||||
|
||||
public FpsDebugFrameCallback(ReactContext reactContext) {
|
||||
mReactContext = reactContext;
|
||||
mUIManagerModule = reactContext.getNativeModule(UIManagerModule.class);
|
||||
mUIManagerModule =
|
||||
Assertions.assertNotNull(reactContext.getNativeModule(UIManagerModule.class));
|
||||
mDidJSUpdateUiDuringFrameDetector = new DidJSUpdateUiDuringFrameDetector();
|
||||
}
|
||||
|
||||
|
||||
@@ -113,11 +113,14 @@ public class UIViewOperationQueue {
|
||||
|
||||
@Override
|
||||
public void execute() {
|
||||
mReactApplicationContext
|
||||
.getNativeModule(UIManagerModule.class)
|
||||
.getEventDispatcher()
|
||||
.dispatchEvent(
|
||||
OnLayoutEvent.obtain(mTag, mScreenX, mScreenY, mScreenWidth, mScreenHeight));
|
||||
UIManagerModule uiManager = mReactApplicationContext.getNativeModule(UIManagerModule.class);
|
||||
|
||||
if (uiManager != null) {
|
||||
uiManager
|
||||
.getEventDispatcher()
|
||||
.dispatchEvent(
|
||||
OnLayoutEvent.obtain(mTag, mScreenX, mScreenY, mScreenWidth, mScreenHeight));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-3
@@ -56,9 +56,12 @@ public class ReactDrawerLayoutManager extends ViewGroupManager<ReactDrawerLayout
|
||||
|
||||
@Override
|
||||
protected void addEventEmitters(ThemedReactContext reactContext, ReactDrawerLayout view) {
|
||||
view.addDrawerListener(
|
||||
new DrawerEventEmitter(
|
||||
view, reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()));
|
||||
UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
|
||||
if (uiManager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
view.addDrawerListener(new DrawerEventEmitter(view, uiManager.getEventDispatcher()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-2
@@ -105,8 +105,12 @@ public class ReactModalHostManager extends ViewGroupManager<ReactModalHostView>
|
||||
|
||||
@Override
|
||||
protected void addEventEmitters(ThemedReactContext reactContext, final ReactModalHostView view) {
|
||||
final EventDispatcher dispatcher =
|
||||
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
||||
UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
|
||||
if (uiManager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final EventDispatcher dispatcher = uiManager.getEventDispatcher();
|
||||
view.setOnRequestCloseListener(
|
||||
new ReactModalHostView.OnRequestCloseListener() {
|
||||
@Override
|
||||
|
||||
@@ -414,9 +414,14 @@ public class ReactModalHostView extends ViewGroup implements LifecycleEventListe
|
||||
new GuardedRunnable(reactContext) {
|
||||
@Override
|
||||
public void runGuarded() {
|
||||
(getReactContext())
|
||||
.getNativeModule(UIManagerModule.class)
|
||||
.updateNodeSize(viewTag, viewWidth, viewHeight);
|
||||
UIManagerModule uiManager =
|
||||
(getReactContext()).getNativeModule(UIManagerModule.class);
|
||||
|
||||
if (uiManager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
uiManager.updateNodeSize(viewTag, viewWidth, viewHeight);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -62,9 +62,13 @@ public abstract class ReactPickerManager extends SimpleViewManager<ReactPicker>
|
||||
|
||||
@Override
|
||||
protected void addEventEmitters(final ThemedReactContext reactContext, final ReactPicker picker) {
|
||||
picker.setOnSelectListener(
|
||||
new PickerEventEmitter(
|
||||
picker, reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher()));
|
||||
UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
|
||||
|
||||
if (uiManager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
picker.setOnSelectListener(new PickerEventEmitter(picker, uiManager.getEventDispatcher()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+21
-13
@@ -91,12 +91,17 @@ public class ReactSliderManager extends SimpleViewManager<ReactSlider>
|
||||
@Override
|
||||
public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) {
|
||||
ReactContext reactContext = (ReactContext) seekbar.getContext();
|
||||
reactContext
|
||||
.getNativeModule(UIManagerModule.class)
|
||||
.getEventDispatcher()
|
||||
.dispatchEvent(
|
||||
new ReactSliderEvent(
|
||||
seekbar.getId(), ((ReactSlider) seekbar).toRealProgress(progress), fromUser));
|
||||
UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
|
||||
|
||||
if (uiManager != null) {
|
||||
uiManager
|
||||
.getEventDispatcher()
|
||||
.dispatchEvent(
|
||||
new ReactSliderEvent(
|
||||
seekbar.getId(),
|
||||
((ReactSlider) seekbar).toRealProgress(progress),
|
||||
fromUser));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,13 +110,16 @@ public class ReactSliderManager extends SimpleViewManager<ReactSlider>
|
||||
@Override
|
||||
public void onStopTrackingTouch(SeekBar seekbar) {
|
||||
ReactContext reactContext = (ReactContext) seekbar.getContext();
|
||||
reactContext
|
||||
.getNativeModule(UIManagerModule.class)
|
||||
.getEventDispatcher()
|
||||
.dispatchEvent(
|
||||
new ReactSlidingCompleteEvent(
|
||||
seekbar.getId(),
|
||||
((ReactSlider) seekbar).toRealProgress(seekbar.getProgress())));
|
||||
UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
|
||||
|
||||
if (uiManager != null) {
|
||||
uiManager
|
||||
.getEventDispatcher()
|
||||
.dispatchEvent(
|
||||
new ReactSlidingCompleteEvent(
|
||||
seekbar.getId(),
|
||||
((ReactSlider) seekbar).toRealProgress(seekbar.getProgress())));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+8
-2
@@ -80,8 +80,14 @@ public class ReactSwitchManager extends SimpleViewManager<ReactSwitch>
|
||||
@Override
|
||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||
ReactContext reactContext = (ReactContext) buttonView.getContext();
|
||||
reactContext
|
||||
.getNativeModule(UIManagerModule.class)
|
||||
|
||||
UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
|
||||
|
||||
if (uiManager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
uiManager
|
||||
.getEventDispatcher()
|
||||
.dispatchEvent(new ReactSwitchEvent(buttonView.getId(), isChecked));
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.widget.AppCompatTextView;
|
||||
import androidx.appcompat.widget.TintContextWrapper;
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.Arguments;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.bridge.WritableArray;
|
||||
@@ -118,7 +119,8 @@ public class ReactTextView extends AppCompatTextView implements ReactCompoundVie
|
||||
}
|
||||
|
||||
ReactContext reactContext = getReactContext();
|
||||
UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
|
||||
UIManagerModule uiManager =
|
||||
Assertions.assertNotNull(reactContext.getNativeModule(UIManagerModule.class));
|
||||
|
||||
Spanned text = (Spanned) getText();
|
||||
Layout layout = getLayout();
|
||||
|
||||
@@ -609,7 +609,9 @@ public class ReactEditText extends AppCompatEditText {
|
||||
ReactContext reactContext = getReactContext(this);
|
||||
final ReactTextInputLocalData localData = new ReactTextInputLocalData(this);
|
||||
UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
|
||||
uiManager.setViewLocalData(getId(), localData);
|
||||
if (uiManager != null) {
|
||||
uiManager.setViewLocalData(getId(), localData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-1
@@ -12,6 +12,7 @@ import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputConnection;
|
||||
import android.view.inputmethod.InputConnectionWrapper;
|
||||
import androidx.annotation.Nullable;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
import com.facebook.react.uimanager.events.EventDispatcher;
|
||||
@@ -62,7 +63,9 @@ class ReactEditTextInputConnectionWrapper extends InputConnectionWrapper {
|
||||
public ReactEditTextInputConnectionWrapper(
|
||||
InputConnection target, final ReactContext reactContext, final ReactEditText editText) {
|
||||
super(target, false);
|
||||
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
||||
mEventDispatcher =
|
||||
Assertions.assertNotNull(reactContext.getNativeModule(UIManagerModule.class))
|
||||
.getEventDispatcher();
|
||||
mEditText = editText;
|
||||
}
|
||||
|
||||
|
||||
+7
-2
@@ -1090,18 +1090,23 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
|
||||
|
||||
private class ReactContentSizeWatcher implements ContentSizeWatcher {
|
||||
private ReactEditText mEditText;
|
||||
private EventDispatcher mEventDispatcher;
|
||||
private @Nullable EventDispatcher mEventDispatcher;
|
||||
private int mPreviousContentWidth = 0;
|
||||
private int mPreviousContentHeight = 0;
|
||||
|
||||
public ReactContentSizeWatcher(ReactEditText editText) {
|
||||
mEditText = editText;
|
||||
ReactContext reactContext = getReactContext(editText);
|
||||
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
||||
UIManagerModule uiManager = reactContext.getNativeModule(UIManagerModule.class);
|
||||
mEventDispatcher = uiManager != null ? uiManager.getEventDispatcher() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLayout() {
|
||||
if (mEventDispatcher == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
int contentWidth = mEditText.getWidth();
|
||||
int contentHeight = mEditText.getHeight();
|
||||
|
||||
|
||||
@@ -233,10 +233,14 @@ public class ReactViewManager extends ReactClippingViewManager<ReactViewGroup> {
|
||||
new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
final EventDispatcher mEventDispatcher =
|
||||
((ReactContext) view.getContext())
|
||||
.getNativeModule(UIManagerModule.class)
|
||||
.getEventDispatcher();
|
||||
UIManagerModule uiManager =
|
||||
((ReactContext) view.getContext()).getNativeModule(UIManagerModule.class);
|
||||
|
||||
if (uiManager == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final EventDispatcher mEventDispatcher = uiManager.getEventDispatcher();
|
||||
mEventDispatcher.dispatchEvent(new ViewGroupClickEvent(view.getId()));
|
||||
}
|
||||
});
|
||||
|
||||
@@ -13,6 +13,7 @@ import android.view.ViewGroup;
|
||||
import androidx.viewpager.widget.PagerAdapter;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import com.facebook.common.logging.FLog;
|
||||
import com.facebook.infer.annotation.Assertions;
|
||||
import com.facebook.react.bridge.ReactContext;
|
||||
import com.facebook.react.common.ReactConstants;
|
||||
import com.facebook.react.uimanager.UIManagerModule;
|
||||
@@ -154,7 +155,9 @@ public class ReactViewPager extends ViewPager {
|
||||
|
||||
public ReactViewPager(ReactContext reactContext) {
|
||||
super(reactContext);
|
||||
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
|
||||
mEventDispatcher =
|
||||
Assertions.assertNotNull(reactContext.getNativeModule(UIManagerModule.class))
|
||||
.getEventDispatcher();
|
||||
mIsCurrentItemFromJs = false;
|
||||
setOnPageChangeListener(new PageChangeListener());
|
||||
setAdapter(new Adapter());
|
||||
|
||||
Reference in New Issue
Block a user