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
|
@@ -4,12 +4,17 @@ import com.facebook.react.bridge.Arguments
|
|
|
4
4
|
import com.facebook.react.bridge.ReactContext
|
|
5
5
|
import com.facebook.react.bridge.WritableMap
|
|
6
6
|
import com.facebook.react.uimanager.UIManagerHelper
|
|
7
|
+
import com.facebook.react.uimanager.events.EventDispatcher
|
|
7
8
|
import com.swmansion.enriched.EnrichedTextInputView
|
|
9
|
+
import com.swmansion.enriched.events.OnChangeStateDeprecatedEvent
|
|
8
10
|
import com.swmansion.enriched.events.OnChangeStateEvent
|
|
9
11
|
import com.swmansion.enriched.spans.EnrichedSpans
|
|
10
12
|
|
|
11
|
-
class EnrichedSpanState(
|
|
13
|
+
class EnrichedSpanState(
|
|
14
|
+
private val view: EnrichedTextInputView,
|
|
15
|
+
) {
|
|
12
16
|
private var previousPayload: WritableMap? = null
|
|
17
|
+
private var previousDeprecatedPayload: WritableMap? = null
|
|
13
18
|
|
|
14
19
|
var boldStart: Int? = null
|
|
15
20
|
private set
|
|
@@ -27,6 +32,12 @@ class EnrichedSpanState(private val view: EnrichedTextInputView) {
|
|
|
27
32
|
private set
|
|
28
33
|
var h3Start: Int? = null
|
|
29
34
|
private set
|
|
35
|
+
var h4Start: Int? = null
|
|
36
|
+
private set
|
|
37
|
+
var h5Start: Int? = null
|
|
38
|
+
private set
|
|
39
|
+
var h6Start: Int? = null
|
|
40
|
+
private set
|
|
30
41
|
var codeBlockStart: Int? = null
|
|
31
42
|
private set
|
|
32
43
|
var blockQuoteStart: Int? = null
|
|
@@ -82,6 +93,21 @@ class EnrichedSpanState(private val view: EnrichedTextInputView) {
|
|
|
82
93
|
emitStateChangeEvent()
|
|
83
94
|
}
|
|
84
95
|
|
|
96
|
+
fun setH4Start(start: Int?) {
|
|
97
|
+
this.h4Start = start
|
|
98
|
+
emitStateChangeEvent()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
fun setH5Start(start: Int?) {
|
|
102
|
+
this.h5Start = start
|
|
103
|
+
emitStateChangeEvent()
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
fun setH6Start(start: Int?) {
|
|
107
|
+
this.h6Start = start
|
|
108
|
+
emitStateChangeEvent()
|
|
109
|
+
}
|
|
110
|
+
|
|
85
111
|
fun setCodeBlockStart(start: Int?) {
|
|
86
112
|
this.codeBlockStart = start
|
|
87
113
|
emitStateChangeEvent()
|
|
@@ -118,29 +144,36 @@ class EnrichedSpanState(private val view: EnrichedTextInputView) {
|
|
|
118
144
|
}
|
|
119
145
|
|
|
120
146
|
fun getStart(name: String): Int? {
|
|
121
|
-
val start =
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
147
|
+
val start =
|
|
148
|
+
when (name) {
|
|
149
|
+
EnrichedSpans.BOLD -> boldStart
|
|
150
|
+
EnrichedSpans.ITALIC -> italicStart
|
|
151
|
+
EnrichedSpans.UNDERLINE -> underlineStart
|
|
152
|
+
EnrichedSpans.STRIKETHROUGH -> strikethroughStart
|
|
153
|
+
EnrichedSpans.INLINE_CODE -> inlineCodeStart
|
|
154
|
+
EnrichedSpans.H1 -> h1Start
|
|
155
|
+
EnrichedSpans.H2 -> h2Start
|
|
156
|
+
EnrichedSpans.H3 -> h3Start
|
|
157
|
+
EnrichedSpans.H4 -> h4Start
|
|
158
|
+
EnrichedSpans.H5 -> h5Start
|
|
159
|
+
EnrichedSpans.H6 -> h6Start
|
|
160
|
+
EnrichedSpans.CODE_BLOCK -> codeBlockStart
|
|
161
|
+
EnrichedSpans.BLOCK_QUOTE -> blockQuoteStart
|
|
162
|
+
EnrichedSpans.ORDERED_LIST -> orderedListStart
|
|
163
|
+
EnrichedSpans.UNORDERED_LIST -> unorderedListStart
|
|
164
|
+
EnrichedSpans.LINK -> linkStart
|
|
165
|
+
EnrichedSpans.IMAGE -> imageStart
|
|
166
|
+
EnrichedSpans.MENTION -> mentionStart
|
|
167
|
+
else -> null
|
|
168
|
+
}
|
|
139
169
|
|
|
140
170
|
return start
|
|
141
171
|
}
|
|
142
172
|
|
|
143
|
-
fun setStart(
|
|
173
|
+
fun setStart(
|
|
174
|
+
name: String,
|
|
175
|
+
start: Int?,
|
|
176
|
+
) {
|
|
144
177
|
when (name) {
|
|
145
178
|
EnrichedSpans.BOLD -> setBoldStart(start)
|
|
146
179
|
EnrichedSpans.ITALIC -> setItalicStart(start)
|
|
@@ -150,6 +183,9 @@ class EnrichedSpanState(private val view: EnrichedTextInputView) {
|
|
|
150
183
|
EnrichedSpans.H1 -> setH1Start(start)
|
|
151
184
|
EnrichedSpans.H2 -> setH2Start(start)
|
|
152
185
|
EnrichedSpans.H3 -> setH3Start(start)
|
|
186
|
+
EnrichedSpans.H4 -> setH4Start(start)
|
|
187
|
+
EnrichedSpans.H5 -> setH5Start(start)
|
|
188
|
+
EnrichedSpans.H6 -> setH6Start(start)
|
|
153
189
|
EnrichedSpans.CODE_BLOCK -> setCodeBlockStart(start)
|
|
154
190
|
EnrichedSpans.BLOCK_QUOTE -> setBlockQuoteStart(start)
|
|
155
191
|
EnrichedSpans.ORDERED_LIST -> setOrderedListStart(start)
|
|
@@ -161,41 +197,140 @@ class EnrichedSpanState(private val view: EnrichedTextInputView) {
|
|
|
161
197
|
}
|
|
162
198
|
|
|
163
199
|
private fun emitStateChangeEvent() {
|
|
164
|
-
val
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
200
|
+
val context = view.context as ReactContext
|
|
201
|
+
val surfaceId = UIManagerHelper.getSurfaceId(context)
|
|
202
|
+
val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, view.id)
|
|
203
|
+
|
|
204
|
+
dispatchDeprecatedPayload(dispatcher, surfaceId)
|
|
205
|
+
dispatchPayload(dispatcher, surfaceId)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
private fun dispatchDeprecatedPayload(
|
|
209
|
+
dispatcher: EventDispatcher?,
|
|
210
|
+
surfaceId: Int,
|
|
211
|
+
) {
|
|
212
|
+
val deprecatedPayload = Arguments.createMap()
|
|
213
|
+
deprecatedPayload.putBoolean("isBold", boldStart != null)
|
|
214
|
+
deprecatedPayload.putBoolean("isItalic", italicStart != null)
|
|
215
|
+
deprecatedPayload.putBoolean("isUnderline", underlineStart != null)
|
|
216
|
+
deprecatedPayload.putBoolean("isStrikeThrough", strikethroughStart != null)
|
|
217
|
+
deprecatedPayload.putBoolean("isInlineCode", inlineCodeStart != null)
|
|
218
|
+
deprecatedPayload.putBoolean("isH1", h1Start != null)
|
|
219
|
+
deprecatedPayload.putBoolean("isH2", h2Start != null)
|
|
220
|
+
deprecatedPayload.putBoolean("isH3", h3Start != null)
|
|
221
|
+
deprecatedPayload.putBoolean("isH4", h4Start != null)
|
|
222
|
+
deprecatedPayload.putBoolean("isH5", h5Start != null)
|
|
223
|
+
deprecatedPayload.putBoolean("isH6", h6Start != null)
|
|
224
|
+
deprecatedPayload.putBoolean("isCodeBlock", codeBlockStart != null)
|
|
225
|
+
deprecatedPayload.putBoolean("isBlockQuote", blockQuoteStart != null)
|
|
226
|
+
deprecatedPayload.putBoolean("isOrderedList", orderedListStart != null)
|
|
227
|
+
deprecatedPayload.putBoolean("isUnorderedList", unorderedListStart != null)
|
|
228
|
+
deprecatedPayload.putBoolean("isLink", linkStart != null)
|
|
229
|
+
deprecatedPayload.putBoolean("isImage", imageStart != null)
|
|
230
|
+
deprecatedPayload.putBoolean("isMention", mentionStart != null)
|
|
231
|
+
|
|
232
|
+
if (previousDeprecatedPayload == deprecatedPayload) {
|
|
233
|
+
return
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
previousDeprecatedPayload =
|
|
237
|
+
Arguments.createMap().apply {
|
|
238
|
+
merge(deprecatedPayload)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
dispatcher?.dispatchEvent(
|
|
242
|
+
OnChangeStateDeprecatedEvent(
|
|
243
|
+
surfaceId,
|
|
244
|
+
view.id,
|
|
245
|
+
deprecatedPayload,
|
|
246
|
+
view.experimentalSynchronousEvents,
|
|
247
|
+
),
|
|
248
|
+
)
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
private fun dispatchPayload(
|
|
252
|
+
dispatcher: EventDispatcher?,
|
|
253
|
+
surfaceId: Int,
|
|
254
|
+
) {
|
|
255
|
+
val activeStyles =
|
|
256
|
+
listOfNotNull(
|
|
257
|
+
if (boldStart != null) EnrichedSpans.BOLD else null,
|
|
258
|
+
if (italicStart != null) EnrichedSpans.ITALIC else null,
|
|
259
|
+
if (underlineStart != null) EnrichedSpans.UNDERLINE else null,
|
|
260
|
+
if (strikethroughStart != null) EnrichedSpans.STRIKETHROUGH else null,
|
|
261
|
+
if (inlineCodeStart != null) EnrichedSpans.INLINE_CODE else null,
|
|
262
|
+
if (h1Start != null) EnrichedSpans.H1 else null,
|
|
263
|
+
if (h2Start != null) EnrichedSpans.H2 else null,
|
|
264
|
+
if (h3Start != null) EnrichedSpans.H3 else null,
|
|
265
|
+
if (h4Start != null) EnrichedSpans.H4 else null,
|
|
266
|
+
if (h5Start != null) EnrichedSpans.H5 else null,
|
|
267
|
+
if (h6Start != null) EnrichedSpans.H6 else null,
|
|
268
|
+
if (codeBlockStart != null) EnrichedSpans.CODE_BLOCK else null,
|
|
269
|
+
if (blockQuoteStart != null) EnrichedSpans.BLOCK_QUOTE else null,
|
|
270
|
+
if (orderedListStart != null) EnrichedSpans.ORDERED_LIST else null,
|
|
271
|
+
if (unorderedListStart != null) EnrichedSpans.UNORDERED_LIST else null,
|
|
272
|
+
if (linkStart != null) EnrichedSpans.LINK else null,
|
|
273
|
+
if (imageStart != null) EnrichedSpans.IMAGE else null,
|
|
274
|
+
if (mentionStart != null) EnrichedSpans.MENTION else null,
|
|
275
|
+
)
|
|
276
|
+
val payload = Arguments.createMap()
|
|
277
|
+
payload.putMap("bold", getStyleState(activeStyles, EnrichedSpans.BOLD))
|
|
278
|
+
payload.putMap("italic", getStyleState(activeStyles, EnrichedSpans.ITALIC))
|
|
279
|
+
payload.putMap("underline", getStyleState(activeStyles, EnrichedSpans.UNDERLINE))
|
|
280
|
+
payload.putMap("strikeThrough", getStyleState(activeStyles, EnrichedSpans.STRIKETHROUGH))
|
|
281
|
+
payload.putMap("inlineCode", getStyleState(activeStyles, EnrichedSpans.INLINE_CODE))
|
|
282
|
+
payload.putMap("h1", getStyleState(activeStyles, EnrichedSpans.H1))
|
|
283
|
+
payload.putMap("h2", getStyleState(activeStyles, EnrichedSpans.H2))
|
|
284
|
+
payload.putMap("h3", getStyleState(activeStyles, EnrichedSpans.H3))
|
|
285
|
+
payload.putMap("h4", getStyleState(activeStyles, EnrichedSpans.H4))
|
|
286
|
+
payload.putMap("h5", getStyleState(activeStyles, EnrichedSpans.H5))
|
|
287
|
+
payload.putMap("h6", getStyleState(activeStyles, EnrichedSpans.H6))
|
|
288
|
+
payload.putMap("codeBlock", getStyleState(activeStyles, EnrichedSpans.CODE_BLOCK))
|
|
289
|
+
payload.putMap("blockQuote", getStyleState(activeStyles, EnrichedSpans.BLOCK_QUOTE))
|
|
290
|
+
payload.putMap("orderedList", getStyleState(activeStyles, EnrichedSpans.ORDERED_LIST))
|
|
291
|
+
payload.putMap("unorderedList", getStyleState(activeStyles, EnrichedSpans.UNORDERED_LIST))
|
|
292
|
+
payload.putMap("link", getStyleState(activeStyles, EnrichedSpans.LINK))
|
|
293
|
+
payload.putMap("image", getStyleState(activeStyles, EnrichedSpans.IMAGE))
|
|
294
|
+
payload.putMap("mention", getStyleState(activeStyles, EnrichedSpans.MENTION))
|
|
180
295
|
|
|
181
296
|
// Do not emit event if payload is the same
|
|
182
297
|
if (previousPayload == payload) {
|
|
183
298
|
return
|
|
184
299
|
}
|
|
185
300
|
|
|
186
|
-
previousPayload =
|
|
187
|
-
|
|
188
|
-
|
|
301
|
+
previousPayload =
|
|
302
|
+
Arguments.createMap().apply {
|
|
303
|
+
merge(payload)
|
|
304
|
+
}
|
|
305
|
+
dispatcher?.dispatchEvent(
|
|
306
|
+
OnChangeStateEvent(
|
|
307
|
+
surfaceId,
|
|
308
|
+
view.id,
|
|
309
|
+
payload,
|
|
310
|
+
view.experimentalSynchronousEvents,
|
|
311
|
+
),
|
|
312
|
+
)
|
|
313
|
+
}
|
|
189
314
|
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
)
|
|
315
|
+
private fun getStyleState(
|
|
316
|
+
activeStyles: List<String>,
|
|
317
|
+
type: String,
|
|
318
|
+
): WritableMap {
|
|
319
|
+
val mergingConfig = EnrichedSpans.getMergingConfigForStyle(type, view.htmlStyle)
|
|
320
|
+
val blockingList = mergingConfig?.blockingStyles
|
|
321
|
+
val conflictingList = mergingConfig?.conflictingStyles
|
|
322
|
+
|
|
323
|
+
val state = Arguments.createMap()
|
|
324
|
+
|
|
325
|
+
state.putBoolean("isActive", activeStyles.contains(type))
|
|
326
|
+
|
|
327
|
+
val isBlocking = blockingList?.any { activeStyles.contains(it) } ?: false
|
|
328
|
+
state.putBoolean("isBlocking", isBlocking)
|
|
329
|
+
|
|
330
|
+
val isConflicting = conflictingList?.any { activeStyles.contains(it) } ?: false
|
|
331
|
+
state.putBoolean("isConflicting", isConflicting)
|
|
332
|
+
|
|
333
|
+
return state
|
|
199
334
|
}
|
|
200
335
|
|
|
201
336
|
companion object {
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
package com.swmansion.enriched.utils
|
|
2
|
+
|
|
3
|
+
import android.text.Spannable
|
|
4
|
+
import android.text.SpannableString
|
|
5
|
+
import android.text.SpannableStringBuilder
|
|
6
|
+
import com.swmansion.enriched.spans.interfaces.EnrichedBlockSpan
|
|
7
|
+
import com.swmansion.enriched.spans.interfaces.EnrichedParagraphSpan
|
|
8
|
+
|
|
9
|
+
fun Spannable.getSafeSpanBoundaries(
|
|
10
|
+
start: Int,
|
|
11
|
+
end: Int,
|
|
12
|
+
): Pair<Int, Int> {
|
|
13
|
+
val safeStart = start.coerceAtMost(end).coerceAtLeast(0)
|
|
14
|
+
val safeEnd = end.coerceAtLeast(start).coerceAtMost(this.length)
|
|
15
|
+
|
|
16
|
+
return Pair(safeStart, safeEnd)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
fun Spannable.getParagraphBounds(
|
|
20
|
+
start: Int,
|
|
21
|
+
end: Int,
|
|
22
|
+
): Pair<Int, Int> {
|
|
23
|
+
var startPosition = start.coerceAtLeast(0).coerceAtMost(this.length)
|
|
24
|
+
var endPosition = end.coerceAtLeast(0).coerceAtMost(this.length)
|
|
25
|
+
|
|
26
|
+
// Find the start of the paragraph
|
|
27
|
+
while (startPosition > 0 && this[startPosition - 1] != '\n') {
|
|
28
|
+
startPosition--
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Find the end of the paragraph
|
|
32
|
+
while (endPosition < this.length && this[endPosition] != '\n') {
|
|
33
|
+
endPosition++
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (startPosition >= endPosition) {
|
|
37
|
+
// If the start position is equal or greater than the end position, return the same position
|
|
38
|
+
startPosition = endPosition
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return Pair(startPosition, endPosition)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
fun Spannable.getParagraphBounds(index: Int): Pair<Int, Int> = this.getParagraphBounds(index, index)
|
|
45
|
+
|
|
46
|
+
fun Spannable.mergeSpannables(
|
|
47
|
+
start: Int,
|
|
48
|
+
end: Int,
|
|
49
|
+
string: String,
|
|
50
|
+
): Spannable = this.mergeSpannables(start, end, SpannableString(string))
|
|
51
|
+
|
|
52
|
+
fun Spannable.mergeSpannables(
|
|
53
|
+
start: Int,
|
|
54
|
+
end: Int,
|
|
55
|
+
spannable: Spannable,
|
|
56
|
+
): Spannable {
|
|
57
|
+
var finalStart = start
|
|
58
|
+
var finalEnd = end
|
|
59
|
+
|
|
60
|
+
val builder = SpannableStringBuilder(this)
|
|
61
|
+
val startBlockSpans = spannable.getSpans(0, 0, EnrichedBlockSpan::class.java)
|
|
62
|
+
val startParagraphSpans = spannable.getSpans(0, 0, EnrichedParagraphSpan::class.java)
|
|
63
|
+
val endBlockSpans = spannable.getSpans(this.length, this.length, EnrichedBlockSpan::class.java)
|
|
64
|
+
val endParagraphSpans = spannable.getSpans(this.length, this.length, EnrichedParagraphSpan::class.java)
|
|
65
|
+
val (paragraphStart, paragraphEnd) = this.getParagraphBounds(start, end)
|
|
66
|
+
val isNewLineStart = startBlockSpans.isNotEmpty() || startParagraphSpans.isNotEmpty()
|
|
67
|
+
val isNewLineEnd = endBlockSpans.isNotEmpty() || endParagraphSpans.isNotEmpty()
|
|
68
|
+
|
|
69
|
+
if (isNewLineStart && start != paragraphStart) {
|
|
70
|
+
builder.insert(start, "\n")
|
|
71
|
+
finalStart = start + 1
|
|
72
|
+
finalEnd = end + 1
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (isNewLineEnd && end != paragraphEnd) {
|
|
76
|
+
builder.insert(finalEnd, "\n")
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
builder.replace(finalStart, finalEnd, spannable)
|
|
80
|
+
|
|
81
|
+
return builder
|
|
82
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
package com.swmansion.enriched.utils
|
|
2
|
+
|
|
3
|
+
import android.text.SpannableStringBuilder
|
|
4
|
+
|
|
5
|
+
// Removes zero-width spaces from the given range in the SpannableStringBuilder without affecting spans
|
|
6
|
+
fun SpannableStringBuilder.removeZWS(
|
|
7
|
+
start: Int,
|
|
8
|
+
end: Int,
|
|
9
|
+
) {
|
|
10
|
+
for (i in (end - 1) downTo start) {
|
|
11
|
+
if (this[i] == EnrichedConstants.ZWS) {
|
|
12
|
+
delete(i, i + 1)
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
package com.swmansion.enriched.utils
|
|
2
2
|
|
|
3
|
-
import android.text.Spannable
|
|
4
|
-
import android.text.SpannableString
|
|
5
|
-
import android.text.SpannableStringBuilder
|
|
6
3
|
import android.util.Log
|
|
7
|
-
import com.swmansion.enriched.spans.interfaces.EnrichedBlockSpan
|
|
8
|
-
import com.swmansion.enriched.spans.interfaces.EnrichedParagraphSpan
|
|
9
4
|
import org.json.JSONObject
|
|
10
5
|
|
|
11
6
|
fun jsonStringToStringMap(json: String): Map<String, String> {
|
|
@@ -24,68 +19,3 @@ fun jsonStringToStringMap(json: String): Map<String, String> {
|
|
|
24
19
|
|
|
25
20
|
return result
|
|
26
21
|
}
|
|
27
|
-
|
|
28
|
-
fun Spannable.getSafeSpanBoundaries(start: Int, end: Int): Pair<Int, Int> {
|
|
29
|
-
val safeStart = start.coerceAtMost(end).coerceAtLeast(0)
|
|
30
|
-
val safeEnd = end.coerceAtLeast(start).coerceAtMost(this.length)
|
|
31
|
-
|
|
32
|
-
return Pair(safeStart, safeEnd)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
fun Spannable.getParagraphBounds(start: Int, end: Int): Pair<Int, Int> {
|
|
36
|
-
var startPosition = start.coerceAtLeast(0).coerceAtMost(this.length)
|
|
37
|
-
var endPosition = end.coerceAtLeast(0).coerceAtMost(this.length)
|
|
38
|
-
|
|
39
|
-
// Find the start of the paragraph
|
|
40
|
-
while (startPosition > 0 && this[startPosition - 1] != '\n') {
|
|
41
|
-
startPosition--
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// Find the end of the paragraph
|
|
45
|
-
while (endPosition < this.length && this[endPosition] != '\n') {
|
|
46
|
-
endPosition++
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
if (startPosition >= endPosition) {
|
|
50
|
-
// If the start position is equal or greater than the end position, return the same position
|
|
51
|
-
startPosition = endPosition
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
return Pair(startPosition, endPosition)
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
fun Spannable.getParagraphBounds(index: Int): Pair<Int, Int> {
|
|
58
|
-
return this.getParagraphBounds(index, index)
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
fun Spannable.mergeSpannables(start: Int, end: Int, string: String): Spannable {
|
|
62
|
-
return this.mergeSpannables(start, end, SpannableString(string))
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
fun Spannable.mergeSpannables(start: Int, end: Int, spannable: Spannable): Spannable {
|
|
66
|
-
var finalStart = start
|
|
67
|
-
var finalEnd = end
|
|
68
|
-
|
|
69
|
-
val builder = SpannableStringBuilder(this)
|
|
70
|
-
val startBlockSpans = spannable.getSpans(0, 0, EnrichedBlockSpan::class.java)
|
|
71
|
-
val startParagraphSpans = spannable.getSpans(0, 0, EnrichedParagraphSpan::class.java)
|
|
72
|
-
val endBlockSpans = spannable.getSpans(this.length, this.length, EnrichedBlockSpan::class.java)
|
|
73
|
-
val endParagraphSpans = spannable.getSpans(this.length, this.length, EnrichedParagraphSpan::class.java)
|
|
74
|
-
val (paragraphStart, paragraphEnd) = this.getParagraphBounds(start, end)
|
|
75
|
-
val isNewLineStart = startBlockSpans.isNotEmpty() || startParagraphSpans.isNotEmpty()
|
|
76
|
-
val isNewLineEnd = endBlockSpans.isNotEmpty() || endParagraphSpans.isNotEmpty()
|
|
77
|
-
|
|
78
|
-
if (isNewLineStart && start != paragraphStart) {
|
|
79
|
-
builder.insert(start, "\n")
|
|
80
|
-
finalStart = start + 1
|
|
81
|
-
finalEnd = end + 1
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
if (isNewLineEnd && end != paragraphEnd) {
|
|
85
|
-
builder.insert(finalEnd, "\n")
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
builder.replace(finalStart, finalEnd, spannable)
|
|
89
|
-
|
|
90
|
-
return builder
|
|
91
|
-
}
|
|
@@ -13,26 +13,49 @@ import com.swmansion.enriched.spans.interfaces.EnrichedSpan
|
|
|
13
13
|
import com.swmansion.enriched.utils.EnrichedParser
|
|
14
14
|
import com.swmansion.enriched.utils.getSafeSpanBoundaries
|
|
15
15
|
|
|
16
|
-
class EnrichedSpanWatcher(
|
|
16
|
+
class EnrichedSpanWatcher(
|
|
17
|
+
private val view: EnrichedTextInputView,
|
|
18
|
+
) : SpanWatcher {
|
|
17
19
|
private var previousHtml: String? = null
|
|
18
20
|
|
|
19
|
-
override fun onSpanAdded(
|
|
21
|
+
override fun onSpanAdded(
|
|
22
|
+
text: Spannable,
|
|
23
|
+
what: Any,
|
|
24
|
+
start: Int,
|
|
25
|
+
end: Int,
|
|
26
|
+
) {
|
|
20
27
|
updateNextLineLayout(what, text, end)
|
|
21
28
|
updateUnorderedListSpans(what, text, end)
|
|
22
29
|
emitEvent(text, what)
|
|
23
30
|
}
|
|
24
31
|
|
|
25
|
-
override fun onSpanRemoved(
|
|
32
|
+
override fun onSpanRemoved(
|
|
33
|
+
text: Spannable,
|
|
34
|
+
what: Any,
|
|
35
|
+
start: Int,
|
|
36
|
+
end: Int,
|
|
37
|
+
) {
|
|
26
38
|
updateNextLineLayout(what, text, end)
|
|
27
39
|
updateUnorderedListSpans(what, text, end)
|
|
28
40
|
emitEvent(text, what)
|
|
29
41
|
}
|
|
30
42
|
|
|
31
|
-
override fun onSpanChanged(
|
|
43
|
+
override fun onSpanChanged(
|
|
44
|
+
text: Spannable,
|
|
45
|
+
what: Any,
|
|
46
|
+
ostart: Int,
|
|
47
|
+
oend: Int,
|
|
48
|
+
nstart: Int,
|
|
49
|
+
nend: Int,
|
|
50
|
+
) {
|
|
32
51
|
// Do nothing for now
|
|
33
52
|
}
|
|
34
53
|
|
|
35
|
-
private fun updateUnorderedListSpans(
|
|
54
|
+
private fun updateUnorderedListSpans(
|
|
55
|
+
what: Any,
|
|
56
|
+
text: Spannable,
|
|
57
|
+
end: Int,
|
|
58
|
+
) {
|
|
36
59
|
if (what is EnrichedOrderedListSpan) {
|
|
37
60
|
view.listStyles?.updateOrderedListIndexes(text, end)
|
|
38
61
|
}
|
|
@@ -40,8 +63,12 @@ class EnrichedSpanWatcher(private val view: EnrichedTextInputView) : SpanWatcher
|
|
|
40
63
|
|
|
41
64
|
// After adding/removing heading span, we have to manually set empty paragraph span to the following text
|
|
42
65
|
// This allows us to update the layout (as it's not updated automatically - looks like an Android issue)
|
|
43
|
-
private fun updateNextLineLayout(
|
|
44
|
-
|
|
66
|
+
private fun updateNextLineLayout(
|
|
67
|
+
what: Any,
|
|
68
|
+
text: Spannable,
|
|
69
|
+
end: Int,
|
|
70
|
+
) {
|
|
71
|
+
class EmptySpan : ParagraphStyle
|
|
45
72
|
|
|
46
73
|
if (what is EnrichedHeadingSpan) {
|
|
47
74
|
val finalStart = (end + 1)
|
|
@@ -51,7 +78,10 @@ class EnrichedSpanWatcher(private val view: EnrichedTextInputView) : SpanWatcher
|
|
|
51
78
|
}
|
|
52
79
|
}
|
|
53
80
|
|
|
54
|
-
fun emitEvent(
|
|
81
|
+
fun emitEvent(
|
|
82
|
+
s: Spannable,
|
|
83
|
+
what: Any?,
|
|
84
|
+
) {
|
|
55
85
|
// Do not parse spannable and emit event if onChangeHtml is not provided
|
|
56
86
|
if (!view.shouldEmitHtml) return
|
|
57
87
|
|
|
@@ -65,11 +95,13 @@ class EnrichedSpanWatcher(private val view: EnrichedTextInputView) : SpanWatcher
|
|
|
65
95
|
val context = view.context as ReactContext
|
|
66
96
|
val surfaceId = UIManagerHelper.getSurfaceId(context)
|
|
67
97
|
val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, view.id)
|
|
68
|
-
dispatcher?.dispatchEvent(
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
98
|
+
dispatcher?.dispatchEvent(
|
|
99
|
+
OnChangeHtmlEvent(
|
|
100
|
+
surfaceId,
|
|
101
|
+
view.id,
|
|
102
|
+
html,
|
|
103
|
+
view.experimentalSynchronousEvents,
|
|
104
|
+
),
|
|
105
|
+
)
|
|
74
106
|
}
|
|
75
107
|
}
|
|
@@ -7,15 +7,29 @@ import com.facebook.react.uimanager.UIManagerHelper
|
|
|
7
7
|
import com.swmansion.enriched.EnrichedTextInputView
|
|
8
8
|
import com.swmansion.enriched.events.OnChangeTextEvent
|
|
9
9
|
|
|
10
|
-
class EnrichedTextWatcher(
|
|
10
|
+
class EnrichedTextWatcher(
|
|
11
|
+
private val view: EnrichedTextInputView,
|
|
12
|
+
) : TextWatcher {
|
|
11
13
|
private var endCursorPosition: Int = 0
|
|
14
|
+
private var startCursorPosition: Int = 0
|
|
12
15
|
private var previousTextLength: Int = 0
|
|
13
16
|
|
|
14
|
-
override fun beforeTextChanged(
|
|
17
|
+
override fun beforeTextChanged(
|
|
18
|
+
s: CharSequence?,
|
|
19
|
+
start: Int,
|
|
20
|
+
count: Int,
|
|
21
|
+
after: Int,
|
|
22
|
+
) {
|
|
15
23
|
previousTextLength = s?.length ?: 0
|
|
16
24
|
}
|
|
17
25
|
|
|
18
|
-
override fun onTextChanged(
|
|
26
|
+
override fun onTextChanged(
|
|
27
|
+
s: CharSequence?,
|
|
28
|
+
start: Int,
|
|
29
|
+
before: Int,
|
|
30
|
+
count: Int,
|
|
31
|
+
) {
|
|
32
|
+
startCursorPosition = start
|
|
19
33
|
endCursorPosition = start + count
|
|
20
34
|
view.layoutManager.invalidateLayout()
|
|
21
35
|
view.isRemovingMany = !view.isDuringTransaction && before > count + 1
|
|
@@ -33,19 +47,28 @@ class EnrichedTextWatcher(private val view: EnrichedTextInputView) : TextWatcher
|
|
|
33
47
|
view.inlineStyles?.afterTextChanged(s, endCursorPosition)
|
|
34
48
|
view.paragraphStyles?.afterTextChanged(s, endCursorPosition, previousTextLength)
|
|
35
49
|
view.listStyles?.afterTextChanged(s, endCursorPosition, previousTextLength)
|
|
36
|
-
view.parametrizedStyles?.afterTextChanged(s, endCursorPosition)
|
|
50
|
+
view.parametrizedStyles?.afterTextChanged(s, startCursorPosition, endCursorPosition)
|
|
37
51
|
}
|
|
38
52
|
|
|
39
|
-
private fun
|
|
53
|
+
private fun emitChangeText(editable: Editable) {
|
|
54
|
+
if (!view.shouldEmitOnChangeText) {
|
|
55
|
+
return
|
|
56
|
+
}
|
|
40
57
|
val context = view.context as ReactContext
|
|
41
58
|
val surfaceId = UIManagerHelper.getSurfaceId(context)
|
|
42
59
|
val dispatcher = UIManagerHelper.getEventDispatcherForReactTag(context, view.id)
|
|
43
|
-
dispatcher?.dispatchEvent(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
60
|
+
dispatcher?.dispatchEvent(
|
|
61
|
+
OnChangeTextEvent(
|
|
62
|
+
surfaceId,
|
|
63
|
+
view.id,
|
|
64
|
+
editable,
|
|
65
|
+
view.experimentalSynchronousEvents,
|
|
66
|
+
),
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private fun emitEvents(s: Editable) {
|
|
71
|
+
emitChangeText(s)
|
|
49
72
|
view.spanWatcher?.emitEvent(s, null)
|
|
50
73
|
}
|
|
51
74
|
}
|
|
@@ -11,6 +11,12 @@ set(LIB_ANDROID_GENERATED_COMPONENTS_DIR ${LIB_ANDROID_GENERATED_JNI_DIR}/react/
|
|
|
11
11
|
file(GLOB LIB_MODULE_SRCS CONFIGURE_DEPENDS *.cpp react/renderer/components/${LIB_LITERAL}/*.cpp)
|
|
12
12
|
file(GLOB LIB_CODEGEN_SRCS CONFIGURE_DEPENDS ${LIB_ANDROID_GENERATED_COMPONENTS_DIR}/*.cpp)
|
|
13
13
|
|
|
14
|
+
if(NOT DEFINED REACT_NATIVE_MINOR_VERSION)
|
|
15
|
+
set(REACT_NATIVE_MINOR_VERSION ${ReactAndroid_VERSION_MINOR})
|
|
16
|
+
endif()
|
|
17
|
+
|
|
18
|
+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DREACT_NATIVE_MINOR_VERSION=${REACT_NATIVE_MINOR_VERSION}")
|
|
19
|
+
|
|
14
20
|
add_library(
|
|
15
21
|
${LIB_TARGET_NAME}
|
|
16
22
|
SHARED
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
|
|
2
2
|
/**
|
|
3
|
-
* This code was generated by
|
|
3
|
+
* This code was generated by
|
|
4
|
+
* [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
|
4
5
|
*
|
|
5
|
-
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
6
|
-
* once the code is regenerated.
|
|
6
|
+
* Do not edit this file as changes may cause incorrect behavior and will be
|
|
7
|
+
* lost once the code is regenerated.
|
|
7
8
|
*
|
|
8
9
|
* @generated by codegen project: GenerateModuleJniCpp.js
|
|
9
10
|
*/
|
|
@@ -12,9 +13,8 @@
|
|
|
12
13
|
|
|
13
14
|
namespace facebook::react {
|
|
14
15
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
std::shared_ptr<TurboModule> RNEnrichedTextInputViewSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms) {
|
|
16
|
+
std::shared_ptr<TurboModule> RNEnrichedTextInputViewSpec_ModuleProvider(
|
|
17
|
+
const std::string &moduleName, const JavaTurboModule::InitParams ¶ms) {
|
|
18
18
|
|
|
19
19
|
return nullptr;
|
|
20
20
|
}
|