Migrate ReactTextInputManager to be bridgeless

Summary: Migrate ReactTextinputManager to support bridgeless mode by accessing the EventDispatcher through the UIManagerHelper instead of from ReactContext.

Reviewed By: mdvacca

Differential Revision: D19614184

fbshipit-source-id: 5dd4945223d10785f8fe171e06d6f7ef42f9d834
This commit is contained in:
Emily Janzer
2020-01-30 18:32:03 -08:00
committed by Facebook Github Bot
parent 1c83e5a917
commit b592c863ef
2 changed files with 14 additions and 10 deletions
@@ -17,6 +17,7 @@ import androidx.annotation.Nullable;
import com.facebook.react.bridge.CatalystInstance;
import com.facebook.react.bridge.JSIModuleType;
import com.facebook.react.bridge.ReactContext;
import com.facebook.react.bridge.ReactNoCrashSoftException;
import com.facebook.react.bridge.ReactSoftException;
import com.facebook.react.bridge.UIManager;
import com.facebook.react.uimanager.common.UIManagerType;
@@ -48,7 +49,7 @@ public class UIManagerHelper {
if (!context.hasCatalystInstance()) {
ReactSoftException.logSoftException(
"UIManagerHelper",
new IllegalStateException(
new ReactNoCrashSoftException(
"Cannot get UIManager because the context doesn't contain a CatalystInstance."));
return null;
}
@@ -57,7 +58,7 @@ public class UIManagerHelper {
if (!context.hasActiveCatalystInstance()) {
ReactSoftException.logSoftException(
"UIManagerHelper",
new IllegalStateException(
new ReactNoCrashSoftException(
"Cannot get UIManager because the context doesn't contain an active CatalystInstance."));
if (returnNullIfCatalystIsInactive) {
return null;
@@ -50,6 +50,7 @@ import com.facebook.react.uimanager.ReactStylesDiffMap;
import com.facebook.react.uimanager.Spacing;
import com.facebook.react.uimanager.StateWrapper;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.UIManagerHelper;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.ViewDefaults;
import com.facebook.react.uimanager.ViewProps;
@@ -848,6 +849,11 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
view.setStagedInputType((view.getStagedInputType() & ~flagsToUnset) | flagsToSet);
}
private static EventDispatcher getEventDispatcher(
ReactContext reactContext, ReactEditText editText) {
return UIManagerHelper.getEventDispatcherForReactTag(reactContext, editText.getId());
}
private class ReactTextInputTextWatcher implements TextWatcher {
private EventDispatcher mEventDispatcher;
@@ -856,7 +862,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
public ReactTextInputTextWatcher(
final ReactContext reactContext, final ReactEditText editText) {
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
mEventDispatcher = getEventDispatcher(reactContext, editText);
mEditText = editText;
mPreviousText = null;
}
@@ -994,8 +1000,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
editText.setOnFocusChangeListener(
new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
EventDispatcher eventDispatcher =
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
EventDispatcher eventDispatcher = getEventDispatcher(reactContext, editText);
if (hasFocus) {
eventDispatcher.dispatchEvent(new ReactTextInputFocusEvent(editText.getId()));
} else {
@@ -1025,9 +1030,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
// * !blurOnSubmit && !isMultiline => Prevent default behaviour (return true).
// Additionally we always generate a `submit` event.
EventDispatcher eventDispatcher =
reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
EventDispatcher eventDispatcher = getEventDispatcher(reactContext, editText);
eventDispatcher.dispatchEvent(
new ReactTextInputSubmitEditingEvent(
editText.getId(), editText.getText().toString()));
@@ -1111,7 +1114,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
mReactEditText = editText;
ReactContext reactContext = getReactContext(editText);
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
mEventDispatcher = getEventDispatcher(reactContext, editText);
}
@Override
@@ -1145,7 +1148,7 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
public ReactScrollWatcher(ReactEditText editText) {
mReactEditText = editText;
ReactContext reactContext = getReactContext(editText);
mEventDispatcher = reactContext.getNativeModule(UIManagerModule.class).getEventDispatcher();
mEventDispatcher = getEventDispatcher(reactContext, editText);
}
@Override