Skip to content

Prevent crash when keyboard opens before text input is created #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.facebook.react.bridge.ReadableMapKeySetIterator;
import com.facebook.react.bridge.UiThreadUtil;
import com.facebook.react.bridge.WritableArray;
import com.facebook.react.uimanager.IllegalViewOperationException;
import com.facebook.react.uimanager.RootView;
import com.facebook.react.uimanager.UIManagerModule;
import com.facebook.react.uimanager.UIViewOperationQueue;
Expand All @@ -43,8 +44,20 @@ public RNCustomKeyboardModule(ReactApplicationContext reactContext) {
Handler handle = new Handler(Looper.getMainLooper());

private ReactEditText getEditById(int id) {
UIViewOperationQueue uii = this.getReactApplicationContext().getNativeModule(UIManagerModule.class).getUIImplementation().getUIViewOperationQueue();
return (ReactEditText) uii.getNativeViewHierarchyManager().resolveView(id);
UIViewOperationQueue uii = null;
ReactEditText edit = null;
while (edit == null) {
// we assume the native component will be instantiated at some point, so just
// loop until it appears. Most of the time, the first pass will pick it up.
uii = this.getReactApplicationContext().getNativeModule(UIManagerModule.class).getUIImplementation().getUIViewOperationQueue();
try {
edit = (ReactEditText) uii.getNativeViewHierarchyManager().resolveView(id);
}
catch (IllegalViewOperationException e) {
// do nothing
}
}
return edit;
}

@ReactMethod
Expand Down Expand Up @@ -278,4 +291,4 @@ public void run() {
public String getName() {
return "CustomKeyboard";
}
}
}