@onekeyfe/react-native-text-input 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (101) hide show
  1. package/LICENSE +20 -0
  2. package/README.md +33 -0
  3. package/android/build.gradle +126 -0
  4. package/android/generated/android/app/build/generated/source/codegen/java/com/facebook/react/viewmanagers/OneKeyTextInputManagerDelegate.java +25 -0
  5. package/android/generated/android/app/build/generated/source/codegen/java/com/facebook/react/viewmanagers/OneKeyTextInputManagerInterface.java +16 -0
  6. package/android/generated/android/app/build/generated/source/codegen/jni/CMakeLists.txt +49 -0
  7. package/android/generated/android/app/build/generated/source/codegen/jni/RNTextInputViewSpec-generated.cpp +22 -0
  8. package/android/generated/android/app/build/generated/source/codegen/jni/RNTextInputViewSpec.h +24 -0
  9. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/ComponentDescriptors.cpp +22 -0
  10. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/ComponentDescriptors.h +24 -0
  11. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/EventEmitters.cpp +24 -0
  12. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/EventEmitters.h +25 -0
  13. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/Props.cpp +25 -0
  14. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/Props.h +27 -0
  15. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/RNTextInputViewSpecJSI-generated.cpp +17 -0
  16. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/RNTextInputViewSpecJSI.h +19 -0
  17. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/ShadowNodes.cpp +17 -0
  18. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/ShadowNodes.h +32 -0
  19. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/States.cpp +16 -0
  20. package/android/generated/android/app/build/generated/source/codegen/jni/react/renderer/components/RNTextInputViewSpec/States.h +29 -0
  21. package/android/gradle.properties +5 -0
  22. package/android/src/main/AndroidManifest.xml +3 -0
  23. package/android/src/main/AndroidManifestNew.xml +2 -0
  24. package/android/src/main/java/com/textinput/PasteWatcher.kt +10 -0
  25. package/android/src/main/java/com/textinput/TextInputPackage.kt +19 -0
  26. package/android/src/main/java/com/textinput/TextInputPasteEvent.kt +48 -0
  27. package/android/src/main/java/com/textinput/TextInputView.kt +67 -0
  28. package/android/src/main/java/com/textinput/TextInputViewManager.kt +68 -0
  29. package/android/src/newarch/TextInputViewManagerSpec.kt +21 -0
  30. package/android/src/oldarch/TextInputViewManagerSpec.kt +9 -0
  31. package/ios/TextInputView.h +17 -0
  32. package/ios/TextInputView.mm +60 -0
  33. package/ios/TextInputViewManager.mm +23 -0
  34. package/ios/Utils.h +8 -0
  35. package/ios/Utils.m +26 -0
  36. package/ios/generated/build/generated/ios/FBReactNativeSpec/FBReactNativeSpec-generated.mm +1881 -0
  37. package/ios/generated/build/generated/ios/FBReactNativeSpec/FBReactNativeSpec.h +2321 -0
  38. package/ios/generated/build/generated/ios/FBReactNativeSpecJSI-generated.cpp +2785 -0
  39. package/ios/generated/build/generated/ios/FBReactNativeSpecJSI.h +7511 -0
  40. package/ios/generated/build/generated/ios/RCTModulesConformingToProtocolsProvider.h +18 -0
  41. package/ios/generated/build/generated/ios/RCTModulesConformingToProtocolsProvider.mm +33 -0
  42. package/ios/generated/build/generated/ios/RNTextInputViewSpec/RNTextInputViewSpec-generated.mm +16 -0
  43. package/ios/generated/build/generated/ios/RNTextInputViewSpec/RNTextInputViewSpec.h +35 -0
  44. package/ios/generated/build/generated/ios/RNTextInputViewSpecJSI-generated.cpp +17 -0
  45. package/ios/generated/build/generated/ios/RNTextInputViewSpecJSI.h +19 -0
  46. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/ComponentDescriptors.cpp +22 -0
  47. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/ComponentDescriptors.h +24 -0
  48. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/EventEmitters.cpp +24 -0
  49. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/EventEmitters.h +25 -0
  50. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/Props.cpp +25 -0
  51. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/Props.h +27 -0
  52. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/RCTComponentViewHelpers.h +20 -0
  53. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/ShadowNodes.cpp +17 -0
  54. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/ShadowNodes.h +32 -0
  55. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/States.cpp +16 -0
  56. package/ios/generated/build/generated/ios/react/renderer/components/RNTextInputViewSpec/States.h +29 -0
  57. package/lib/commonjs/Input.js +670 -0
  58. package/lib/commonjs/Input.js.map +1 -0
  59. package/lib/commonjs/TextInputViewNativeComponent.js +10 -0
  60. package/lib/commonjs/TextInputViewNativeComponent.js.map +1 -0
  61. package/lib/commonjs/enum.js +11 -0
  62. package/lib/commonjs/enum.js.map +1 -0
  63. package/lib/commonjs/index.js +38 -0
  64. package/lib/commonjs/index.js.map +1 -0
  65. package/lib/commonjs/type.js +6 -0
  66. package/lib/commonjs/type.js.map +1 -0
  67. package/lib/module/Input.js +667 -0
  68. package/lib/module/Input.js.map +1 -0
  69. package/lib/module/TextInputViewNativeComponent.js +5 -0
  70. package/lib/module/TextInputViewNativeComponent.js.map +1 -0
  71. package/lib/module/enum.js +7 -0
  72. package/lib/module/enum.js.map +1 -0
  73. package/lib/module/index.js +9 -0
  74. package/lib/module/index.js.map +1 -0
  75. package/lib/module/type.js +4 -0
  76. package/lib/module/type.js.map +1 -0
  77. package/lib/typescript/commonjs/package.json +1 -0
  78. package/lib/typescript/commonjs/src/TextInputViewNativeComponent.d.ts +8 -0
  79. package/lib/typescript/commonjs/src/TextInputViewNativeComponent.d.ts.map +1 -0
  80. package/lib/typescript/commonjs/src/enum.d.ts +4 -0
  81. package/lib/typescript/commonjs/src/enum.d.ts.map +1 -0
  82. package/lib/typescript/commonjs/src/index.d.ts +8 -0
  83. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  84. package/lib/typescript/commonjs/src/type.d.ts +16 -0
  85. package/lib/typescript/commonjs/src/type.d.ts.map +1 -0
  86. package/lib/typescript/module/package.json +1 -0
  87. package/lib/typescript/module/src/TextInputViewNativeComponent.d.ts +8 -0
  88. package/lib/typescript/module/src/TextInputViewNativeComponent.d.ts.map +1 -0
  89. package/lib/typescript/module/src/enum.d.ts +4 -0
  90. package/lib/typescript/module/src/enum.d.ts.map +1 -0
  91. package/lib/typescript/module/src/index.d.ts +8 -0
  92. package/lib/typescript/module/src/index.d.ts.map +1 -0
  93. package/lib/typescript/module/src/type.d.ts +16 -0
  94. package/lib/typescript/module/src/type.d.ts.map +1 -0
  95. package/package.json +200 -0
  96. package/react-native-text-input.podspec +42 -0
  97. package/src/Input.js +1739 -0
  98. package/src/TextInputViewNativeComponent.ts +9 -0
  99. package/src/enum.ts +3 -0
  100. package/src/index.tsx +17 -0
  101. package/src/type.ts +13 -0
@@ -0,0 +1,48 @@
1
+ package com.textinput
2
+
3
+ import androidx.annotation.Nullable
4
+ import com.facebook.react.bridge.Arguments
5
+ import com.facebook.react.bridge.WritableMap
6
+ import com.facebook.react.bridge.WritableArray
7
+ import com.facebook.react.uimanager.common.ViewUtil
8
+ import com.facebook.react.uimanager.events.Event
9
+
10
+ /**
11
+ * Event emitted by EditText native view when clipboard content is pasted
12
+ */
13
+ class TextInputPasteEvent : Event<TextInputPasteEvent> {
14
+
15
+ companion object {
16
+ private const val EVENT_NAME = "topPaste"
17
+ }
18
+
19
+ private val mType: String
20
+ private val mData: String
21
+
22
+ @Deprecated("Use the constructor with surfaceId")
23
+ constructor(viewId: Int, type: String, data: String) : this(ViewUtil.NO_SURFACE_ID, viewId, type, data)
24
+
25
+ constructor(surfaceId: Int, viewId: Int, type: String, data: String) : super(surfaceId, viewId) {
26
+ mType = type
27
+ mData = data
28
+ }
29
+
30
+ override fun getEventName(): String = EVENT_NAME
31
+
32
+ override fun canCoalesce(): Boolean = false
33
+
34
+ @Nullable
35
+ override fun getEventData(): WritableMap? {
36
+ val eventData = Arguments.createMap()
37
+
38
+ val items = Arguments.createArray()
39
+ val item = Arguments.createMap()
40
+ item.putString("type", mType)
41
+ item.putString("data", mData)
42
+ items.pushMap(item)
43
+
44
+ eventData.putArray("items", items)
45
+
46
+ return eventData
47
+ }
48
+ }
@@ -0,0 +1,67 @@
1
+ package com.textinput
2
+
3
+ import android.content.ClipData
4
+ import android.content.ClipDescription
5
+ import android.content.ClipboardManager
6
+ import android.content.Context
7
+ import android.os.Build
8
+ import android.text.Spanned
9
+ import androidx.annotation.Nullable
10
+ import com.facebook.react.uimanager.UIManagerHelper
11
+ import com.facebook.react.views.textinput.ReactEditText
12
+ import so.onekey.app.wallet.pasteinput.PasteWatcher
13
+
14
+ class TextInputView(context: Context) : ReactEditText(context) {
15
+
16
+ private var mPasteWatcher: PasteWatcher? = null
17
+
18
+ override fun onTextContextMenuItem(id: Int): Boolean {
19
+ if (id == android.R.id.paste || id == android.R.id.pasteAsPlainText) {
20
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
21
+ val newId = android.R.id.pasteAsPlainText
22
+ mPasteWatcher?.let { pasteWatcher ->
23
+ val clipboardManager = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
24
+ val clipData = clipboardManager.primaryClip
25
+ var type: String? = null
26
+ var data: String? = null
27
+ if (clipData?.description?.hasMimeType(ClipDescription.MIMETYPE_TEXT_PLAIN) == true) {
28
+ type = ClipDescription.MIMETYPE_TEXT_PLAIN
29
+ data = clipData.getItemAt(0).text.toString()
30
+ } else {
31
+ val itemUri = clipData?.getItemAt(0)?.uri
32
+ itemUri?.let {
33
+ val cr = UIManagerHelper.getReactContext(this)?.contentResolver
34
+ type = cr?.getType(it)
35
+ data = it.toString()
36
+ }
37
+ }
38
+ if (type != null && data != null) {
39
+ pasteWatcher.onPaste(type!!, data!!)
40
+ }
41
+ }
42
+ return super.onTextContextMenuItem(newId)
43
+ } else {
44
+ val clipboard = context.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
45
+ val previousClipData = clipboard.primaryClip
46
+ previousClipData?.let {
47
+ for (i in 0 until it.itemCount) {
48
+ val text = it.getItemAt(i).coerceToText(context)
49
+ val paste = if (text is Spanned) text.toString() else text
50
+ paste?.let { pasteText ->
51
+ val clipData = ClipData.newPlainText(null, pasteText)
52
+ clipboard.setPrimaryClip(clipData)
53
+ }
54
+ }
55
+ val actionPerformed = super.onTextContextMenuItem(id)
56
+ clipboard.setPrimaryClip(previousClipData)
57
+ return actionPerformed
58
+ }
59
+ }
60
+ }
61
+ return super.onTextContextMenuItem(id)
62
+ }
63
+
64
+ fun setPasteWatcher(@Nullable pasteWatcher: PasteWatcher?) {
65
+ mPasteWatcher = pasteWatcher
66
+ }
67
+ }
@@ -0,0 +1,68 @@
1
+ package com.textinput
2
+
3
+ import android.text.InputType
4
+ import android.view.ViewGroup
5
+ import com.facebook.react.common.MapBuilder
6
+ import com.facebook.react.module.annotations.ReactModule
7
+ import com.facebook.react.uimanager.ThemedReactContext
8
+ import com.facebook.react.uimanager.UIManagerHelper
9
+ import com.facebook.react.uimanager.annotations.ReactProp
10
+ import com.facebook.react.uimanager.events.EventDispatcher
11
+ import com.facebook.react.views.textinput.ReactEditText
12
+ import com.facebook.react.views.textinput.ReactTextInputManager
13
+ import so.onekey.app.wallet.pasteinput.PasteWatcher
14
+
15
+ @ReactModule(name = ReactTextInputManager.REACT_CLASS)
16
+ class TextInputViewManager() : ReactTextInputManager() {
17
+
18
+ companion object {
19
+ const val REACT_CLASS = "OneKeyTextInput"
20
+ }
21
+
22
+ override fun getName(): String = REACT_CLASS
23
+
24
+ override fun createViewInstance(context: ThemedReactContext): ReactEditText {
25
+ val editText = TextInputView(context)
26
+ val inputType = editText.inputType
27
+ editText.inputType = inputType and InputType.TYPE_TEXT_FLAG_MULTI_LINE.inv()
28
+ editText.returnKeyType = "done"
29
+ editText.layoutParams = ViewGroup.LayoutParams(
30
+ ViewGroup.LayoutParams.WRAP_CONTENT,
31
+ ViewGroup.LayoutParams.WRAP_CONTENT
32
+ )
33
+ return editText
34
+ }
35
+
36
+ override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any>? {
37
+ val baseEventTypeConstants = super.getExportedCustomDirectEventTypeConstants()?.toMutableMap()
38
+ baseEventTypeConstants?.put("topPaste", MapBuilder.of("registrationName", "onPaste"))
39
+ return baseEventTypeConstants
40
+ }
41
+
42
+ @ReactProp(name = "onPaste", defaultBoolean = false)
43
+ fun setOnPaste(view: TextInputView, onPaste: Boolean) {
44
+ if (onPaste) {
45
+ view.setPasteWatcher(ReactPasteWatcher(view))
46
+ } else {
47
+ view.setPasteWatcher(null)
48
+ }
49
+ }
50
+
51
+ private class ReactPasteWatcher(editText: TextInputView) : PasteWatcher {
52
+ private val mReactEditText: TextInputView = editText
53
+ private val mEventDispatcher: EventDispatcher
54
+ private val mSurfaceId: Int
55
+
56
+ init {
57
+ val reactContext = UIManagerHelper.getReactContext(editText)
58
+ mEventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, editText.id)!!
59
+ mSurfaceId = UIManagerHelper.getSurfaceId(reactContext)
60
+ }
61
+
62
+ override fun onPaste(type: String, data: String) {
63
+ mEventDispatcher.dispatchEvent(
64
+ TextInputPasteEvent(mSurfaceId, mReactEditText.id, type, data)
65
+ )
66
+ }
67
+ }
68
+ }
@@ -0,0 +1,21 @@
1
+ package com.textinput
2
+
3
+ import android.view.View
4
+
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.SimpleViewManager
7
+ import com.facebook.react.uimanager.ViewManagerDelegate
8
+ import com.facebook.react.viewmanagers.TextInputViewManagerDelegate
9
+ import com.facebook.react.viewmanagers.TextInputViewManagerInterface
10
+
11
+ abstract class TextInputViewManagerSpec<T : View> : SimpleViewManager<T>(), TextInputViewManagerInterface<T> {
12
+ private val mDelegate: ViewManagerDelegate<T>
13
+
14
+ init {
15
+ mDelegate = TextInputViewManagerDelegate(this)
16
+ }
17
+
18
+ override fun getDelegate(): ViewManagerDelegate<T>? {
19
+ return mDelegate
20
+ }
21
+ }
@@ -0,0 +1,9 @@
1
+ package com.textinput
2
+
3
+ import android.view.View
4
+ import com.facebook.react.bridge.ReactApplicationContext
5
+ import com.facebook.react.uimanager.SimpleViewManager
6
+
7
+ abstract class TextInputViewManagerSpec<T : View> : SimpleViewManager<T>() {
8
+ abstract fun setColor(view: T?, value: String?)
9
+ }
@@ -0,0 +1,17 @@
1
+ // This guard prevent this file to be compiled in the old architecture.
2
+ #ifdef RCT_NEW_ARCH_ENABLED
3
+ #import <React/RCTViewComponentView.h>
4
+ #import <UIKit/UIKit.h>
5
+
6
+ #ifndef TextInputViewNativeComponent_h
7
+ #define TextInputViewNativeComponent_h
8
+
9
+ NS_ASSUME_NONNULL_BEGIN
10
+
11
+ @interface TextInputView : RCTViewComponentView
12
+ @end
13
+
14
+ NS_ASSUME_NONNULL_END
15
+
16
+ #endif /* TextInputViewNativeComponent_h */
17
+ #endif /* RCT_NEW_ARCH_ENABLED */
@@ -0,0 +1,60 @@
1
+ #ifdef RCT_NEW_ARCH_ENABLED
2
+ #import "TextInputView.h"
3
+
4
+ #import <react/renderer/components/RNTextInputViewSpec/ComponentDescriptors.h>
5
+ #import <react/renderer/components/RNTextInputViewSpec/EventEmitters.h>
6
+ #import <react/renderer/components/RNTextInputViewSpec/Props.h>
7
+ #import <react/renderer/components/RNTextInputViewSpec/RCTComponentViewHelpers.h>
8
+
9
+ #import "RCTFabricComponentsPlugins.h"
10
+ #import "Utils.h"
11
+
12
+ using namespace facebook::react;
13
+
14
+ @interface TextInputView () <RCTTextInputViewViewProtocol>
15
+
16
+ @end
17
+
18
+ @implementation TextInputView {
19
+ UIView * _view;
20
+ }
21
+
22
+ + (ComponentDescriptorProvider)componentDescriptorProvider
23
+ {
24
+ return concreteComponentDescriptorProvider<TextInputViewComponentDescriptor>();
25
+ }
26
+
27
+ - (instancetype)initWithFrame:(CGRect)frame
28
+ {
29
+ if (self = [super initWithFrame:frame]) {
30
+ static const auto defaultProps = std::make_shared<const TextInputViewProps>();
31
+ _props = defaultProps;
32
+
33
+ _view = [[UIView alloc] init];
34
+
35
+ self.contentView = _view;
36
+ }
37
+
38
+ return self;
39
+ }
40
+
41
+ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &)oldProps
42
+ {
43
+ const auto &oldViewProps = *std::static_pointer_cast<TextInputViewProps const>(_props);
44
+ const auto &newViewProps = *std::static_pointer_cast<TextInputViewProps const>(props);
45
+
46
+ if (oldViewProps.color != newViewProps.color) {
47
+ NSString * colorToConvert = [[NSString alloc] initWithUTF8String: newViewProps.color.c_str()];
48
+ [_view setBackgroundColor: [Utils hexStringToColor:colorToConvert]];
49
+ }
50
+
51
+ [super updateProps:props oldProps:oldProps];
52
+ }
53
+
54
+ Class<RCTComponentViewProtocol> TextInputViewCls(void)
55
+ {
56
+ return TextInputView.class;
57
+ }
58
+
59
+ @end
60
+ #endif
@@ -0,0 +1,23 @@
1
+ #import <React/RCTViewManager.h>
2
+ #import <React/RCTUIManager.h>
3
+ #import "RCTBridge.h"
4
+ #import "Utils.h"
5
+
6
+ @interface TextInputViewManager : RCTViewManager
7
+ @end
8
+
9
+ @implementation TextInputViewManager
10
+
11
+ RCT_EXPORT_MODULE(TextInputView)
12
+
13
+ - (UIView *)view
14
+ {
15
+ return [[UIView alloc] init];
16
+ }
17
+
18
+ RCT_CUSTOM_VIEW_PROPERTY(color, NSString, UIView)
19
+ {
20
+ [view setBackgroundColor: [Utils hexStringToColor:json]];
21
+ }
22
+
23
+ @end
package/ios/Utils.h ADDED
@@ -0,0 +1,8 @@
1
+ #ifndef Utils_h
2
+ #define Utils_h
3
+
4
+ @interface Utils : NSObject
5
+ + hexStringToColor:(NSString *)stringToConvert;
6
+ @end
7
+
8
+ #endif /* Utils_h */
package/ios/Utils.m ADDED
@@ -0,0 +1,26 @@
1
+ #import <Foundation/Foundation.h>
2
+ #import "Utils.h"
3
+ #import <UIKit/UIKit.h>
4
+
5
+ @implementation Utils
6
+
7
+ + hexStringToColor:(NSString *)stringToConvert
8
+ {
9
+ NSString *noHashString = [stringToConvert stringByReplacingOccurrencesOfString:@"#" withString:@""];
10
+ NSScanner *stringScanner = [NSScanner scannerWithString:noHashString];
11
+
12
+ unsigned hex;
13
+ if (![stringScanner scanHexInt:&hex]) return nil;
14
+ int r = (hex >> 16) & 0xFF;
15
+ int g = (hex >> 8) & 0xFF;
16
+ int b = (hex) & 0xFF;
17
+
18
+ return [UIColor colorWithRed:r / 255.0f green:g / 255.0f blue:b / 255.0f alpha:1.0f];
19
+ }
20
+
21
+ + (id)alloc {
22
+ [NSException raise:@"Cannot be instantiated!" format:@"Static class 'Utils' cannot be instantiated!"];
23
+ return nil;
24
+ }
25
+
26
+ @end