@onekeyfe/react-native-text-input 3.0.91 → 3.0.93

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.
@@ -7,7 +7,6 @@ import com.facebook.react.module.annotations.ReactModule
7
7
  import com.facebook.react.uimanager.ThemedReactContext
8
8
  import com.facebook.react.uimanager.UIManagerHelper
9
9
  import com.facebook.react.uimanager.annotations.ReactProp
10
- import com.facebook.react.uimanager.events.EventDispatcher
11
10
  import com.facebook.react.views.textinput.ReactEditText
12
11
  import com.facebook.react.views.textinput.ReactTextInputManager
13
12
  import so.onekey.app.wallet.pasteinput.PasteWatcher
@@ -53,19 +52,20 @@ class TextInputViewManager : ReactTextInputManager() {
53
52
 
54
53
  private class ReactPasteWatcher(editText: TextInputView) : PasteWatcher {
55
54
  private val mReactEditText: TextInputView = editText
56
- private val mEventDispatcher: EventDispatcher
57
- private val mSurfaceId: Int
58
-
59
- init {
60
- val reactContext = UIManagerHelper.getReactContext(editText)
61
- mEventDispatcher =
62
- UIManagerHelper.getEventDispatcherForReactTag(reactContext, editText.id)!!
63
- mSurfaceId = UIManagerHelper.getSurfaceId(reactContext)
64
- }
65
55
 
66
56
  override fun onPaste(type: String, data: String) {
67
- mEventDispatcher.dispatchEvent(
68
- TextInputPasteEvent(mSurfaceId, mReactEditText.id, type, data)
57
+ val reactContext = UIManagerHelper.getReactContext(mReactEditText) ?: return
58
+ val eventDispatcher =
59
+ UIManagerHelper.getEventDispatcherForReactTag(reactContext, mReactEditText.id)
60
+ ?: return
61
+
62
+ eventDispatcher.dispatchEvent(
63
+ TextInputPasteEvent(
64
+ UIManagerHelper.getSurfaceId(reactContext),
65
+ mReactEditText.id,
66
+ type,
67
+ data
68
+ )
69
69
  )
70
70
  }
71
71
  }
@@ -0,0 +1,35 @@
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ #
3
+ # This source code is licensed under the MIT license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ cmake_minimum_required(VERSION 3.13)
7
+ set(CMAKE_VERBOSE_MAKEFILE ON)
8
+
9
+ set(LIB_TARGET_NAME react_codegen_RNTextInputViewSpec)
10
+ set(LIB_ANDROID_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..)
11
+ set(LIB_GENERATED_JNI_DIR ${LIB_ANDROID_DIR}/build/generated/source/codegen/jni)
12
+
13
+ file(GLOB LIB_CODEGEN_SRCS CONFIGURE_DEPENDS ${LIB_GENERATED_JNI_DIR}/*.cpp)
14
+
15
+ add_library(
16
+ ${LIB_TARGET_NAME}
17
+ SHARED
18
+ ${LIB_CODEGEN_SRCS}
19
+ )
20
+
21
+ target_include_directories(
22
+ ${LIB_TARGET_NAME}
23
+ PUBLIC
24
+ .
25
+ ${LIB_GENERATED_JNI_DIR}
26
+ )
27
+
28
+ target_link_libraries(
29
+ ${LIB_TARGET_NAME}
30
+ fbjni
31
+ jsi
32
+ reactnative
33
+ )
34
+
35
+ target_compile_reactnative_options(${LIB_TARGET_NAME} PRIVATE)
@@ -0,0 +1,174 @@
1
+ /*
2
+ * Copyright (c) Meta Platforms, Inc. and affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+
12
+ #include <react/renderer/components/androidtextinput/AndroidTextInputShadowNode.h>
13
+ #include <react/renderer/components/androidtextinput/AndroidTextInputState.h>
14
+ #include <react/renderer/componentregistry/ComponentDescriptorProviderRegistry.h>
15
+ #include <react/renderer/core/ConcreteComponentDescriptor.h>
16
+
17
+ #include <yoga/YGEnums.h>
18
+ #include <yoga/YGValue.h>
19
+
20
+ #include <unordered_map>
21
+
22
+ namespace facebook::react {
23
+
24
+ class OneKeyTextInputComponentDescriptor final
25
+ : public ConcreteComponentDescriptor<AndroidTextInputShadowNode> {
26
+ using Base = ConcreteComponentDescriptor<AndroidTextInputShadowNode>;
27
+
28
+ public:
29
+ struct ConcreteShadowNode {
30
+ inline static constexpr char NameValue[] = "OneKeyTextInput";
31
+
32
+ static ComponentHandle Handle() {
33
+ return ComponentHandle(NameValue);
34
+ }
35
+
36
+ static ComponentName Name() {
37
+ return NameValue;
38
+ }
39
+ };
40
+
41
+ explicit OneKeyTextInputComponentDescriptor(
42
+ const ComponentDescriptorParameters &parameters)
43
+ : Base(parameters),
44
+ textLayoutManager_(
45
+ std::make_shared<TextLayoutManager>(contextContainer_)) {}
46
+
47
+ ComponentHandle getComponentHandle() const override {
48
+ return ConcreteShadowNode::Handle();
49
+ }
50
+
51
+ ComponentName getComponentName() const override {
52
+ return ConcreteShadowNode::Name();
53
+ }
54
+
55
+ State::Shared createInitialState(
56
+ const Props::Shared &props,
57
+ const ShadowNodeFamily::Shared &family) const override {
58
+ const auto surfaceId = family->getSurfaceId();
59
+
60
+ ThemePadding theme;
61
+ if (surfaceIdToThemePaddingMap_.find(surfaceId) !=
62
+ surfaceIdToThemePaddingMap_.end()) {
63
+ theme = surfaceIdToThemePaddingMap_[surfaceId];
64
+ } else {
65
+ const jni::global_ref<jobject> &fabricUIManager =
66
+ contextContainer_->at<jni::global_ref<jobject>>("FabricUIManager");
67
+
68
+ auto env = jni::Environment::current();
69
+ auto defaultTextInputPaddingArray = env->NewFloatArray(4);
70
+ static auto getThemeData = jni::findClassStatic(UIManagerJavaDescriptor)
71
+ ->getMethod<jboolean(jint, jfloatArray)>(
72
+ "getThemeData");
73
+
74
+ if (getThemeData(
75
+ fabricUIManager, surfaceId, defaultTextInputPaddingArray) != 0u) {
76
+ auto defaultTextInputPadding = env->GetFloatArrayElements(
77
+ defaultTextInputPaddingArray, nullptr);
78
+ theme.start = defaultTextInputPadding[0];
79
+ theme.end = defaultTextInputPadding[1];
80
+ theme.top = defaultTextInputPadding[2];
81
+ theme.bottom = defaultTextInputPadding[3];
82
+ surfaceIdToThemePaddingMap_.emplace(surfaceId, theme);
83
+ env->ReleaseFloatArrayElements(
84
+ defaultTextInputPaddingArray,
85
+ defaultTextInputPadding,
86
+ JNI_ABORT);
87
+ }
88
+ env->DeleteLocalRef(defaultTextInputPaddingArray);
89
+ }
90
+
91
+ return std::make_shared<AndroidTextInputShadowNode::ConcreteState>(
92
+ std::make_shared<const AndroidTextInputState>(
93
+ AndroidTextInputState({}, {}, {}, 0)),
94
+ family);
95
+ }
96
+
97
+ protected:
98
+ void adopt(ShadowNode &shadowNode) const override {
99
+ auto &textInputShadowNode =
100
+ static_cast<AndroidTextInputShadowNode &>(shadowNode);
101
+ textInputShadowNode.setTextLayoutManager(textLayoutManager_);
102
+
103
+ const auto surfaceId = textInputShadowNode.getSurfaceId();
104
+ if (surfaceIdToThemePaddingMap_.find(surfaceId) !=
105
+ surfaceIdToThemePaddingMap_.end()) {
106
+ const auto &theme = surfaceIdToThemePaddingMap_[surfaceId];
107
+ const auto &textInputProps = textInputShadowNode.getConcreteProps();
108
+ auto &style = const_cast<yoga::Style &>(textInputProps.yogaStyle);
109
+ auto changedPadding = false;
110
+
111
+ if (!textInputProps.hasPadding && !textInputProps.hasPaddingStart &&
112
+ !textInputProps.hasPaddingLeft &&
113
+ !textInputProps.hasPaddingHorizontal) {
114
+ changedPadding = true;
115
+ style.setPadding(
116
+ yoga::Edge::Start, yoga::StyleLength::points(theme.start));
117
+ }
118
+ if (!textInputProps.hasPadding && !textInputProps.hasPaddingEnd &&
119
+ !textInputProps.hasPaddingRight &&
120
+ !textInputProps.hasPaddingHorizontal) {
121
+ changedPadding = true;
122
+ style.setPadding(
123
+ yoga::Edge::End, yoga::StyleLength::points(theme.end));
124
+ }
125
+ if (!textInputProps.hasPadding && !textInputProps.hasPaddingTop &&
126
+ !textInputProps.hasPaddingVertical) {
127
+ changedPadding = true;
128
+ style.setPadding(
129
+ yoga::Edge::Top, yoga::StyleLength::points(theme.top));
130
+ }
131
+ if (!textInputProps.hasPadding && !textInputProps.hasPaddingBottom &&
132
+ !textInputProps.hasPaddingVertical) {
133
+ changedPadding = true;
134
+ style.setPadding(
135
+ yoga::Edge::Bottom, yoga::StyleLength::points(theme.bottom));
136
+ }
137
+
138
+ if ((textInputProps.hasPadding || textInputProps.hasPaddingLeft ||
139
+ textInputProps.hasPaddingHorizontal) &&
140
+ !textInputProps.hasPaddingStart) {
141
+ style.setPadding(yoga::Edge::Start, yoga::StyleLength::undefined());
142
+ }
143
+ if ((textInputProps.hasPadding || textInputProps.hasPaddingRight ||
144
+ textInputProps.hasPaddingHorizontal) &&
145
+ !textInputProps.hasPaddingEnd) {
146
+ style.setPadding(yoga::Edge::End, yoga::StyleLength::undefined());
147
+ }
148
+
149
+ if (changedPadding) {
150
+ textInputShadowNode.updateYogaProps();
151
+ }
152
+ }
153
+
154
+ textInputShadowNode.dirtyLayout();
155
+ Base::adopt(shadowNode);
156
+ }
157
+
158
+ private:
159
+ struct ThemePadding {
160
+ float start{};
161
+ float end{};
162
+ float top{};
163
+ float bottom{};
164
+ };
165
+
166
+ inline static constexpr auto UIManagerJavaDescriptor =
167
+ "com/facebook/react/fabric/FabricUIManager";
168
+
169
+ const std::shared_ptr<TextLayoutManager> textLayoutManager_;
170
+ mutable std::unordered_map<int, ThemePadding>
171
+ surfaceIdToThemePaddingMap_;
172
+ };
173
+
174
+ } // namespace facebook::react
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-text-input",
3
- "version": "3.0.91",
3
+ "version": "3.0.93",
4
4
  "description": "React Native TextInput with native paste events",
5
5
  "source": "./src/index.tsx",
6
6
  "main": "./lib/module/index.js",
@@ -5,7 +5,8 @@ module.exports = {
5
5
  dependency: {
6
6
  platforms: {
7
7
  android: {
8
- cmakeListsPath: "build/generated/source/codegen/jni/CMakeLists.txt",
8
+ cmakeListsPath: "src/main/jni/CMakeLists.txt",
9
+ componentDescriptors: ["OneKeyTextInputComponentDescriptor"],
9
10
  },
10
11
  },
11
12
  },