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.
Files changed (107) hide show
  1. package/README.md +1 -5
  2. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +3 -0
  3. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +1 -0
  4. package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.cpp +10 -0
  5. package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.h +7 -0
  6. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt +92 -0
  7. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt +6 -0
  8. package/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt +1 -1
  9. package/android/src/main/java/com/swmansion/enriched/events/OnRequestHtmlResultEvent.kt +33 -0
  10. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBlockQuoteSpan.kt +6 -0
  11. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt +6 -0
  12. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedCodeBlockSpan.kt +6 -0
  13. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt +6 -0
  14. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt +6 -0
  15. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt +6 -0
  16. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedImageSpan.kt +5 -0
  17. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedInlineCodeSpan.kt +6 -0
  18. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt +5 -0
  19. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt +6 -0
  20. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedMentionSpan.kt +6 -0
  21. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedOrderedListSpan.kt +6 -0
  22. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedSpans.kt +9 -3
  23. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt +5 -0
  24. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt +5 -0
  25. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnorderedListSpan.kt +6 -0
  26. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt +4 -0
  27. package/android/src/main/java/com/swmansion/enriched/styles/HtmlStyle.kt +78 -0
  28. package/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt +80 -4
  29. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedParser.java +8 -0
  30. package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp +6 -6
  31. package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.h +6 -6
  32. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputComponentDescriptor.h +19 -19
  33. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.cpp +40 -51
  34. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.h +13 -15
  35. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.cpp +23 -21
  36. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.h +35 -36
  37. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.cpp +4 -4
  38. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.h +13 -14
  39. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/conversions.h +12 -13
  40. package/ios/EnrichedTextInputView.h +25 -13
  41. package/ios/EnrichedTextInputView.mm +872 -581
  42. package/ios/attachments/ImageAttachment.h +10 -0
  43. package/ios/attachments/ImageAttachment.mm +34 -0
  44. package/ios/attachments/MediaAttachment.h +23 -0
  45. package/ios/attachments/MediaAttachment.mm +31 -0
  46. package/ios/config/InputConfig.h +6 -6
  47. package/ios/config/InputConfig.mm +39 -33
  48. package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.cpp +10 -0
  49. package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.h +7 -0
  50. package/ios/generated/RNEnrichedTextInputViewSpec/RCTComponentViewHelpers.h +21 -0
  51. package/ios/inputParser/InputParser.h +5 -5
  52. package/ios/inputParser/InputParser.mm +789 -378
  53. package/ios/inputTextView/InputTextView.h +1 -1
  54. package/ios/inputTextView/InputTextView.mm +100 -59
  55. package/ios/internals/EnrichedTextInputViewComponentDescriptor.h +11 -9
  56. package/ios/internals/EnrichedTextInputViewShadowNode.h +28 -25
  57. package/ios/internals/EnrichedTextInputViewShadowNode.mm +45 -40
  58. package/ios/internals/EnrichedTextInputViewState.h +3 -1
  59. package/ios/styles/BlockQuoteStyle.mm +189 -118
  60. package/ios/styles/BoldStyle.mm +95 -63
  61. package/ios/styles/CodeBlockStyle.mm +204 -128
  62. package/ios/styles/H1Style.mm +10 -4
  63. package/ios/styles/H2Style.mm +10 -4
  64. package/ios/styles/H3Style.mm +10 -4
  65. package/ios/styles/HeadingStyleBase.mm +129 -84
  66. package/ios/styles/ImageStyle.mm +75 -73
  67. package/ios/styles/InlineCodeStyle.mm +148 -85
  68. package/ios/styles/ItalicStyle.mm +76 -52
  69. package/ios/styles/LinkStyle.mm +348 -227
  70. package/ios/styles/MentionStyle.mm +363 -246
  71. package/ios/styles/OrderedListStyle.mm +171 -106
  72. package/ios/styles/StrikethroughStyle.mm +52 -35
  73. package/ios/styles/UnderlineStyle.mm +68 -46
  74. package/ios/styles/UnorderedListStyle.mm +169 -106
  75. package/ios/utils/BaseStyleProtocol.h +2 -2
  76. package/ios/utils/ColorExtension.mm +7 -5
  77. package/ios/utils/FontExtension.mm +42 -27
  78. package/ios/utils/LayoutManagerExtension.h +1 -1
  79. package/ios/utils/LayoutManagerExtension.mm +280 -170
  80. package/ios/utils/MentionParams.h +0 -1
  81. package/ios/utils/MentionStyleProps.h +1 -1
  82. package/ios/utils/MentionStyleProps.mm +27 -20
  83. package/ios/utils/OccurenceUtils.h +42 -42
  84. package/ios/utils/OccurenceUtils.mm +142 -119
  85. package/ios/utils/ParagraphAttributesUtils.h +6 -2
  86. package/ios/utils/ParagraphAttributesUtils.mm +115 -71
  87. package/ios/utils/ParagraphsUtils.h +2 -1
  88. package/ios/utils/ParagraphsUtils.mm +40 -26
  89. package/ios/utils/StringExtension.h +1 -1
  90. package/ios/utils/StringExtension.mm +19 -16
  91. package/ios/utils/StyleHeaders.h +27 -15
  92. package/ios/utils/TextInsertionUtils.h +13 -2
  93. package/ios/utils/TextInsertionUtils.mm +38 -20
  94. package/ios/utils/WordsUtils.h +2 -1
  95. package/ios/utils/WordsUtils.mm +32 -22
  96. package/ios/utils/ZeroWidthSpaceUtils.h +3 -1
  97. package/ios/utils/ZeroWidthSpaceUtils.mm +145 -79
  98. package/lib/module/EnrichedTextInput.js +39 -1
  99. package/lib/module/EnrichedTextInput.js.map +1 -1
  100. package/lib/module/EnrichedTextInputNativeComponent.ts +11 -0
  101. package/lib/typescript/src/EnrichedTextInput.d.ts +1 -0
  102. package/lib/typescript/src/EnrichedTextInput.d.ts.map +1 -1
  103. package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts +6 -0
  104. package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts.map +1 -1
  105. package/package.json +8 -1
  106. package/src/EnrichedTextInput.tsx +45 -0
  107. 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
- view.spanState.setStart(style, null)
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 [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
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 lost
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 &params) {
16
+ std::shared_ptr<TurboModule> RNEnrichedTextInputViewSpec_ModuleProvider(
17
+ const std::string &moduleName, const JavaTurboModule::InitParams &params) {
18
18
 
19
19
  return nullptr;
20
20
  }
@@ -1,9 +1,10 @@
1
1
 
2
2
  /**
3
- * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
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 lost
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(const std::string &moduleName, const JavaTurboModule::InitParams &params);
23
+ std::shared_ptr<TurboModule> RNEnrichedTextInputViewSpec_ModuleProvider(
24
+ const std::string &moduleName, const JavaTurboModule::InitParams &params);
25
25
 
26
26
  } // namespace facebook::react
@@ -8,28 +8,28 @@
8
8
  namespace facebook::react {
9
9
 
10
10
  class EnrichedTextInputComponentDescriptor final
11
- : public ConcreteComponentDescriptor<EnrichedTextInputShadowNode> {
11
+ : public ConcreteComponentDescriptor<EnrichedTextInputShadowNode> {
12
12
  public:
13
- EnrichedTextInputComponentDescriptor(
14
- const ComponentDescriptorParameters& parameters)
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 = static_cast<EnrichedTextInputShadowNode&>(shadowNode);
23
-
24
- // `EnrichedTextInputShadowNode` uses
25
- // `EnrichedTextInputMeasurementManager` to provide measurements to Yoga.
26
- editorShadowNode.setMeasurementsManager(measurementsManager_);
27
- }
13
+ EnrichedTextInputComponentDescriptor(
14
+ const ComponentDescriptorParameters &parameters)
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
- const std::shared_ptr<EnrichedTextInputMeasurementManager>
31
- measurementsManager_;
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
- Size EnrichedTextInputMeasurementManager::measure(
13
- SurfaceId surfaceId,
14
- int viewTag,
15
- const EnrichedTextInputViewProps& props,
16
- LayoutConstraints layoutConstraints) const {
17
- const jni::global_ref<jobject>& fabricUIManager =
18
- contextContainer_->at<jni::global_ref<jobject>>("FabricUIManager");
19
-
20
- static const auto measure = facebook::jni::findClassStatic(
21
- "com/facebook/react/fabric/FabricUIManager")
22
- ->getMethod<jlong(
23
- jint,
24
- jstring,
25
- ReadableMap::javaobject,
26
- ReadableMap::javaobject,
27
- ReadableMap::javaobject,
28
- jfloat,
29
- jfloat,
30
- jfloat,
31
- jfloat)>("measure");
32
-
33
- auto minimumSize = layoutConstraints.minimumSize;
34
- auto maximumSize = layoutConstraints.maximumSize;
35
-
36
- local_ref<JString> componentName = make_jstring("EnrichedTextInputView");
37
-
38
- // Prepare extraData map with viewTag
39
- folly::dynamic extraData = folly::dynamic::object();
40
- extraData["viewTag"] = viewTag;
41
- local_ref<ReadableNativeMap::javaobject> extraDataRNM = ReadableNativeMap::newObjectCxxArgs(extraData);
42
- local_ref<ReadableMap::javaobject> extraDataRM = make_local(reinterpret_cast<ReadableMap::javaobject>(extraDataRNM.get()));
43
-
44
- // Prepare layout metrics affecting props
45
- auto serializedProps = toDynamic(props);
46
- local_ref<ReadableNativeMap::javaobject> propsRNM = ReadableNativeMap::newObjectCxxArgs(serializedProps);
47
- local_ref<ReadableMap::javaobject> propsRM = make_local(reinterpret_cast<ReadableMap::javaobject>(propsRNM.get()));
48
-
49
- auto measurement = yogaMeassureToSize(measure(
50
- fabricUIManager,
51
- surfaceId,
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
- class EnrichedTextInputMeasurementManager {
12
- public:
13
- EnrichedTextInputMeasurementManager(
14
- const std::shared_ptr<const ContextContainer>& contextContainer)
15
- : contextContainer_(contextContainer) {}
11
+ class EnrichedTextInputMeasurementManager {
12
+ public:
13
+ EnrichedTextInputMeasurementManager(
14
+ const std::shared_ptr<const ContextContainer> &contextContainer)
15
+ : contextContainer_(contextContainer) {}
16
16
 
17
- Size measure(
18
- SurfaceId surfaceId,
19
- int viewTag,
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
- private:
24
- const std::shared_ptr<const ContextContainer> contextContainer_;
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
- void EnrichedTextInputShadowNode::setMeasurementsManager(
8
- const std::shared_ptr<EnrichedTextInputMeasurementManager>&
9
- measurementsManager) {
10
- ensureUnsealed();
11
- measurementsManager_ = measurementsManager;
12
- }
7
+ void EnrichedTextInputShadowNode::setMeasurementsManager(
8
+ const std::shared_ptr<EnrichedTextInputMeasurementManager>
9
+ &measurementsManager) {
10
+ ensureUnsealed();
11
+ measurementsManager_ = measurementsManager;
12
+ }
13
13
 
14
- // Mark layout as dirty after state has been updated
15
- // Once layout is marked as dirty, `measureContent` will be called in order to recalculate layout
16
- void EnrichedTextInputShadowNode::dirtyLayoutIfNeeded() {
17
- const auto state = this->getStateData();
18
- const auto counter = state.getForceHeightRecalculationCounter();
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
- if (forceHeightRecalculationCounter_ != counter) {
21
- forceHeightRecalculationCounter_ = counter;
21
+ if (forceHeightRecalculationCounter_ != counter) {
22
+ forceHeightRecalculationCounter_ = counter;
22
23
 
23
- dirtyLayout();
24
- }
25
- }
24
+ dirtyLayout();
25
+ }
26
+ }
26
27
 
27
- Size EnrichedTextInputShadowNode::measureContent(
28
- const LayoutContext &layoutContext,
29
- const LayoutConstraints &layoutConstraints) const {
30
- return measurementsManager_->measure(getSurfaceId(), getTag(), getConcreteProps(), layoutConstraints);
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 : public ConcreteViewShadowNode<
17
- EnrichedTextInputComponentName,
18
- EnrichedTextInputViewProps,
19
- EnrichedTextInputViewEventEmitter,
20
- EnrichedTextInputState> {
16
+ class EnrichedTextInputShadowNode final
17
+ : public ConcreteViewShadowNode<
18
+ EnrichedTextInputComponentName, EnrichedTextInputViewProps,
19
+ EnrichedTextInputViewEventEmitter, EnrichedTextInputState> {
21
20
  public:
22
- using ConcreteViewShadowNode::ConcreteViewShadowNode;
23
-
24
- // This constructor is called when we "update" shadow node, e.g. after updating shadow node's state
25
- EnrichedTextInputShadowNode(
26
- ShadowNode const &sourceShadowNode,
27
- ShadowNodeFragment const &fragment)
28
- : ConcreteViewShadowNode(sourceShadowNode, fragment) {
29
- dirtyLayoutIfNeeded();
30
- }
31
-
32
- static ShadowNodeTraits BaseTraits() {
33
- auto traits = ConcreteViewShadowNode::BaseTraits();
34
- traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
35
- traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode);
36
- return traits;
37
- }
38
-
39
- // Associates a shared `EnrichedTextInputMeasurementManager` with the node.
40
- void setMeasurementsManager(
41
- const std::shared_ptr<EnrichedTextInputMeasurementManager>&
42
- measurementsManager);
43
-
44
- void dirtyLayoutIfNeeded();
45
-
46
- Size measureContent(
47
- const LayoutContext& layoutContext,
48
- const LayoutConstraints& layoutConstraints) const override;
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
- int forceHeightRecalculationCounter_;
52
- std::shared_ptr<EnrichedTextInputMeasurementManager> measurementsManager_;
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
- int EnrichedTextInputState::getForceHeightRecalculationCounter() const {
6
- return forceHeightRecalculationCounter_;
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
- class EnrichedTextInputState {
8
- public:
9
- EnrichedTextInputState()
10
- : forceHeightRecalculationCounter_(0) {}
7
+ class EnrichedTextInputState {
8
+ public:
9
+ EnrichedTextInputState() : forceHeightRecalculationCounter_(0) {}
11
10
 
12
- // Used by Kotlin to set current text value
13
- EnrichedTextInputState(EnrichedTextInputState const &previousState, folly::dynamic data)
14
- : forceHeightRecalculationCounter_((int)data["forceHeightRecalculationCounter"].getInt()){};
15
- folly::dynamic getDynamic() const {
16
- return {};
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
- int getForceHeightRecalculationCounter() const;
18
+ int getForceHeightRecalculationCounter() const;
20
19
 
21
- private:
22
- const int forceHeightRecalculationCounter_{};
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
- // Serialize only metrics affecting props
14
- folly::dynamic serializedProps = folly::dynamic::object();
15
- serializedProps["defaultValue"] = props.defaultValue;
16
- serializedProps["placeholder"] = props.placeholder;
17
- serializedProps["fontSize"] = props.fontSize;
18
- serializedProps["fontWeight"] = props.fontWeight;
19
- serializedProps["fontStyle"] = props.fontStyle;
20
- serializedProps["fontFamily"] = props.fontFamily;
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
- return serializedProps;
22
+ return serializedProps;
24
23
  }
25
24
  #endif
26
25