-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add react native 69+ support (old arch) (#11)
- Loading branch information
Showing
39 changed files
with
23,072 additions
and
21,739 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
android/src/reactNative69/java/com/mattermost/pasteinput/PasteInputEditText.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package com.mattermost.pasteinput | ||
|
||
import android.os.Build | ||
import android.view.inputmethod.EditorInfo | ||
import android.view.inputmethod.InputConnection | ||
import androidx.core.view.inputmethod.EditorInfoCompat | ||
import androidx.core.view.inputmethod.InputConnectionCompat | ||
import com.facebook.react.uimanager.ThemedReactContext | ||
import com.facebook.react.views.textinput.ReactEditText | ||
import java.lang.Exception | ||
|
||
|
||
class PasteInputEditText(context: ThemedReactContext) : ReactEditText(context) { | ||
private lateinit var mOnPasteListener: IPasteInputListener | ||
|
||
fun setOnPasteListener(listener: IPasteInputListener) { | ||
mOnPasteListener = listener | ||
} | ||
|
||
fun getOnPasteListener() : IPasteInputListener { | ||
return mOnPasteListener | ||
} | ||
|
||
override fun onCreateInputConnection(outAttrs: EditorInfo): InputConnection? { | ||
val ic = super.onCreateInputConnection(outAttrs) | ||
if (ic == null) { | ||
return null | ||
} | ||
|
||
EditorInfoCompat.setContentMimeTypes(outAttrs, arrayOf<String>("*/*")) | ||
|
||
val callback = InputConnectionCompat.OnCommitContentListener { inputContentInfo, flags, opts -> | ||
val lacksPermission = (flags and InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0 | ||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1 && lacksPermission) { | ||
try { | ||
inputContentInfo.requestPermission() | ||
} catch (e: Exception) { | ||
return@OnCommitContentListener false | ||
} | ||
} | ||
|
||
getOnPasteListener().onPaste(inputContentInfo.contentUri) | ||
|
||
true | ||
} | ||
|
||
return InputConnectionCompat.createWrapper(ic, outAttrs, callback) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.