react-native-enriched 0.2.0 → 0.3.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.
- package/README.md +16 -17
- package/android/build.gradle +77 -72
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +21 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +7 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.cpp +156 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.h +147 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/Props.cpp +10 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/Props.h +194 -0
- package/android/lint.gradle +70 -0
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputConnectionWrapper.kt +140 -0
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt +304 -83
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewLayoutManager.kt +3 -1
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt +166 -51
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewPackage.kt +1 -3
- package/android/src/main/java/com/swmansion/enriched/MeasurementStore.kt +70 -21
- package/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt +21 -11
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeHtmlEvent.kt +8 -9
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeSelectionEvent.kt +10 -9
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeStateDeprecatedEvent.kt +21 -0
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeStateEvent.kt +9 -12
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeTextEvent.kt +10 -10
- package/android/src/main/java/com/swmansion/enriched/events/OnInputBlurEvent.kt +7 -9
- package/android/src/main/java/com/swmansion/enriched/events/OnInputFocusEvent.kt +7 -9
- package/android/src/main/java/com/swmansion/enriched/events/OnInputKeyPressEvent.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/events/OnLinkDetectedEvent.kt +13 -11
- package/android/src/main/java/com/swmansion/enriched/events/OnMentionDetectedEvent.kt +10 -9
- package/android/src/main/java/com/swmansion/enriched/events/OnMentionEvent.kt +9 -8
- package/android/src/main/java/com/swmansion/enriched/events/OnRequestHtmlResultEvent.kt +32 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBlockQuoteSpan.kt +24 -5
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedCodeBlockSpan.kt +10 -2
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH4Span.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH5Span.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH6Span.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedImageSpan.kt +34 -17
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedInlineCodeSpan.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt +7 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt +10 -4
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedMentionSpan.kt +14 -11
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedOrderedListSpan.kt +18 -11
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedSpans.kt +174 -72
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt +7 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt +7 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnorderedListSpan.kt +11 -5
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedBlockSpan.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedHeadingSpan.kt +1 -2
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedInlineSpan.kt +1 -2
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedParagraphSpan.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedZeroWidthSpaceSpan.kt +1 -2
- package/android/src/main/java/com/swmansion/enriched/spans/utils/ForceRedrawSpan.kt +2 -1
- package/android/src/main/java/com/swmansion/enriched/styles/HtmlStyle.kt +155 -20
- package/android/src/main/java/com/swmansion/enriched/styles/InlineStyles.kt +25 -8
- package/android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt +60 -20
- package/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt +161 -25
- package/android/src/main/java/com/swmansion/enriched/styles/ParametrizedStyles.kt +128 -52
- package/android/src/main/java/com/swmansion/enriched/utils/AsyncDrawable.kt +10 -7
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedConstants.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedEditableFactory.kt +17 -0
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedParser.java +136 -87
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSelection.kt +71 -42
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpanState.kt +183 -48
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpannable.kt +82 -0
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpannableStringBuilder.kt +15 -0
- package/android/src/main/java/com/swmansion/enriched/utils/Utils.kt +0 -70
- package/android/src/main/java/com/swmansion/enriched/watchers/EnrichedSpanWatcher.kt +46 -14
- package/android/src/main/java/com/swmansion/enriched/watchers/EnrichedTextWatcher.kt +34 -11
- package/android/src/main/new_arch/CMakeLists.txt +6 -0
- package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp +6 -6
- package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.h +6 -6
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputComponentDescriptor.h +19 -19
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.cpp +40 -51
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.h +13 -15
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.cpp +23 -21
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.h +35 -36
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.cpp +4 -4
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.h +13 -14
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/conversions.h +33 -14
- package/ios/EnrichedTextInputView.h +26 -14
- package/ios/EnrichedTextInputView.mm +1209 -586
- package/ios/config/InputConfig.h +24 -6
- package/ios/config/InputConfig.mm +154 -38
- package/ios/{utils → extensions}/ColorExtension.mm +7 -5
- package/ios/extensions/FontExtension.mm +106 -0
- package/ios/{utils → extensions}/LayoutManagerExtension.h +1 -1
- package/ios/extensions/LayoutManagerExtension.mm +396 -0
- package/ios/{utils → extensions}/StringExtension.mm +19 -16
- package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.cpp +156 -0
- package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.h +147 -0
- package/ios/generated/RNEnrichedTextInputViewSpec/Props.cpp +10 -0
- package/ios/generated/RNEnrichedTextInputViewSpec/Props.h +194 -0
- package/ios/generated/RNEnrichedTextInputViewSpec/RCTComponentViewHelpers.h +95 -0
- package/ios/inputParser/InputParser.h +5 -5
- package/ios/inputParser/InputParser.mm +864 -380
- package/ios/inputTextView/InputTextView.h +1 -1
- package/ios/inputTextView/InputTextView.mm +100 -59
- package/ios/{utils → interfaces}/BaseStyleProtocol.h +2 -2
- package/ios/interfaces/ImageAttachment.h +10 -0
- package/ios/interfaces/ImageAttachment.mm +36 -0
- package/ios/interfaces/LinkRegexConfig.h +19 -0
- package/ios/interfaces/LinkRegexConfig.mm +37 -0
- package/ios/interfaces/MediaAttachment.h +23 -0
- package/ios/interfaces/MediaAttachment.mm +31 -0
- package/ios/{utils → interfaces}/MentionParams.h +0 -1
- package/ios/{utils → interfaces}/MentionStyleProps.mm +27 -20
- package/ios/{utils → interfaces}/StyleHeaders.h +37 -15
- package/ios/{utils → interfaces}/StyleTypeEnum.h +3 -0
- package/ios/internals/EnrichedTextInputViewComponentDescriptor.h +11 -9
- package/ios/internals/EnrichedTextInputViewShadowNode.h +28 -25
- package/ios/internals/EnrichedTextInputViewShadowNode.mm +45 -40
- package/ios/internals/EnrichedTextInputViewState.h +3 -1
- package/ios/styles/BlockQuoteStyle.mm +189 -118
- package/ios/styles/BoldStyle.mm +110 -63
- package/ios/styles/CodeBlockStyle.mm +204 -128
- package/ios/styles/H1Style.mm +10 -4
- package/ios/styles/H2Style.mm +10 -4
- package/ios/styles/H3Style.mm +10 -4
- package/ios/styles/H4Style.mm +17 -0
- package/ios/styles/H5Style.mm +17 -0
- package/ios/styles/H6Style.mm +17 -0
- package/ios/styles/HeadingStyleBase.mm +148 -86
- package/ios/styles/ImageStyle.mm +75 -73
- package/ios/styles/InlineCodeStyle.mm +162 -88
- package/ios/styles/ItalicStyle.mm +76 -52
- package/ios/styles/LinkStyle.mm +411 -232
- package/ios/styles/MentionStyle.mm +363 -246
- package/ios/styles/OrderedListStyle.mm +171 -106
- package/ios/styles/StrikethroughStyle.mm +52 -35
- package/ios/styles/UnderlineStyle.mm +68 -46
- package/ios/styles/UnorderedListStyle.mm +169 -106
- package/ios/utils/OccurenceUtils.h +42 -42
- package/ios/utils/OccurenceUtils.mm +142 -119
- package/ios/utils/ParagraphAttributesUtils.h +10 -2
- package/ios/utils/ParagraphAttributesUtils.mm +182 -71
- package/ios/utils/ParagraphsUtils.h +2 -1
- package/ios/utils/ParagraphsUtils.mm +41 -27
- package/ios/utils/TextInsertionUtils.h +13 -2
- package/ios/utils/TextInsertionUtils.mm +38 -20
- package/ios/utils/WordsUtils.h +2 -1
- package/ios/utils/WordsUtils.mm +32 -22
- package/ios/utils/ZeroWidthSpaceUtils.h +3 -1
- package/ios/utils/ZeroWidthSpaceUtils.mm +145 -79
- package/lib/module/EnrichedTextInput.js +61 -2
- package/lib/module/EnrichedTextInput.js.map +1 -1
- package/lib/module/EnrichedTextInputNativeComponent.ts +149 -12
- package/lib/module/{normalizeHtmlStyle.js → utils/normalizeHtmlStyle.js} +12 -0
- package/lib/module/utils/normalizeHtmlStyle.js.map +1 -0
- package/lib/module/utils/regexParser.js +46 -0
- package/lib/module/utils/regexParser.js.map +1 -0
- package/lib/typescript/src/EnrichedTextInput.d.ts +24 -14
- package/lib/typescript/src/EnrichedTextInput.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts +129 -12
- package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts +4 -0
- package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts.map +1 -0
- package/lib/typescript/src/utils/regexParser.d.ts +3 -0
- package/lib/typescript/src/utils/regexParser.d.ts.map +1 -0
- package/package.json +17 -6
- package/src/EnrichedTextInput.tsx +96 -13
- package/src/EnrichedTextInputNativeComponent.ts +149 -12
- package/src/index.tsx +2 -0
- package/src/{normalizeHtmlStyle.ts → utils/normalizeHtmlStyle.ts} +14 -2
- package/src/utils/regexParser.ts +56 -0
- package/ios/utils/FontExtension.mm +0 -91
- package/ios/utils/LayoutManagerExtension.mm +0 -286
- package/lib/module/normalizeHtmlStyle.js.map +0 -1
- package/lib/typescript/src/normalizeHtmlStyle.d.ts +0 -4
- package/lib/typescript/src/normalizeHtmlStyle.d.ts.map +0 -1
- package/ios/{utils → extensions}/ColorExtension.h +0 -0
- package/ios/{utils → extensions}/FontExtension.h +0 -0
- package/ios/{utils → extensions}/StringExtension.h +1 -1
- package/ios/{utils → interfaces}/ImageData.h +0 -0
- package/ios/{utils → interfaces}/ImageData.mm +0 -0
- package/ios/{utils → interfaces}/LinkData.h +0 -0
- package/ios/{utils → interfaces}/LinkData.mm +0 -0
- package/ios/{utils → interfaces}/MentionParams.mm +0 -0
- package/ios/{utils → interfaces}/MentionStyleProps.h +1 -1
- /package/ios/{utils → interfaces}/StylePair.h +0 -0
- /package/ios/{utils → interfaces}/StylePair.mm +0 -0
- /package/ios/{utils → interfaces}/TextDecorationLineEnum.h +0 -0
- /package/ios/{utils → interfaces}/TextDecorationLineEnum.mm +0 -0
package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.h
CHANGED
|
@@ -33,7 +33,136 @@ class EnrichedTextInputViewEventEmitter : public ViewEventEmitter {
|
|
|
33
33
|
std::string value;
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
+
struct OnChangeStateBold {
|
|
37
|
+
bool isActive;
|
|
38
|
+
bool isConflicting;
|
|
39
|
+
bool isBlocking;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
struct OnChangeStateItalic {
|
|
43
|
+
bool isActive;
|
|
44
|
+
bool isConflicting;
|
|
45
|
+
bool isBlocking;
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
struct OnChangeStateUnderline {
|
|
49
|
+
bool isActive;
|
|
50
|
+
bool isConflicting;
|
|
51
|
+
bool isBlocking;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
struct OnChangeStateStrikeThrough {
|
|
55
|
+
bool isActive;
|
|
56
|
+
bool isConflicting;
|
|
57
|
+
bool isBlocking;
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
struct OnChangeStateInlineCode {
|
|
61
|
+
bool isActive;
|
|
62
|
+
bool isConflicting;
|
|
63
|
+
bool isBlocking;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
struct OnChangeStateH1 {
|
|
67
|
+
bool isActive;
|
|
68
|
+
bool isConflicting;
|
|
69
|
+
bool isBlocking;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
struct OnChangeStateH2 {
|
|
73
|
+
bool isActive;
|
|
74
|
+
bool isConflicting;
|
|
75
|
+
bool isBlocking;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
struct OnChangeStateH3 {
|
|
79
|
+
bool isActive;
|
|
80
|
+
bool isConflicting;
|
|
81
|
+
bool isBlocking;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
struct OnChangeStateH4 {
|
|
85
|
+
bool isActive;
|
|
86
|
+
bool isConflicting;
|
|
87
|
+
bool isBlocking;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
struct OnChangeStateH5 {
|
|
91
|
+
bool isActive;
|
|
92
|
+
bool isConflicting;
|
|
93
|
+
bool isBlocking;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
struct OnChangeStateH6 {
|
|
97
|
+
bool isActive;
|
|
98
|
+
bool isConflicting;
|
|
99
|
+
bool isBlocking;
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
struct OnChangeStateCodeBlock {
|
|
103
|
+
bool isActive;
|
|
104
|
+
bool isConflicting;
|
|
105
|
+
bool isBlocking;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
struct OnChangeStateBlockQuote {
|
|
109
|
+
bool isActive;
|
|
110
|
+
bool isConflicting;
|
|
111
|
+
bool isBlocking;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
struct OnChangeStateOrderedList {
|
|
115
|
+
bool isActive;
|
|
116
|
+
bool isConflicting;
|
|
117
|
+
bool isBlocking;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
struct OnChangeStateUnorderedList {
|
|
121
|
+
bool isActive;
|
|
122
|
+
bool isConflicting;
|
|
123
|
+
bool isBlocking;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
struct OnChangeStateLink {
|
|
127
|
+
bool isActive;
|
|
128
|
+
bool isConflicting;
|
|
129
|
+
bool isBlocking;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
struct OnChangeStateImage {
|
|
133
|
+
bool isActive;
|
|
134
|
+
bool isConflicting;
|
|
135
|
+
bool isBlocking;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
struct OnChangeStateMention {
|
|
139
|
+
bool isActive;
|
|
140
|
+
bool isConflicting;
|
|
141
|
+
bool isBlocking;
|
|
142
|
+
};
|
|
143
|
+
|
|
36
144
|
struct OnChangeState {
|
|
145
|
+
OnChangeStateBold bold;
|
|
146
|
+
OnChangeStateItalic italic;
|
|
147
|
+
OnChangeStateUnderline underline;
|
|
148
|
+
OnChangeStateStrikeThrough strikeThrough;
|
|
149
|
+
OnChangeStateInlineCode inlineCode;
|
|
150
|
+
OnChangeStateH1 h1;
|
|
151
|
+
OnChangeStateH2 h2;
|
|
152
|
+
OnChangeStateH3 h3;
|
|
153
|
+
OnChangeStateH4 h4;
|
|
154
|
+
OnChangeStateH5 h5;
|
|
155
|
+
OnChangeStateH6 h6;
|
|
156
|
+
OnChangeStateCodeBlock codeBlock;
|
|
157
|
+
OnChangeStateBlockQuote blockQuote;
|
|
158
|
+
OnChangeStateOrderedList orderedList;
|
|
159
|
+
OnChangeStateUnorderedList unorderedList;
|
|
160
|
+
OnChangeStateLink link;
|
|
161
|
+
OnChangeStateImage image;
|
|
162
|
+
OnChangeStateMention mention;
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
struct OnChangeStateDeprecated {
|
|
37
166
|
bool isBold;
|
|
38
167
|
bool isItalic;
|
|
39
168
|
bool isUnderline;
|
|
@@ -42,6 +171,9 @@ class EnrichedTextInputViewEventEmitter : public ViewEventEmitter {
|
|
|
42
171
|
bool isH1;
|
|
43
172
|
bool isH2;
|
|
44
173
|
bool isH3;
|
|
174
|
+
bool isH4;
|
|
175
|
+
bool isH5;
|
|
176
|
+
bool isH6;
|
|
45
177
|
bool isCodeBlock;
|
|
46
178
|
bool isBlockQuote;
|
|
47
179
|
bool isOrderedList;
|
|
@@ -74,6 +206,15 @@ class EnrichedTextInputViewEventEmitter : public ViewEventEmitter {
|
|
|
74
206
|
int end;
|
|
75
207
|
std::string text;
|
|
76
208
|
};
|
|
209
|
+
|
|
210
|
+
struct OnRequestHtmlResult {
|
|
211
|
+
int requestId;
|
|
212
|
+
folly::dynamic html;
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
struct OnInputKeyPress {
|
|
216
|
+
std::string key;
|
|
217
|
+
};
|
|
77
218
|
void onInputFocus(OnInputFocus value) const;
|
|
78
219
|
|
|
79
220
|
void onInputBlur(OnInputBlur value) const;
|
|
@@ -84,6 +225,8 @@ class EnrichedTextInputViewEventEmitter : public ViewEventEmitter {
|
|
|
84
225
|
|
|
85
226
|
void onChangeState(OnChangeState value) const;
|
|
86
227
|
|
|
228
|
+
void onChangeStateDeprecated(OnChangeStateDeprecated value) const;
|
|
229
|
+
|
|
87
230
|
void onLinkDetected(OnLinkDetected value) const;
|
|
88
231
|
|
|
89
232
|
void onMentionDetected(OnMentionDetected value) const;
|
|
@@ -91,5 +234,9 @@ class EnrichedTextInputViewEventEmitter : public ViewEventEmitter {
|
|
|
91
234
|
void onMention(OnMention value) const;
|
|
92
235
|
|
|
93
236
|
void onChangeSelection(OnChangeSelection value) const;
|
|
237
|
+
|
|
238
|
+
void onRequestHtmlResult(OnRequestHtmlResult value) const;
|
|
239
|
+
|
|
240
|
+
void onInputKeyPress(OnInputKeyPress value) const;
|
|
94
241
|
};
|
|
95
242
|
} // namespace facebook::react
|
package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/Props.cpp
CHANGED
|
@@ -31,12 +31,14 @@ EnrichedTextInputViewProps::EnrichedTextInputViewProps(
|
|
|
31
31
|
autoCapitalize(convertRawProp(context, rawProps, "autoCapitalize", sourceProps.autoCapitalize, {})),
|
|
32
32
|
htmlStyle(convertRawProp(context, rawProps, "htmlStyle", sourceProps.htmlStyle, {})),
|
|
33
33
|
scrollEnabled(convertRawProp(context, rawProps, "scrollEnabled", sourceProps.scrollEnabled, {false})),
|
|
34
|
+
linkRegex(convertRawProp(context, rawProps, "linkRegex", sourceProps.linkRegex, {})),
|
|
34
35
|
color(convertRawProp(context, rawProps, "color", sourceProps.color, {})),
|
|
35
36
|
fontSize(convertRawProp(context, rawProps, "fontSize", sourceProps.fontSize, {0.0})),
|
|
36
37
|
fontFamily(convertRawProp(context, rawProps, "fontFamily", sourceProps.fontFamily, {})),
|
|
37
38
|
fontWeight(convertRawProp(context, rawProps, "fontWeight", sourceProps.fontWeight, {})),
|
|
38
39
|
fontStyle(convertRawProp(context, rawProps, "fontStyle", sourceProps.fontStyle, {})),
|
|
39
40
|
isOnChangeHtmlSet(convertRawProp(context, rawProps, "isOnChangeHtmlSet", sourceProps.isOnChangeHtmlSet, {false})),
|
|
41
|
+
isOnChangeTextSet(convertRawProp(context, rawProps, "isOnChangeTextSet", sourceProps.isOnChangeTextSet, {false})),
|
|
40
42
|
androidExperimentalSynchronousEvents(convertRawProp(context, rawProps, "androidExperimentalSynchronousEvents", sourceProps.androidExperimentalSynchronousEvents, {false})) {}
|
|
41
43
|
|
|
42
44
|
#ifdef RN_SERIALIZABLE_STATE
|
|
@@ -99,6 +101,10 @@ folly::dynamic EnrichedTextInputViewProps::getDiffProps(
|
|
|
99
101
|
result["scrollEnabled"] = scrollEnabled;
|
|
100
102
|
}
|
|
101
103
|
|
|
104
|
+
if (linkRegex != oldProps->linkRegex) {
|
|
105
|
+
result["linkRegex"] = toDynamic(linkRegex);
|
|
106
|
+
}
|
|
107
|
+
|
|
102
108
|
if (color != oldProps->color) {
|
|
103
109
|
result["color"] = *color;
|
|
104
110
|
}
|
|
@@ -123,6 +129,10 @@ folly::dynamic EnrichedTextInputViewProps::getDiffProps(
|
|
|
123
129
|
result["isOnChangeHtmlSet"] = isOnChangeHtmlSet;
|
|
124
130
|
}
|
|
125
131
|
|
|
132
|
+
if (isOnChangeTextSet != oldProps->isOnChangeTextSet) {
|
|
133
|
+
result["isOnChangeTextSet"] = isOnChangeTextSet;
|
|
134
|
+
}
|
|
135
|
+
|
|
126
136
|
if (androidExperimentalSynchronousEvents != oldProps->androidExperimentalSynchronousEvents) {
|
|
127
137
|
result["androidExperimentalSynchronousEvents"] = androidExperimentalSynchronousEvents;
|
|
128
138
|
}
|
|
@@ -135,6 +135,123 @@ static inline folly::dynamic toDynamic(const EnrichedTextInputViewHtmlStyleH3Str
|
|
|
135
135
|
}
|
|
136
136
|
#endif
|
|
137
137
|
|
|
138
|
+
struct EnrichedTextInputViewHtmlStyleH4Struct {
|
|
139
|
+
Float fontSize{0.0};
|
|
140
|
+
bool bold{false};
|
|
141
|
+
|
|
142
|
+
#ifdef RN_SERIALIZABLE_STATE
|
|
143
|
+
bool operator==(const EnrichedTextInputViewHtmlStyleH4Struct&) const = default;
|
|
144
|
+
|
|
145
|
+
folly::dynamic toDynamic() const {
|
|
146
|
+
folly::dynamic result = folly::dynamic::object();
|
|
147
|
+
result["fontSize"] = fontSize;
|
|
148
|
+
result["bold"] = bold;
|
|
149
|
+
return result;
|
|
150
|
+
}
|
|
151
|
+
#endif
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, EnrichedTextInputViewHtmlStyleH4Struct &result) {
|
|
155
|
+
auto map = (std::unordered_map<std::string, RawValue>)value;
|
|
156
|
+
|
|
157
|
+
auto tmp_fontSize = map.find("fontSize");
|
|
158
|
+
if (tmp_fontSize != map.end()) {
|
|
159
|
+
fromRawValue(context, tmp_fontSize->second, result.fontSize);
|
|
160
|
+
}
|
|
161
|
+
auto tmp_bold = map.find("bold");
|
|
162
|
+
if (tmp_bold != map.end()) {
|
|
163
|
+
fromRawValue(context, tmp_bold->second, result.bold);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
static inline std::string toString(const EnrichedTextInputViewHtmlStyleH4Struct &value) {
|
|
168
|
+
return "[Object EnrichedTextInputViewHtmlStyleH4Struct]";
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
#ifdef RN_SERIALIZABLE_STATE
|
|
172
|
+
static inline folly::dynamic toDynamic(const EnrichedTextInputViewHtmlStyleH4Struct &value) {
|
|
173
|
+
return value.toDynamic();
|
|
174
|
+
}
|
|
175
|
+
#endif
|
|
176
|
+
|
|
177
|
+
struct EnrichedTextInputViewHtmlStyleH5Struct {
|
|
178
|
+
Float fontSize{0.0};
|
|
179
|
+
bool bold{false};
|
|
180
|
+
|
|
181
|
+
#ifdef RN_SERIALIZABLE_STATE
|
|
182
|
+
bool operator==(const EnrichedTextInputViewHtmlStyleH5Struct&) const = default;
|
|
183
|
+
|
|
184
|
+
folly::dynamic toDynamic() const {
|
|
185
|
+
folly::dynamic result = folly::dynamic::object();
|
|
186
|
+
result["fontSize"] = fontSize;
|
|
187
|
+
result["bold"] = bold;
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
#endif
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, EnrichedTextInputViewHtmlStyleH5Struct &result) {
|
|
194
|
+
auto map = (std::unordered_map<std::string, RawValue>)value;
|
|
195
|
+
|
|
196
|
+
auto tmp_fontSize = map.find("fontSize");
|
|
197
|
+
if (tmp_fontSize != map.end()) {
|
|
198
|
+
fromRawValue(context, tmp_fontSize->second, result.fontSize);
|
|
199
|
+
}
|
|
200
|
+
auto tmp_bold = map.find("bold");
|
|
201
|
+
if (tmp_bold != map.end()) {
|
|
202
|
+
fromRawValue(context, tmp_bold->second, result.bold);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
static inline std::string toString(const EnrichedTextInputViewHtmlStyleH5Struct &value) {
|
|
207
|
+
return "[Object EnrichedTextInputViewHtmlStyleH5Struct]";
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
#ifdef RN_SERIALIZABLE_STATE
|
|
211
|
+
static inline folly::dynamic toDynamic(const EnrichedTextInputViewHtmlStyleH5Struct &value) {
|
|
212
|
+
return value.toDynamic();
|
|
213
|
+
}
|
|
214
|
+
#endif
|
|
215
|
+
|
|
216
|
+
struct EnrichedTextInputViewHtmlStyleH6Struct {
|
|
217
|
+
Float fontSize{0.0};
|
|
218
|
+
bool bold{false};
|
|
219
|
+
|
|
220
|
+
#ifdef RN_SERIALIZABLE_STATE
|
|
221
|
+
bool operator==(const EnrichedTextInputViewHtmlStyleH6Struct&) const = default;
|
|
222
|
+
|
|
223
|
+
folly::dynamic toDynamic() const {
|
|
224
|
+
folly::dynamic result = folly::dynamic::object();
|
|
225
|
+
result["fontSize"] = fontSize;
|
|
226
|
+
result["bold"] = bold;
|
|
227
|
+
return result;
|
|
228
|
+
}
|
|
229
|
+
#endif
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, EnrichedTextInputViewHtmlStyleH6Struct &result) {
|
|
233
|
+
auto map = (std::unordered_map<std::string, RawValue>)value;
|
|
234
|
+
|
|
235
|
+
auto tmp_fontSize = map.find("fontSize");
|
|
236
|
+
if (tmp_fontSize != map.end()) {
|
|
237
|
+
fromRawValue(context, tmp_fontSize->second, result.fontSize);
|
|
238
|
+
}
|
|
239
|
+
auto tmp_bold = map.find("bold");
|
|
240
|
+
if (tmp_bold != map.end()) {
|
|
241
|
+
fromRawValue(context, tmp_bold->second, result.bold);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
static inline std::string toString(const EnrichedTextInputViewHtmlStyleH6Struct &value) {
|
|
246
|
+
return "[Object EnrichedTextInputViewHtmlStyleH6Struct]";
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
#ifdef RN_SERIALIZABLE_STATE
|
|
250
|
+
static inline folly::dynamic toDynamic(const EnrichedTextInputViewHtmlStyleH6Struct &value) {
|
|
251
|
+
return value.toDynamic();
|
|
252
|
+
}
|
|
253
|
+
#endif
|
|
254
|
+
|
|
138
255
|
struct EnrichedTextInputViewHtmlStyleBlockquoteStruct {
|
|
139
256
|
SharedColor borderColor{};
|
|
140
257
|
Float borderWidth{0.0};
|
|
@@ -415,6 +532,9 @@ struct EnrichedTextInputViewHtmlStyleStruct {
|
|
|
415
532
|
EnrichedTextInputViewHtmlStyleH1Struct h1{};
|
|
416
533
|
EnrichedTextInputViewHtmlStyleH2Struct h2{};
|
|
417
534
|
EnrichedTextInputViewHtmlStyleH3Struct h3{};
|
|
535
|
+
EnrichedTextInputViewHtmlStyleH4Struct h4{};
|
|
536
|
+
EnrichedTextInputViewHtmlStyleH5Struct h5{};
|
|
537
|
+
EnrichedTextInputViewHtmlStyleH6Struct h6{};
|
|
418
538
|
EnrichedTextInputViewHtmlStyleBlockquoteStruct blockquote{};
|
|
419
539
|
EnrichedTextInputViewHtmlStyleCodeblockStruct codeblock{};
|
|
420
540
|
EnrichedTextInputViewHtmlStyleCodeStruct code{};
|
|
@@ -431,6 +551,9 @@ struct EnrichedTextInputViewHtmlStyleStruct {
|
|
|
431
551
|
result["h1"] = ::facebook::react::toDynamic(h1);
|
|
432
552
|
result["h2"] = ::facebook::react::toDynamic(h2);
|
|
433
553
|
result["h3"] = ::facebook::react::toDynamic(h3);
|
|
554
|
+
result["h4"] = ::facebook::react::toDynamic(h4);
|
|
555
|
+
result["h5"] = ::facebook::react::toDynamic(h5);
|
|
556
|
+
result["h6"] = ::facebook::react::toDynamic(h6);
|
|
434
557
|
result["blockquote"] = ::facebook::react::toDynamic(blockquote);
|
|
435
558
|
result["codeblock"] = ::facebook::react::toDynamic(codeblock);
|
|
436
559
|
result["code"] = ::facebook::react::toDynamic(code);
|
|
@@ -458,6 +581,18 @@ static inline void fromRawValue(const PropsParserContext& context, const RawValu
|
|
|
458
581
|
if (tmp_h3 != map.end()) {
|
|
459
582
|
fromRawValue(context, tmp_h3->second, result.h3);
|
|
460
583
|
}
|
|
584
|
+
auto tmp_h4 = map.find("h4");
|
|
585
|
+
if (tmp_h4 != map.end()) {
|
|
586
|
+
fromRawValue(context, tmp_h4->second, result.h4);
|
|
587
|
+
}
|
|
588
|
+
auto tmp_h5 = map.find("h5");
|
|
589
|
+
if (tmp_h5 != map.end()) {
|
|
590
|
+
fromRawValue(context, tmp_h5->second, result.h5);
|
|
591
|
+
}
|
|
592
|
+
auto tmp_h6 = map.find("h6");
|
|
593
|
+
if (tmp_h6 != map.end()) {
|
|
594
|
+
fromRawValue(context, tmp_h6->second, result.h6);
|
|
595
|
+
}
|
|
461
596
|
auto tmp_blockquote = map.find("blockquote");
|
|
462
597
|
if (tmp_blockquote != map.end()) {
|
|
463
598
|
fromRawValue(context, tmp_blockquote->second, result.blockquote);
|
|
@@ -497,6 +632,63 @@ static inline folly::dynamic toDynamic(const EnrichedTextInputViewHtmlStyleStruc
|
|
|
497
632
|
return value.toDynamic();
|
|
498
633
|
}
|
|
499
634
|
#endif
|
|
635
|
+
|
|
636
|
+
struct EnrichedTextInputViewLinkRegexStruct {
|
|
637
|
+
std::string pattern{};
|
|
638
|
+
bool caseInsensitive{false};
|
|
639
|
+
bool dotAll{false};
|
|
640
|
+
bool isDisabled{false};
|
|
641
|
+
bool isDefault{false};
|
|
642
|
+
|
|
643
|
+
#ifdef RN_SERIALIZABLE_STATE
|
|
644
|
+
bool operator==(const EnrichedTextInputViewLinkRegexStruct&) const = default;
|
|
645
|
+
|
|
646
|
+
folly::dynamic toDynamic() const {
|
|
647
|
+
folly::dynamic result = folly::dynamic::object();
|
|
648
|
+
result["pattern"] = pattern;
|
|
649
|
+
result["caseInsensitive"] = caseInsensitive;
|
|
650
|
+
result["dotAll"] = dotAll;
|
|
651
|
+
result["isDisabled"] = isDisabled;
|
|
652
|
+
result["isDefault"] = isDefault;
|
|
653
|
+
return result;
|
|
654
|
+
}
|
|
655
|
+
#endif
|
|
656
|
+
};
|
|
657
|
+
|
|
658
|
+
static inline void fromRawValue(const PropsParserContext& context, const RawValue &value, EnrichedTextInputViewLinkRegexStruct &result) {
|
|
659
|
+
auto map = (std::unordered_map<std::string, RawValue>)value;
|
|
660
|
+
|
|
661
|
+
auto tmp_pattern = map.find("pattern");
|
|
662
|
+
if (tmp_pattern != map.end()) {
|
|
663
|
+
fromRawValue(context, tmp_pattern->second, result.pattern);
|
|
664
|
+
}
|
|
665
|
+
auto tmp_caseInsensitive = map.find("caseInsensitive");
|
|
666
|
+
if (tmp_caseInsensitive != map.end()) {
|
|
667
|
+
fromRawValue(context, tmp_caseInsensitive->second, result.caseInsensitive);
|
|
668
|
+
}
|
|
669
|
+
auto tmp_dotAll = map.find("dotAll");
|
|
670
|
+
if (tmp_dotAll != map.end()) {
|
|
671
|
+
fromRawValue(context, tmp_dotAll->second, result.dotAll);
|
|
672
|
+
}
|
|
673
|
+
auto tmp_isDisabled = map.find("isDisabled");
|
|
674
|
+
if (tmp_isDisabled != map.end()) {
|
|
675
|
+
fromRawValue(context, tmp_isDisabled->second, result.isDisabled);
|
|
676
|
+
}
|
|
677
|
+
auto tmp_isDefault = map.find("isDefault");
|
|
678
|
+
if (tmp_isDefault != map.end()) {
|
|
679
|
+
fromRawValue(context, tmp_isDefault->second, result.isDefault);
|
|
680
|
+
}
|
|
681
|
+
}
|
|
682
|
+
|
|
683
|
+
static inline std::string toString(const EnrichedTextInputViewLinkRegexStruct &value) {
|
|
684
|
+
return "[Object EnrichedTextInputViewLinkRegexStruct]";
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
#ifdef RN_SERIALIZABLE_STATE
|
|
688
|
+
static inline folly::dynamic toDynamic(const EnrichedTextInputViewLinkRegexStruct &value) {
|
|
689
|
+
return value.toDynamic();
|
|
690
|
+
}
|
|
691
|
+
#endif
|
|
500
692
|
class EnrichedTextInputViewProps final : public ViewProps {
|
|
501
693
|
public:
|
|
502
694
|
EnrichedTextInputViewProps() = default;
|
|
@@ -515,12 +707,14 @@ class EnrichedTextInputViewProps final : public ViewProps {
|
|
|
515
707
|
std::string autoCapitalize{};
|
|
516
708
|
EnrichedTextInputViewHtmlStyleStruct htmlStyle{};
|
|
517
709
|
bool scrollEnabled{false};
|
|
710
|
+
EnrichedTextInputViewLinkRegexStruct linkRegex{};
|
|
518
711
|
SharedColor color{};
|
|
519
712
|
Float fontSize{0.0};
|
|
520
713
|
std::string fontFamily{};
|
|
521
714
|
std::string fontWeight{};
|
|
522
715
|
std::string fontStyle{};
|
|
523
716
|
bool isOnChangeHtmlSet{false};
|
|
717
|
+
bool isOnChangeTextSet{false};
|
|
524
718
|
bool androidExperimentalSynchronousEvents{false};
|
|
525
719
|
|
|
526
720
|
#ifdef RN_SERIALIZABLE_STATE
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
apply plugin: "org.jlleitschuh.gradle.ktlint"
|
|
2
|
+
apply plugin: 'com.diffplug.spotless'
|
|
3
|
+
|
|
4
|
+
ktlint {
|
|
5
|
+
version = "1.8.0"
|
|
6
|
+
verbose = true
|
|
7
|
+
outputToConsole = true
|
|
8
|
+
coloredOutput = true
|
|
9
|
+
android = true
|
|
10
|
+
enableExperimentalRules = true
|
|
11
|
+
|
|
12
|
+
reporters {
|
|
13
|
+
reporter "plain"
|
|
14
|
+
reporter "checkstyle"
|
|
15
|
+
reporter "html"
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
filter {
|
|
19
|
+
exclude("**/generated/**")
|
|
20
|
+
exclude("**/build/**")
|
|
21
|
+
exclude("**/node_modules/**")
|
|
22
|
+
|
|
23
|
+
include("src/**/*.kt")
|
|
24
|
+
include("src/**/*.kts")
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
spotless {
|
|
29
|
+
kotlin {
|
|
30
|
+
target 'src/**/*.kt', 'src/**/*.kts'
|
|
31
|
+
ktlint("1.8.0")
|
|
32
|
+
trimTrailingWhitespace()
|
|
33
|
+
endWithNewline()
|
|
34
|
+
lineEndings 'UNIX'
|
|
35
|
+
targetExclude '**/generated/**', '**/build/**', '**/node_modules/**'
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
java {
|
|
39
|
+
target 'src/**/*.java'
|
|
40
|
+
googleJavaFormat("1.23.0")
|
|
41
|
+
removeUnusedImports()
|
|
42
|
+
trimTrailingWhitespace()
|
|
43
|
+
endWithNewline()
|
|
44
|
+
leadingTabsToSpaces(2)
|
|
45
|
+
lineEndings 'UNIX'
|
|
46
|
+
targetExclude '**/generated/**', '**/build/**', '**/node_modules/**'
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
groovyGradle {
|
|
50
|
+
target '*.gradle', 'gradle/*.gradle'
|
|
51
|
+
greclipse()
|
|
52
|
+
trimTrailingWhitespace()
|
|
53
|
+
endWithNewline()
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
tasks.register('lintFormat') {
|
|
58
|
+
group = "formatting"
|
|
59
|
+
description = "Auto-fix all code formatting issues"
|
|
60
|
+
dependsOn 'ktlintFormat', 'spotlessApply'
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
tasks.register('lintVerify') {
|
|
64
|
+
group = "verification"
|
|
65
|
+
description = "Verify code is properly formatted"
|
|
66
|
+
dependsOn 'ktlintCheck', 'spotlessCheck'
|
|
67
|
+
doLast {
|
|
68
|
+
println "✓ All code formatting checks passed!"
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
package com.swmansion.enriched
|
|
2
|
+
|
|
3
|
+
import android.view.KeyEvent
|
|
4
|
+
import android.view.inputmethod.InputConnection
|
|
5
|
+
import android.view.inputmethod.InputConnectionWrapper
|
|
6
|
+
import com.facebook.react.bridge.ReactContext
|
|
7
|
+
import com.facebook.react.uimanager.UIManagerHelper
|
|
8
|
+
import com.swmansion.enriched.events.OnInputKeyPressEvent
|
|
9
|
+
|
|
10
|
+
// This class is based on the implementation from Facebook React Native to provide 'onKeyPress' API on android.
|
|
11
|
+
// Original source:
|
|
12
|
+
// https://github.com/facebook/react-native/blob/v0.83.1/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/views/textinput/ReactEditTextInputConnectionWrapper.kt
|
|
13
|
+
class EnrichedTextInputConnectionWrapper(
|
|
14
|
+
target: InputConnection,
|
|
15
|
+
private val reactContext: ReactContext,
|
|
16
|
+
private val editText: EnrichedTextInputView,
|
|
17
|
+
private val experimentalSynchronousEvents: Boolean,
|
|
18
|
+
) : InputConnectionWrapper(target, false) {
|
|
19
|
+
private var isBatchEdit = false
|
|
20
|
+
private var key: String? = null
|
|
21
|
+
|
|
22
|
+
override fun beginBatchEdit(): Boolean {
|
|
23
|
+
isBatchEdit = true
|
|
24
|
+
return super.beginBatchEdit()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
override fun endBatchEdit(): Boolean {
|
|
28
|
+
isBatchEdit = false
|
|
29
|
+
key?.let { k ->
|
|
30
|
+
dispatchKeyEvent(k)
|
|
31
|
+
key = null
|
|
32
|
+
}
|
|
33
|
+
return super.endBatchEdit()
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
override fun setComposingText(
|
|
37
|
+
text: CharSequence,
|
|
38
|
+
newCursorPosition: Int,
|
|
39
|
+
): Boolean {
|
|
40
|
+
val previousSelectionStart = editText.selectionStart
|
|
41
|
+
val previousSelectionEnd = editText.selectionEnd
|
|
42
|
+
|
|
43
|
+
val consumed = super.setComposingText(text, newCursorPosition)
|
|
44
|
+
|
|
45
|
+
val currentSelectionStart = editText.selectionStart
|
|
46
|
+
val noPreviousSelection = previousSelectionStart == previousSelectionEnd
|
|
47
|
+
val cursorDidNotMove = currentSelectionStart == previousSelectionStart
|
|
48
|
+
val cursorMovedBackwardsOrAtBeginningOfInput =
|
|
49
|
+
currentSelectionStart < previousSelectionStart || currentSelectionStart <= 0
|
|
50
|
+
|
|
51
|
+
val inputKey =
|
|
52
|
+
if (
|
|
53
|
+
cursorMovedBackwardsOrAtBeginningOfInput || (!noPreviousSelection && cursorDidNotMove)
|
|
54
|
+
) {
|
|
55
|
+
BACKSPACE_KEY_VALUE
|
|
56
|
+
} else {
|
|
57
|
+
editText.text?.get(currentSelectionStart - 1).toString()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
dispatchKeyEventOrEnqueue(inputKey)
|
|
61
|
+
return consumed
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
override fun commitText(
|
|
65
|
+
text: CharSequence,
|
|
66
|
+
newCursorPosition: Int,
|
|
67
|
+
): Boolean {
|
|
68
|
+
var inputKey = text.toString()
|
|
69
|
+
// Assume not a keyPress if length > 1 (or 2 if unicode)
|
|
70
|
+
if (inputKey.length <= 2) {
|
|
71
|
+
if (inputKey.isEmpty()) {
|
|
72
|
+
inputKey = BACKSPACE_KEY_VALUE
|
|
73
|
+
}
|
|
74
|
+
dispatchKeyEventOrEnqueue(inputKey)
|
|
75
|
+
}
|
|
76
|
+
return super.commitText(text, newCursorPosition)
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
override fun deleteSurroundingText(
|
|
80
|
+
beforeLength: Int,
|
|
81
|
+
afterLength: Int,
|
|
82
|
+
): Boolean {
|
|
83
|
+
dispatchKeyEvent(BACKSPACE_KEY_VALUE)
|
|
84
|
+
return super.deleteSurroundingText(beforeLength, afterLength)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Called by SwiftKey when cursor at beginning of input when there is a delete
|
|
88
|
+
// or when enter is pressed anywhere in the text. Whereas stock Android Keyboard calls
|
|
89
|
+
// [InputConnection.deleteSurroundingText] & [InputConnection.commitText]
|
|
90
|
+
// in each case, respectively.
|
|
91
|
+
override fun sendKeyEvent(event: KeyEvent): Boolean {
|
|
92
|
+
if (event.action == KeyEvent.ACTION_DOWN) {
|
|
93
|
+
val isNumberKey = event.unicodeChar in 48..57
|
|
94
|
+
when (event.keyCode) {
|
|
95
|
+
KeyEvent.KEYCODE_DEL -> {
|
|
96
|
+
dispatchKeyEvent(BACKSPACE_KEY_VALUE)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
KeyEvent.KEYCODE_ENTER -> {
|
|
100
|
+
dispatchKeyEvent(ENTER_KEY_VALUE)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
else -> {
|
|
104
|
+
if (isNumberKey) {
|
|
105
|
+
dispatchKeyEvent(event.number.toString())
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return super.sendKeyEvent(event)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
private fun dispatchKeyEventOrEnqueue(inputKey: String) {
|
|
114
|
+
if (isBatchEdit) {
|
|
115
|
+
key = inputKey
|
|
116
|
+
} else {
|
|
117
|
+
dispatchKeyEvent(inputKey)
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
private fun dispatchKeyEvent(inputKey: String) {
|
|
122
|
+
val resolvedKey = if (inputKey == NEWLINE_RAW_VALUE) ENTER_KEY_VALUE else inputKey
|
|
123
|
+
val surfaceId = UIManagerHelper.getSurfaceId(editText)
|
|
124
|
+
val eventDispatcher = UIManagerHelper.getEventDispatcherForReactTag(reactContext, editText.id)
|
|
125
|
+
eventDispatcher?.dispatchEvent(
|
|
126
|
+
OnInputKeyPressEvent(
|
|
127
|
+
surfaceId = surfaceId,
|
|
128
|
+
viewId = editText.id,
|
|
129
|
+
key = resolvedKey,
|
|
130
|
+
experimentalSynchronousEvents = experimentalSynchronousEvents,
|
|
131
|
+
),
|
|
132
|
+
)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
companion object {
|
|
136
|
+
const val NEWLINE_RAW_VALUE: String = "\n"
|
|
137
|
+
const val BACKSPACE_KEY_VALUE: String = "Backspace"
|
|
138
|
+
const val ENTER_KEY_VALUE: String = "Enter"
|
|
139
|
+
}
|
|
140
|
+
}
|