Gustash / react-native-image-keyboard

React Native TextInput expansion to enable media input.
MIT License
147 stars 14 forks source link

Fix crash caused by attempting to wrap a null input connection #2

Closed brkastner closed 4 years ago

brkastner commented 4 years ago

If the input connection returned by super.onCreateInputConnection(outAttrs) is null, attempts to create a compatibility wrapper around it will cause the following crash:

java.lang.IllegalArgumentException: inputConnection must be non-null
    at androidx.core.view.inputmethod.InputConnectionCompat.createWrapper(InputConnectionCompat.java:261)
    at com.rnimagekeyboard.ReactMediaInputManager$1.onCreateInputConnection(ReactMediaInputManager.java:193)
    at android.view.inputmethod.InputMethodManager.startInputInner(InputMethodManager.java:1197)
    at android.view.inputmethod.InputMethodManager.restartInput(InputMethodManager.java:1139)
    at android.widget.TextView.setText(TextView.java:4651)
    at android.widget.TextView.setText(TextView.java:4588)
    at android.widget.EditText.setText(EditText.java:89)
    at android.widget.TextView.setText(TextView.java:4543)
    at com.facebook.react.views.textinput.ReactEditText.maybeSetText(ReactEditText.java:426)
    at com.facebook.react.views.textinput.ReactTextInputManager.updateExtraData(ReactTextInputManager.java:213)
    at com.facebook.react.views.textinput.ReactTextInputManager.updateExtraData(ReactTextInputManager.java:59)
    at com.facebook.react.uimanager.NativeViewHierarchyManager.updateViewExtraData(NativeViewHierarchyManager.java:157)
    at com.facebook.react.uimanager.UIViewOperationQueue$UpdateViewExtraData.execute(UIViewOperationQueue.java:236)
    at com.facebook.react.uimanager.UIViewOperationQueue$1.run(UIViewOperationQueue.java:779)
    at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches(UIViewOperationQueue.java:888)
    at com.facebook.react.uimanager.UIViewOperationQueue.access$2200(UIViewOperationQueue.java:42)
    at com.facebook.react.uimanager.UIViewOperationQueue$DispatchUIFrameCallback.doFrameGuarded(UIViewOperationQueue.java:948)
    at com.facebook.react.uimanager.GuardedFrameCallback.doFrame(GuardedFrameCallback.java:28)
    at com.facebook.react.modules.core.ReactChoreographer$ReactChoreographerDispatcher.doFrame(ReactChoreographer.java:174)
    at com.facebook.react.modules.core.ChoreographerCompat$FrameCallback$1.doFrame(ChoreographerCompat.java:84)
    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:869)
    at android.view.Choreographer.doCallbacks(Choreographer.java:683)
    at android.view.Choreographer.doFrame(Choreographer.java:616)
    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:857)
    at android.os.Handler.handleCallback(Handler.java:751)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6247)
    at java.lang.reflect.Method.invoke(Method.java)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:872)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:762)

I also updated the check performed before requesting permissions to match the open PR this project was based on and bumped this project's version to v1.1.1!

brkastner commented 4 years ago

@Gustash Honestly I have no idea lol, I haven't really done much development on native RN modules.

I used this library to add GIF support to react-native-gifted-chat in my app's chat screen. For whatever reason though, using this library without my changes resulted in the app crashing on Android whenever the login form was submitted, even though they barely share any code.

Anyways the good news is after switching to my forked version 2 weeks ago, the crashes have completely disappeared!

Gustash commented 4 years ago

@brkastner Just as an aside, the GIFs still work with your changes on gifted chat?

Gustash commented 4 years ago

@brkastner I'll do a release tomorrow on NPM and notify you here when I do

brkastner commented 4 years ago

@Gustash yep everything is working as expected now!

Gustash commented 4 years ago

@brkastner this has been released as v1.1.1 on NPM