react-native-enriched 0.2.0 → 0.2.1
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 +1 -5
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +3 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +1 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.cpp +10 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.h +7 -0
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt +92 -0
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt +1 -1
- package/android/src/main/java/com/swmansion/enriched/events/OnRequestHtmlResultEvent.kt +33 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBlockQuoteSpan.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedCodeBlockSpan.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedImageSpan.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedInlineCodeSpan.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedMentionSpan.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedOrderedListSpan.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedSpans.kt +9 -3
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnorderedListSpan.kt +6 -0
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt +4 -0
- package/android/src/main/java/com/swmansion/enriched/styles/HtmlStyle.kt +78 -0
- package/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt +80 -4
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedParser.java +8 -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 +12 -13
- package/ios/EnrichedTextInputView.h +25 -13
- package/ios/EnrichedTextInputView.mm +872 -581
- package/ios/attachments/ImageAttachment.h +10 -0
- package/ios/attachments/ImageAttachment.mm +34 -0
- package/ios/attachments/MediaAttachment.h +23 -0
- package/ios/attachments/MediaAttachment.mm +31 -0
- package/ios/config/InputConfig.h +6 -6
- package/ios/config/InputConfig.mm +39 -33
- package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.cpp +10 -0
- package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.h +7 -0
- package/ios/generated/RNEnrichedTextInputViewSpec/RCTComponentViewHelpers.h +21 -0
- package/ios/inputParser/InputParser.h +5 -5
- package/ios/inputParser/InputParser.mm +789 -378
- package/ios/inputTextView/InputTextView.h +1 -1
- package/ios/inputTextView/InputTextView.mm +100 -59
- 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 +95 -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/HeadingStyleBase.mm +129 -84
- package/ios/styles/ImageStyle.mm +75 -73
- package/ios/styles/InlineCodeStyle.mm +148 -85
- package/ios/styles/ItalicStyle.mm +76 -52
- package/ios/styles/LinkStyle.mm +348 -227
- 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/BaseStyleProtocol.h +2 -2
- package/ios/utils/ColorExtension.mm +7 -5
- package/ios/utils/FontExtension.mm +42 -27
- package/ios/utils/LayoutManagerExtension.h +1 -1
- package/ios/utils/LayoutManagerExtension.mm +280 -170
- package/ios/utils/MentionParams.h +0 -1
- package/ios/utils/MentionStyleProps.h +1 -1
- package/ios/utils/MentionStyleProps.mm +27 -20
- package/ios/utils/OccurenceUtils.h +42 -42
- package/ios/utils/OccurenceUtils.mm +142 -119
- package/ios/utils/ParagraphAttributesUtils.h +6 -2
- package/ios/utils/ParagraphAttributesUtils.mm +115 -71
- package/ios/utils/ParagraphsUtils.h +2 -1
- package/ios/utils/ParagraphsUtils.mm +40 -26
- package/ios/utils/StringExtension.h +1 -1
- package/ios/utils/StringExtension.mm +19 -16
- package/ios/utils/StyleHeaders.h +27 -15
- 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 +39 -1
- package/lib/module/EnrichedTextInput.js.map +1 -1
- package/lib/module/EnrichedTextInputNativeComponent.ts +11 -0
- package/lib/typescript/src/EnrichedTextInput.d.ts +1 -0
- package/lib/typescript/src/EnrichedTextInput.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts +6 -0
- package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts.map +1 -1
- package/package.json +8 -1
- package/src/EnrichedTextInput.tsx +45 -0
- package/src/EnrichedTextInputNativeComponent.ts +11 -0
|
@@ -5,9 +5,8 @@ import android.text.Spannable
|
|
|
5
5
|
import android.text.SpannableStringBuilder
|
|
6
6
|
import android.util.Log
|
|
7
7
|
import com.swmansion.enriched.EnrichedTextInputView
|
|
8
|
-
import com.swmansion.enriched.spans.EnrichedBlockQuoteSpan
|
|
9
|
-
import com.swmansion.enriched.spans.EnrichedCodeBlockSpan
|
|
10
8
|
import com.swmansion.enriched.spans.EnrichedSpans
|
|
9
|
+
import com.swmansion.enriched.spans.interfaces.EnrichedSpan
|
|
11
10
|
import com.swmansion.enriched.utils.getParagraphBounds
|
|
12
11
|
import com.swmansion.enriched.utils.getSafeSpanBoundaries
|
|
13
12
|
|
|
@@ -194,16 +193,84 @@ class ParagraphStyles(private val view: EnrichedTextInputView) {
|
|
|
194
193
|
s.setSpan(span, safeStart, safeEnd, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE)
|
|
195
194
|
}
|
|
196
195
|
|
|
196
|
+
private fun handleConflictsDuringNewlineDeletion(s: Editable, style: String, paragraphStart: Int, paragraphEnd: Int): Boolean {
|
|
197
|
+
val spanState = view.spanState ?: return false
|
|
198
|
+
val mergingConfig = EnrichedSpans.getMergingConfigForStyle(style, view.htmlStyle) ?: return false
|
|
199
|
+
var isConflicting = false
|
|
200
|
+
val stylesToCheck = mergingConfig.blockingStyles + mergingConfig.conflictingStyles
|
|
201
|
+
|
|
202
|
+
for (styleToCheck in stylesToCheck) {
|
|
203
|
+
val conflictingType = EnrichedSpans.allSpans[styleToCheck]?.clazz ?: continue
|
|
204
|
+
|
|
205
|
+
val spans = s.getSpans(paragraphStart, paragraphEnd, conflictingType)
|
|
206
|
+
if (spans.isEmpty()) {
|
|
207
|
+
continue
|
|
208
|
+
}
|
|
209
|
+
isConflicting = true
|
|
210
|
+
|
|
211
|
+
val isParagraphStyle = EnrichedSpans.paragraphSpans[styleToCheck] != null
|
|
212
|
+
if (!isParagraphStyle) {
|
|
213
|
+
continue
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
for (span in spans) {
|
|
217
|
+
extendStyleOnWholeParagraph(s, span as EnrichedSpan, conflictingType, paragraphEnd)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
if (isConflicting) {
|
|
222
|
+
val styleStart = spanState.getStart(style) ?: return false
|
|
223
|
+
spanState.setStart(style, null)
|
|
224
|
+
removeStyle(style, styleStart, paragraphEnd)
|
|
225
|
+
return true
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
return false
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
private fun deleteConflictingAndBlockingStyles(s: Editable, style: String, paragraphStart: Int, paragraphEnd: Int) {
|
|
233
|
+
val mergingConfig = EnrichedSpans.getMergingConfigForStyle(style, view.htmlStyle) ?: return
|
|
234
|
+
val stylesToCheck = mergingConfig.blockingStyles + mergingConfig.conflictingStyles
|
|
235
|
+
|
|
236
|
+
for (styleToCheck in stylesToCheck) {
|
|
237
|
+
val conflictingType = EnrichedSpans.allSpans[styleToCheck]?.clazz ?: continue
|
|
238
|
+
|
|
239
|
+
val spans = s.getSpans(paragraphStart, paragraphEnd, conflictingType)
|
|
240
|
+
for (span in spans) {
|
|
241
|
+
s.removeSpan(span)
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private fun <T>extendStyleOnWholeParagraph(s: Editable, span: EnrichedSpan, type: Class<T>, paragraphEnd: Int) {
|
|
247
|
+
val currStyleStart = s.getSpanStart(span)
|
|
248
|
+
s.removeSpan(span)
|
|
249
|
+
val (safeStart, safeEnd) = s.getSafeSpanBoundaries(currStyleStart, paragraphEnd)
|
|
250
|
+
setSpan(s, type, safeStart, safeEnd)
|
|
251
|
+
}
|
|
252
|
+
|
|
197
253
|
fun afterTextChanged(s: Editable, endPosition: Int, previousTextLength: Int) {
|
|
198
254
|
var endCursorPosition = endPosition
|
|
199
255
|
val isBackspace = s.length < previousTextLength
|
|
200
256
|
val isNewLine = endCursorPosition == 0 || endCursorPosition > 0 && s[endCursorPosition - 1] == '\n'
|
|
257
|
+
val spanState = view.spanState ?: return
|
|
201
258
|
|
|
202
259
|
for ((style, config) in EnrichedSpans.paragraphSpans) {
|
|
203
|
-
val spanState = view.spanState ?: continue
|
|
204
260
|
val styleStart = spanState.getStart(style)
|
|
205
261
|
|
|
206
262
|
if (styleStart == null) {
|
|
263
|
+
if (isBackspace) {
|
|
264
|
+
val (start, end) = s.getParagraphBounds(endCursorPosition)
|
|
265
|
+
val spans = s.getSpans(start, end, config.clazz)
|
|
266
|
+
|
|
267
|
+
for (span in spans) {
|
|
268
|
+
// handle conflicts when entering paragraph with some paragraph style applied
|
|
269
|
+
deleteConflictingAndBlockingStyles(s, style, start, end)
|
|
270
|
+
extendStyleOnWholeParagraph(s, span as EnrichedSpan, config.clazz, end)
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
207
274
|
if (config.isContinuous) {
|
|
208
275
|
mergeAdjacentStyleSpans(s, endCursorPosition, config.clazz)
|
|
209
276
|
}
|
|
@@ -218,7 +285,7 @@ class ParagraphStyles(private val view: EnrichedTextInputView) {
|
|
|
218
285
|
|
|
219
286
|
if (isBackspace) {
|
|
220
287
|
endCursorPosition -= 1
|
|
221
|
-
|
|
288
|
+
spanState.setStart(style, null)
|
|
222
289
|
} else {
|
|
223
290
|
s.insert(endCursorPosition, "\u200B")
|
|
224
291
|
endCursorPosition += 1
|
|
@@ -226,6 +293,15 @@ class ParagraphStyles(private val view: EnrichedTextInputView) {
|
|
|
226
293
|
}
|
|
227
294
|
|
|
228
295
|
var (start, end) = s.getParagraphBounds(styleStart, endCursorPosition)
|
|
296
|
+
|
|
297
|
+
// handle conflicts when deleting newline from paragraph style (going back to previous line)
|
|
298
|
+
if (isBackspace && styleStart != start) {
|
|
299
|
+
val isConflicting = handleConflictsDuringNewlineDeletion(s, style, start, end)
|
|
300
|
+
if (isConflicting) {
|
|
301
|
+
continue
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
|
|
229
305
|
val isNotEndLineSpan = isSpanEnabledInNextLine(s, end, config.clazz)
|
|
230
306
|
val spans = s.getSpans(start, end, config.clazz)
|
|
231
307
|
|
|
@@ -105,6 +105,14 @@ public class EnrichedParser {
|
|
|
105
105
|
String normalizedBlockQuote = normalizedCodeBlock.replaceAll("</blockquote>\\n<br>", "</blockquote>");
|
|
106
106
|
return "<html>\n" + normalizedBlockQuote + "</html>";
|
|
107
107
|
}
|
|
108
|
+
|
|
109
|
+
public static String toHtmlWithDefault(CharSequence text) {
|
|
110
|
+
if (text instanceof Spanned) {
|
|
111
|
+
return toHtml((Spanned) text);
|
|
112
|
+
}
|
|
113
|
+
return "<html>\n<p></p>\n</html>";
|
|
114
|
+
}
|
|
115
|
+
|
|
108
116
|
/**
|
|
109
117
|
* Returns an HTML escaped representation of the given plain text.
|
|
110
118
|
*/
|
|
@@ -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
|
}
|
|
@@ -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: GenerateModuleJniH.js
|
|
9
10
|
*/
|
|
@@ -18,9 +19,8 @@
|
|
|
18
19
|
|
|
19
20
|
namespace facebook::react {
|
|
20
21
|
|
|
21
|
-
|
|
22
|
-
|
|
23
22
|
JSI_EXPORT
|
|
24
|
-
std::shared_ptr<TurboModule> RNEnrichedTextInputViewSpec_ModuleProvider(
|
|
23
|
+
std::shared_ptr<TurboModule> RNEnrichedTextInputViewSpec_ModuleProvider(
|
|
24
|
+
const std::string &moduleName, const JavaTurboModule::InitParams ¶ms);
|
|
25
25
|
|
|
26
26
|
} // namespace facebook::react
|
|
@@ -8,28 +8,28 @@
|
|
|
8
8
|
namespace facebook::react {
|
|
9
9
|
|
|
10
10
|
class EnrichedTextInputComponentDescriptor final
|
|
11
|
-
|
|
11
|
+
: public ConcreteComponentDescriptor<EnrichedTextInputShadowNode> {
|
|
12
12
|
public:
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
13
|
+
EnrichedTextInputComponentDescriptor(
|
|
14
|
+
const ComponentDescriptorParameters ¶meters)
|
|
15
|
+
: ConcreteComponentDescriptor(parameters),
|
|
16
|
+
measurementsManager_(
|
|
17
|
+
std::make_shared<EnrichedTextInputMeasurementManager>(
|
|
18
|
+
contextContainer_)) {}
|
|
19
|
+
|
|
20
|
+
void adopt(ShadowNode &shadowNode) const override {
|
|
21
|
+
ConcreteComponentDescriptor::adopt(shadowNode);
|
|
22
|
+
auto &editorShadowNode =
|
|
23
|
+
static_cast<EnrichedTextInputShadowNode &>(shadowNode);
|
|
24
|
+
|
|
25
|
+
// `EnrichedTextInputShadowNode` uses
|
|
26
|
+
// `EnrichedTextInputMeasurementManager` to provide measurements to Yoga.
|
|
27
|
+
editorShadowNode.setMeasurementsManager(measurementsManager_);
|
|
28
|
+
}
|
|
28
29
|
|
|
29
30
|
private:
|
|
30
|
-
|
|
31
|
-
|
|
31
|
+
const std::shared_ptr<EnrichedTextInputMeasurementManager>
|
|
32
|
+
measurementsManager_;
|
|
32
33
|
};
|
|
33
34
|
|
|
34
35
|
} // namespace facebook::react
|
|
35
|
-
|
|
@@ -9,56 +9,45 @@ using namespace facebook::jni;
|
|
|
9
9
|
|
|
10
10
|
namespace facebook::react {
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
componentName.get(),
|
|
53
|
-
extraDataRM.get(),
|
|
54
|
-
propsRM.get(),
|
|
55
|
-
nullptr,
|
|
56
|
-
minimumSize.width,
|
|
57
|
-
maximumSize.width,
|
|
58
|
-
minimumSize.height,
|
|
59
|
-
maximumSize.height));
|
|
60
|
-
|
|
61
|
-
return measurement;
|
|
62
|
-
}
|
|
12
|
+
Size EnrichedTextInputMeasurementManager::measure(
|
|
13
|
+
SurfaceId surfaceId, int viewTag, const EnrichedTextInputViewProps &props,
|
|
14
|
+
LayoutConstraints layoutConstraints) const {
|
|
15
|
+
const jni::global_ref<jobject> &fabricUIManager =
|
|
16
|
+
contextContainer_->at<jni::global_ref<jobject>>("FabricUIManager");
|
|
17
|
+
|
|
18
|
+
static const auto measure =
|
|
19
|
+
facebook::jni::findClassStatic(
|
|
20
|
+
"com/facebook/react/fabric/FabricUIManager")
|
|
21
|
+
->getMethod<jlong(jint, jstring, ReadableMap::javaobject,
|
|
22
|
+
ReadableMap::javaobject, ReadableMap::javaobject,
|
|
23
|
+
jfloat, jfloat, jfloat, jfloat)>("measure");
|
|
24
|
+
|
|
25
|
+
auto minimumSize = layoutConstraints.minimumSize;
|
|
26
|
+
auto maximumSize = layoutConstraints.maximumSize;
|
|
27
|
+
|
|
28
|
+
local_ref<JString> componentName = make_jstring("EnrichedTextInputView");
|
|
29
|
+
|
|
30
|
+
// Prepare extraData map with viewTag
|
|
31
|
+
folly::dynamic extraData = folly::dynamic::object();
|
|
32
|
+
extraData["viewTag"] = viewTag;
|
|
33
|
+
local_ref<ReadableNativeMap::javaobject> extraDataRNM =
|
|
34
|
+
ReadableNativeMap::newObjectCxxArgs(extraData);
|
|
35
|
+
local_ref<ReadableMap::javaobject> extraDataRM =
|
|
36
|
+
make_local(reinterpret_cast<ReadableMap::javaobject>(extraDataRNM.get()));
|
|
37
|
+
|
|
38
|
+
// Prepare layout metrics affecting props
|
|
39
|
+
auto serializedProps = toDynamic(props);
|
|
40
|
+
local_ref<ReadableNativeMap::javaobject> propsRNM =
|
|
41
|
+
ReadableNativeMap::newObjectCxxArgs(serializedProps);
|
|
42
|
+
local_ref<ReadableMap::javaobject> propsRM =
|
|
43
|
+
make_local(reinterpret_cast<ReadableMap::javaobject>(propsRNM.get()));
|
|
44
|
+
|
|
45
|
+
auto measurement = yogaMeassureToSize(
|
|
46
|
+
measure(fabricUIManager, surfaceId, componentName.get(),
|
|
47
|
+
extraDataRM.get(), propsRM.get(), nullptr, minimumSize.width,
|
|
48
|
+
maximumSize.width, minimumSize.height, maximumSize.height));
|
|
49
|
+
|
|
50
|
+
return measurement;
|
|
51
|
+
}
|
|
63
52
|
|
|
64
53
|
} // namespace facebook::react
|
|
@@ -2,26 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
#include "ComponentDescriptors.h"
|
|
4
4
|
|
|
5
|
-
#include <react/utils/ContextContainer.h>
|
|
6
|
-
#include <react/renderer/core/LayoutConstraints.h>
|
|
7
5
|
#include <react/renderer/components/RNEnrichedTextInputViewSpec/Props.h>
|
|
6
|
+
#include <react/renderer/core/LayoutConstraints.h>
|
|
7
|
+
#include <react/utils/ContextContainer.h>
|
|
8
8
|
|
|
9
9
|
namespace facebook::react {
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
11
|
+
class EnrichedTextInputMeasurementManager {
|
|
12
|
+
public:
|
|
13
|
+
EnrichedTextInputMeasurementManager(
|
|
14
|
+
const std::shared_ptr<const ContextContainer> &contextContainer)
|
|
15
|
+
: contextContainer_(contextContainer) {}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
const EnrichedTextInputViewProps& props,
|
|
21
|
-
LayoutConstraints layoutConstraints) const;
|
|
17
|
+
Size measure(SurfaceId surfaceId, int viewTag,
|
|
18
|
+
const EnrichedTextInputViewProps &props,
|
|
19
|
+
LayoutConstraints layoutConstraints) const;
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
private:
|
|
22
|
+
const std::shared_ptr<const ContextContainer> contextContainer_;
|
|
23
|
+
};
|
|
26
24
|
|
|
27
25
|
} // namespace facebook::react
|
|
@@ -4,30 +4,32 @@
|
|
|
4
4
|
|
|
5
5
|
namespace facebook::react {
|
|
6
6
|
extern const char EnrichedTextInputComponentName[] = "EnrichedTextInputView";
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
void EnrichedTextInputShadowNode::setMeasurementsManager(
|
|
8
|
+
const std::shared_ptr<EnrichedTextInputMeasurementManager>
|
|
9
|
+
&measurementsManager) {
|
|
10
|
+
ensureUnsealed();
|
|
11
|
+
measurementsManager_ = measurementsManager;
|
|
12
|
+
}
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
// Mark layout as dirty after state has been updated
|
|
15
|
+
// Once layout is marked as dirty, `measureContent` will be called in order to
|
|
16
|
+
// recalculate layout
|
|
17
|
+
void EnrichedTextInputShadowNode::dirtyLayoutIfNeeded() {
|
|
18
|
+
const auto state = this->getStateData();
|
|
19
|
+
const auto counter = state.getForceHeightRecalculationCounter();
|
|
19
20
|
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
if (forceHeightRecalculationCounter_ != counter) {
|
|
22
|
+
forceHeightRecalculationCounter_ = counter;
|
|
22
23
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
dirtyLayout();
|
|
25
|
+
}
|
|
26
|
+
}
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
Size EnrichedTextInputShadowNode::measureContent(
|
|
29
|
+
const LayoutContext &layoutContext,
|
|
30
|
+
const LayoutConstraints &layoutConstraints) const {
|
|
31
|
+
return measurementsManager_->measure(getSurfaceId(), getTag(),
|
|
32
|
+
getConcreteProps(), layoutConstraints);
|
|
33
|
+
}
|
|
32
34
|
|
|
33
35
|
} // namespace facebook::react
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
#include "EnrichedTextInputMeasurementManager.h"
|
|
4
4
|
#include "EnrichedTextInputState.h"
|
|
5
5
|
|
|
6
|
-
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
7
|
-
#include <react/renderer/components/RNEnrichedTextInputViewSpec/Props.h>
|
|
8
6
|
#include <react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.h>
|
|
7
|
+
#include <react/renderer/components/RNEnrichedTextInputViewSpec/Props.h>
|
|
8
|
+
#include <react/renderer/components/view/ConcreteViewShadowNode.h>
|
|
9
9
|
|
|
10
10
|
namespace facebook::react {
|
|
11
11
|
|
|
@@ -13,42 +13,41 @@ JSI_EXPORT extern const char EnrichedTextInputComponentName[];
|
|
|
13
13
|
/*
|
|
14
14
|
* `ShadowNode` for <EnrichedTextInputView> component.
|
|
15
15
|
*/
|
|
16
|
-
class EnrichedTextInputShadowNode final
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
EnrichedTextInputState> {
|
|
16
|
+
class EnrichedTextInputShadowNode final
|
|
17
|
+
: public ConcreteViewShadowNode<
|
|
18
|
+
EnrichedTextInputComponentName, EnrichedTextInputViewProps,
|
|
19
|
+
EnrichedTextInputViewEventEmitter, EnrichedTextInputState> {
|
|
21
20
|
public:
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
21
|
+
using ConcreteViewShadowNode::ConcreteViewShadowNode;
|
|
22
|
+
|
|
23
|
+
// This constructor is called when we "update" shadow node, e.g. after
|
|
24
|
+
// updating shadow node's state
|
|
25
|
+
EnrichedTextInputShadowNode(ShadowNode const &sourceShadowNode,
|
|
26
|
+
ShadowNodeFragment const &fragment)
|
|
27
|
+
: ConcreteViewShadowNode(sourceShadowNode, fragment) {
|
|
28
|
+
dirtyLayoutIfNeeded();
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
static ShadowNodeTraits BaseTraits() {
|
|
32
|
+
auto traits = ConcreteViewShadowNode::BaseTraits();
|
|
33
|
+
traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
|
|
34
|
+
traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode);
|
|
35
|
+
return traits;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Associates a shared `EnrichedTextInputMeasurementManager` with the node.
|
|
39
|
+
void setMeasurementsManager(
|
|
40
|
+
const std::shared_ptr<EnrichedTextInputMeasurementManager>
|
|
41
|
+
&measurementsManager);
|
|
42
|
+
|
|
43
|
+
void dirtyLayoutIfNeeded();
|
|
44
|
+
|
|
45
|
+
Size
|
|
46
|
+
measureContent(const LayoutContext &layoutContext,
|
|
47
|
+
const LayoutConstraints &layoutConstraints) const override;
|
|
49
48
|
|
|
50
49
|
private:
|
|
51
|
-
|
|
52
|
-
|
|
50
|
+
int forceHeightRecalculationCounter_;
|
|
51
|
+
std::shared_ptr<EnrichedTextInputMeasurementManager> measurementsManager_;
|
|
53
52
|
};
|
|
54
53
|
} // namespace facebook::react
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
namespace facebook::react {
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
5
|
+
int EnrichedTextInputState::getForceHeightRecalculationCounter() const {
|
|
6
|
+
return forceHeightRecalculationCounter_;
|
|
9
7
|
}
|
|
8
|
+
|
|
9
|
+
} // namespace facebook::react
|
|
@@ -4,22 +4,21 @@
|
|
|
4
4
|
|
|
5
5
|
namespace facebook::react {
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
: forceHeightRecalculationCounter_(0) {}
|
|
7
|
+
class EnrichedTextInputState {
|
|
8
|
+
public:
|
|
9
|
+
EnrichedTextInputState() : forceHeightRecalculationCounter_(0) {}
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
// Used by Kotlin to set current text value
|
|
12
|
+
EnrichedTextInputState(EnrichedTextInputState const &previousState,
|
|
13
|
+
folly::dynamic data)
|
|
14
|
+
: forceHeightRecalculationCounter_(
|
|
15
|
+
(int)data["forceHeightRecalculationCounter"].getInt()){};
|
|
16
|
+
folly::dynamic getDynamic() const { return {}; };
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
int getForceHeightRecalculationCounter() const;
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
private:
|
|
21
|
+
const int forceHeightRecalculationCounter_{};
|
|
22
|
+
};
|
|
24
23
|
|
|
25
24
|
} // namespace facebook::react
|
|
@@ -2,25 +2,24 @@
|
|
|
2
2
|
|
|
3
3
|
#include <folly/dynamic.h>
|
|
4
4
|
#include <react/renderer/components/FBReactNativeSpec/Props.h>
|
|
5
|
-
#include <react/renderer/core/propsConversions.h>
|
|
6
5
|
#include <react/renderer/components/RNEnrichedTextInputViewSpec/Props.h>
|
|
6
|
+
#include <react/renderer/core/propsConversions.h>
|
|
7
7
|
|
|
8
8
|
namespace facebook::react {
|
|
9
9
|
|
|
10
10
|
#ifdef RN_SERIALIZABLE_STATE
|
|
11
|
-
inline folly::dynamic toDynamic(const EnrichedTextInputViewProps &props)
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
serializedProps["htmlStyle"] = toDynamic(props.htmlStyle);
|
|
11
|
+
inline folly::dynamic toDynamic(const EnrichedTextInputViewProps &props) {
|
|
12
|
+
// Serialize only metrics affecting props
|
|
13
|
+
folly::dynamic serializedProps = folly::dynamic::object();
|
|
14
|
+
serializedProps["defaultValue"] = props.defaultValue;
|
|
15
|
+
serializedProps["placeholder"] = props.placeholder;
|
|
16
|
+
serializedProps["fontSize"] = props.fontSize;
|
|
17
|
+
serializedProps["fontWeight"] = props.fontWeight;
|
|
18
|
+
serializedProps["fontStyle"] = props.fontStyle;
|
|
19
|
+
serializedProps["fontFamily"] = props.fontFamily;
|
|
20
|
+
serializedProps["htmlStyle"] = toDynamic(props.htmlStyle);
|
|
22
21
|
|
|
23
|
-
|
|
22
|
+
return serializedProps;
|
|
24
23
|
}
|
|
25
24
|
#endif
|
|
26
25
|
|