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.
Files changed (186) hide show
  1. package/README.md +16 -17
  2. package/android/build.gradle +77 -72
  3. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +21 -0
  4. package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +7 -0
  5. package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.cpp +156 -0
  6. package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.h +147 -0
  7. package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/Props.cpp +10 -0
  8. package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/Props.h +194 -0
  9. package/android/lint.gradle +70 -0
  10. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputConnectionWrapper.kt +140 -0
  11. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt +304 -83
  12. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewLayoutManager.kt +3 -1
  13. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt +166 -51
  14. package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewPackage.kt +1 -3
  15. package/android/src/main/java/com/swmansion/enriched/MeasurementStore.kt +70 -21
  16. package/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt +21 -11
  17. package/android/src/main/java/com/swmansion/enriched/events/OnChangeHtmlEvent.kt +8 -9
  18. package/android/src/main/java/com/swmansion/enriched/events/OnChangeSelectionEvent.kt +10 -9
  19. package/android/src/main/java/com/swmansion/enriched/events/OnChangeStateDeprecatedEvent.kt +21 -0
  20. package/android/src/main/java/com/swmansion/enriched/events/OnChangeStateEvent.kt +9 -12
  21. package/android/src/main/java/com/swmansion/enriched/events/OnChangeTextEvent.kt +10 -10
  22. package/android/src/main/java/com/swmansion/enriched/events/OnInputBlurEvent.kt +7 -9
  23. package/android/src/main/java/com/swmansion/enriched/events/OnInputFocusEvent.kt +7 -9
  24. package/android/src/main/java/com/swmansion/enriched/events/OnInputKeyPressEvent.kt +27 -0
  25. package/android/src/main/java/com/swmansion/enriched/events/OnLinkDetectedEvent.kt +13 -11
  26. package/android/src/main/java/com/swmansion/enriched/events/OnMentionDetectedEvent.kt +10 -9
  27. package/android/src/main/java/com/swmansion/enriched/events/OnMentionEvent.kt +9 -8
  28. package/android/src/main/java/com/swmansion/enriched/events/OnRequestHtmlResultEvent.kt +32 -0
  29. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBlockQuoteSpan.kt +24 -5
  30. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt +8 -1
  31. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedCodeBlockSpan.kt +10 -2
  32. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt +8 -1
  33. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt +8 -1
  34. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt +8 -1
  35. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH4Span.kt +24 -0
  36. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH5Span.kt +24 -0
  37. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH6Span.kt +24 -0
  38. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedImageSpan.kt +34 -17
  39. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedInlineCodeSpan.kt +8 -1
  40. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt +7 -1
  41. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt +10 -4
  42. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedMentionSpan.kt +14 -11
  43. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedOrderedListSpan.kt +18 -11
  44. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedSpans.kt +174 -72
  45. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt +7 -1
  46. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt +7 -1
  47. package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnorderedListSpan.kt +11 -5
  48. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedBlockSpan.kt +3 -2
  49. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedHeadingSpan.kt +1 -2
  50. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedInlineSpan.kt +1 -2
  51. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedParagraphSpan.kt +3 -2
  52. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt +5 -0
  53. package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedZeroWidthSpaceSpan.kt +1 -2
  54. package/android/src/main/java/com/swmansion/enriched/spans/utils/ForceRedrawSpan.kt +2 -1
  55. package/android/src/main/java/com/swmansion/enriched/styles/HtmlStyle.kt +155 -20
  56. package/android/src/main/java/com/swmansion/enriched/styles/InlineStyles.kt +25 -8
  57. package/android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt +60 -20
  58. package/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt +161 -25
  59. package/android/src/main/java/com/swmansion/enriched/styles/ParametrizedStyles.kt +128 -52
  60. package/android/src/main/java/com/swmansion/enriched/utils/AsyncDrawable.kt +10 -7
  61. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedConstants.kt +11 -0
  62. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedEditableFactory.kt +17 -0
  63. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedParser.java +136 -87
  64. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSelection.kt +71 -42
  65. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpanState.kt +183 -48
  66. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpannable.kt +82 -0
  67. package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpannableStringBuilder.kt +15 -0
  68. package/android/src/main/java/com/swmansion/enriched/utils/Utils.kt +0 -70
  69. package/android/src/main/java/com/swmansion/enriched/watchers/EnrichedSpanWatcher.kt +46 -14
  70. package/android/src/main/java/com/swmansion/enriched/watchers/EnrichedTextWatcher.kt +34 -11
  71. package/android/src/main/new_arch/CMakeLists.txt +6 -0
  72. package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp +6 -6
  73. package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.h +6 -6
  74. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputComponentDescriptor.h +19 -19
  75. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.cpp +40 -51
  76. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.h +13 -15
  77. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.cpp +23 -21
  78. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.h +35 -36
  79. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.cpp +4 -4
  80. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.h +13 -14
  81. package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/conversions.h +33 -14
  82. package/ios/EnrichedTextInputView.h +26 -14
  83. package/ios/EnrichedTextInputView.mm +1209 -586
  84. package/ios/config/InputConfig.h +24 -6
  85. package/ios/config/InputConfig.mm +154 -38
  86. package/ios/{utils → extensions}/ColorExtension.mm +7 -5
  87. package/ios/extensions/FontExtension.mm +106 -0
  88. package/ios/{utils → extensions}/LayoutManagerExtension.h +1 -1
  89. package/ios/extensions/LayoutManagerExtension.mm +396 -0
  90. package/ios/{utils → extensions}/StringExtension.mm +19 -16
  91. package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.cpp +156 -0
  92. package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.h +147 -0
  93. package/ios/generated/RNEnrichedTextInputViewSpec/Props.cpp +10 -0
  94. package/ios/generated/RNEnrichedTextInputViewSpec/Props.h +194 -0
  95. package/ios/generated/RNEnrichedTextInputViewSpec/RCTComponentViewHelpers.h +95 -0
  96. package/ios/inputParser/InputParser.h +5 -5
  97. package/ios/inputParser/InputParser.mm +864 -380
  98. package/ios/inputTextView/InputTextView.h +1 -1
  99. package/ios/inputTextView/InputTextView.mm +100 -59
  100. package/ios/{utils → interfaces}/BaseStyleProtocol.h +2 -2
  101. package/ios/interfaces/ImageAttachment.h +10 -0
  102. package/ios/interfaces/ImageAttachment.mm +36 -0
  103. package/ios/interfaces/LinkRegexConfig.h +19 -0
  104. package/ios/interfaces/LinkRegexConfig.mm +37 -0
  105. package/ios/interfaces/MediaAttachment.h +23 -0
  106. package/ios/interfaces/MediaAttachment.mm +31 -0
  107. package/ios/{utils → interfaces}/MentionParams.h +0 -1
  108. package/ios/{utils → interfaces}/MentionStyleProps.mm +27 -20
  109. package/ios/{utils → interfaces}/StyleHeaders.h +37 -15
  110. package/ios/{utils → interfaces}/StyleTypeEnum.h +3 -0
  111. package/ios/internals/EnrichedTextInputViewComponentDescriptor.h +11 -9
  112. package/ios/internals/EnrichedTextInputViewShadowNode.h +28 -25
  113. package/ios/internals/EnrichedTextInputViewShadowNode.mm +45 -40
  114. package/ios/internals/EnrichedTextInputViewState.h +3 -1
  115. package/ios/styles/BlockQuoteStyle.mm +189 -118
  116. package/ios/styles/BoldStyle.mm +110 -63
  117. package/ios/styles/CodeBlockStyle.mm +204 -128
  118. package/ios/styles/H1Style.mm +10 -4
  119. package/ios/styles/H2Style.mm +10 -4
  120. package/ios/styles/H3Style.mm +10 -4
  121. package/ios/styles/H4Style.mm +17 -0
  122. package/ios/styles/H5Style.mm +17 -0
  123. package/ios/styles/H6Style.mm +17 -0
  124. package/ios/styles/HeadingStyleBase.mm +148 -86
  125. package/ios/styles/ImageStyle.mm +75 -73
  126. package/ios/styles/InlineCodeStyle.mm +162 -88
  127. package/ios/styles/ItalicStyle.mm +76 -52
  128. package/ios/styles/LinkStyle.mm +411 -232
  129. package/ios/styles/MentionStyle.mm +363 -246
  130. package/ios/styles/OrderedListStyle.mm +171 -106
  131. package/ios/styles/StrikethroughStyle.mm +52 -35
  132. package/ios/styles/UnderlineStyle.mm +68 -46
  133. package/ios/styles/UnorderedListStyle.mm +169 -106
  134. package/ios/utils/OccurenceUtils.h +42 -42
  135. package/ios/utils/OccurenceUtils.mm +142 -119
  136. package/ios/utils/ParagraphAttributesUtils.h +10 -2
  137. package/ios/utils/ParagraphAttributesUtils.mm +182 -71
  138. package/ios/utils/ParagraphsUtils.h +2 -1
  139. package/ios/utils/ParagraphsUtils.mm +41 -27
  140. package/ios/utils/TextInsertionUtils.h +13 -2
  141. package/ios/utils/TextInsertionUtils.mm +38 -20
  142. package/ios/utils/WordsUtils.h +2 -1
  143. package/ios/utils/WordsUtils.mm +32 -22
  144. package/ios/utils/ZeroWidthSpaceUtils.h +3 -1
  145. package/ios/utils/ZeroWidthSpaceUtils.mm +145 -79
  146. package/lib/module/EnrichedTextInput.js +61 -2
  147. package/lib/module/EnrichedTextInput.js.map +1 -1
  148. package/lib/module/EnrichedTextInputNativeComponent.ts +149 -12
  149. package/lib/module/{normalizeHtmlStyle.js → utils/normalizeHtmlStyle.js} +12 -0
  150. package/lib/module/utils/normalizeHtmlStyle.js.map +1 -0
  151. package/lib/module/utils/regexParser.js +46 -0
  152. package/lib/module/utils/regexParser.js.map +1 -0
  153. package/lib/typescript/src/EnrichedTextInput.d.ts +24 -14
  154. package/lib/typescript/src/EnrichedTextInput.d.ts.map +1 -1
  155. package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts +129 -12
  156. package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts.map +1 -1
  157. package/lib/typescript/src/index.d.ts +1 -1
  158. package/lib/typescript/src/index.d.ts.map +1 -1
  159. package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts +4 -0
  160. package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts.map +1 -0
  161. package/lib/typescript/src/utils/regexParser.d.ts +3 -0
  162. package/lib/typescript/src/utils/regexParser.d.ts.map +1 -0
  163. package/package.json +17 -6
  164. package/src/EnrichedTextInput.tsx +96 -13
  165. package/src/EnrichedTextInputNativeComponent.ts +149 -12
  166. package/src/index.tsx +2 -0
  167. package/src/{normalizeHtmlStyle.ts → utils/normalizeHtmlStyle.ts} +14 -2
  168. package/src/utils/regexParser.ts +56 -0
  169. package/ios/utils/FontExtension.mm +0 -91
  170. package/ios/utils/LayoutManagerExtension.mm +0 -286
  171. package/lib/module/normalizeHtmlStyle.js.map +0 -1
  172. package/lib/typescript/src/normalizeHtmlStyle.d.ts +0 -4
  173. package/lib/typescript/src/normalizeHtmlStyle.d.ts.map +0 -1
  174. package/ios/{utils → extensions}/ColorExtension.h +0 -0
  175. package/ios/{utils → extensions}/FontExtension.h +0 -0
  176. package/ios/{utils → extensions}/StringExtension.h +1 -1
  177. package/ios/{utils → interfaces}/ImageData.h +0 -0
  178. package/ios/{utils → interfaces}/ImageData.mm +0 -0
  179. package/ios/{utils → interfaces}/LinkData.h +0 -0
  180. package/ios/{utils → interfaces}/LinkData.mm +0 -0
  181. package/ios/{utils → interfaces}/MentionParams.mm +0 -0
  182. package/ios/{utils → interfaces}/MentionStyleProps.h +1 -1
  183. /package/ios/{utils → interfaces}/StylePair.h +0 -0
  184. /package/ios/{utils → interfaces}/StylePair.mm +0 -0
  185. /package/ios/{utils → interfaces}/TextDecorationLineEnum.h +0 -0
  186. /package/ios/{utils → interfaces}/TextDecorationLineEnum.mm +0 -0
@@ -1,10 +1,10 @@
1
1
  #pragma once
2
+ #include <ReactNativeEnriched/EnrichedTextInputViewState.h>
2
3
  #include <ReactNativeEnriched/EventEmitters.h>
3
4
  #include <ReactNativeEnriched/Props.h>
4
- #include <ReactNativeEnriched/EnrichedTextInputViewState.h>
5
+ #include <jsi/jsi.h>
5
6
  #include <react/renderer/components/view/ConcreteViewShadowNode.h>
6
7
  #include <react/renderer/core/LayoutConstraints.h>
7
- #include <jsi/jsi.h>
8
8
 
9
9
  namespace facebook::react {
10
10
 
@@ -13,29 +13,32 @@ JSI_EXPORT extern const char EnrichedTextInputViewComponentName[];
13
13
  /*
14
14
  * `ShadowNode` for <EnrichedTextInputView> component.
15
15
  */
16
- class EnrichedTextInputViewShadowNode : public ConcreteViewShadowNode<
17
- EnrichedTextInputViewComponentName,
18
- EnrichedTextInputViewProps,
19
- EnrichedTextInputViewEventEmitter,
20
- EnrichedTextInputViewState> {
21
- public:
22
- using ConcreteViewShadowNode::ConcreteViewShadowNode;
23
- EnrichedTextInputViewShadowNode(const ShadowNodeFragment& fragment, const ShadowNodeFamily::Shared& family, ShadowNodeTraits traits);
24
- EnrichedTextInputViewShadowNode(const ShadowNode& sourceShadowNode, const ShadowNodeFragment& fragment);
25
- void dirtyLayoutIfNeeded();
26
- Size measureContent(const LayoutContext& layoutContext, const LayoutConstraints& layoutConstraints) const override;
27
-
28
-
29
- static ShadowNodeTraits BaseTraits() {
30
- auto traits = ConcreteViewShadowNode::BaseTraits();
31
- traits.set(ShadowNodeTraits::Trait::LeafYogaNode);
32
- traits.set(ShadowNodeTraits::Trait::MeasurableYogaNode);
33
- return traits;
34
- }
35
-
36
- private:
37
- int localForceHeightRecalculationCounter_;
38
- id setupMockTextInputView_() const;
16
+ class EnrichedTextInputViewShadowNode
17
+ : public ConcreteViewShadowNode<
18
+ EnrichedTextInputViewComponentName, EnrichedTextInputViewProps,
19
+ EnrichedTextInputViewEventEmitter, EnrichedTextInputViewState> {
20
+ public:
21
+ using ConcreteViewShadowNode::ConcreteViewShadowNode;
22
+ EnrichedTextInputViewShadowNode(const ShadowNodeFragment &fragment,
23
+ const ShadowNodeFamily::Shared &family,
24
+ ShadowNodeTraits traits);
25
+ EnrichedTextInputViewShadowNode(const ShadowNode &sourceShadowNode,
26
+ const ShadowNodeFragment &fragment);
27
+ void dirtyLayoutIfNeeded();
28
+ Size
29
+ measureContent(const LayoutContext &layoutContext,
30
+ const LayoutConstraints &layoutConstraints) const override;
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
+ private:
40
+ int localForceHeightRecalculationCounter_;
41
+ id setupMockTextInputView_() const;
39
42
  };
40
43
 
41
44
  } // namespace facebook::react
@@ -1,28 +1,30 @@
1
1
  #import "EnrichedTextInputViewShadowNode.h"
2
+ #import "CoreText/CoreText.h"
2
3
  #import <EnrichedTextInputView.h>
4
+ #import <React/RCTShadowView+Layout.h>
3
5
  #import <react/utils/ManagedObjectWrapper.h>
4
6
  #import <yoga/Yoga.h>
5
- #import <React/RCTShadowView+Layout.h>
6
- #import "CoreText/CoreText.h"
7
7
 
8
8
  namespace facebook::react {
9
9
 
10
- extern const char EnrichedTextInputViewComponentName[] = "EnrichedTextInputView";
10
+ extern const char EnrichedTextInputViewComponentName[] =
11
+ "EnrichedTextInputView";
11
12
 
12
13
  EnrichedTextInputViewShadowNode::EnrichedTextInputViewShadowNode(
13
- const ShadowNodeFragment& fragment,
14
- const ShadowNodeFamily::Shared& family,
15
- ShadowNodeTraits traits
16
- ): ConcreteViewShadowNode(fragment, family, traits) {
14
+ const ShadowNodeFragment &fragment, const ShadowNodeFamily::Shared &family,
15
+ ShadowNodeTraits traits)
16
+ : ConcreteViewShadowNode(fragment, family, traits) {
17
17
  localForceHeightRecalculationCounter_ = 0;
18
18
  }
19
19
 
20
- // mock input is used for the first measure calls that need to be done when the real input isn't defined yet
20
+ // mock input is used for the first measure calls that need to be done when the
21
+ // real input isn't defined yet
21
22
  id EnrichedTextInputViewShadowNode::setupMockTextInputView_() const {
22
23
  // it's rendered far away from the viewport
23
24
  const int veryFarAway = 20000;
24
25
  const int mockSize = 1000;
25
- EnrichedTextInputView *mockTextInputView_ = [[EnrichedTextInputView alloc] initWithFrame:(CGRectMake(veryFarAway, veryFarAway, mockSize, mockSize))];
26
+ EnrichedTextInputView *mockTextInputView_ = [[EnrichedTextInputView alloc]
27
+ initWithFrame:(CGRectMake(veryFarAway, veryFarAway, mockSize, mockSize))];
26
28
  const auto props = this->getProps();
27
29
  mockTextInputView_->blockEmitting = YES;
28
30
  [mockTextInputView_ updateProps:props oldProps:nullptr];
@@ -30,69 +32,72 @@ id EnrichedTextInputViewShadowNode::setupMockTextInputView_() const {
30
32
  }
31
33
 
32
34
  EnrichedTextInputViewShadowNode::EnrichedTextInputViewShadowNode(
33
- const ShadowNode& sourceShadowNode,
34
- const ShadowNodeFragment& fragment
35
- ): ConcreteViewShadowNode(sourceShadowNode, fragment) {
35
+ const ShadowNode &sourceShadowNode, const ShadowNodeFragment &fragment)
36
+ : ConcreteViewShadowNode(sourceShadowNode, fragment) {
36
37
  dirtyLayoutIfNeeded();
37
38
  }
38
39
 
39
40
  void EnrichedTextInputViewShadowNode::dirtyLayoutIfNeeded() {
40
41
  const auto state = this->getStateData();
41
42
  const int receivedCounter = state.getForceHeightRecalculationCounter();
42
-
43
- if(receivedCounter > localForceHeightRecalculationCounter_) {
43
+
44
+ if (receivedCounter > localForceHeightRecalculationCounter_) {
44
45
  localForceHeightRecalculationCounter_ = receivedCounter;
45
46
  YGNodeMarkDirty(&yogaNode_);
46
47
  }
47
48
  }
48
49
 
49
- Size EnrichedTextInputViewShadowNode::measureContent(const LayoutContext& layoutContext, const LayoutConstraints& layoutConstraints) const {
50
+ Size EnrichedTextInputViewShadowNode::measureContent(
51
+ const LayoutContext &layoutContext,
52
+ const LayoutConstraints &layoutConstraints) const {
50
53
  const auto state = this->getStateData();
51
54
  const auto componentRef = state.getComponentViewRef();
52
- RCTInternalGenericWeakWrapper *weakWrapper = (RCTInternalGenericWeakWrapper *)unwrapManagedObject(componentRef);
53
-
54
- if(weakWrapper != nullptr) {
55
+ RCTInternalGenericWeakWrapper *weakWrapper =
56
+ (RCTInternalGenericWeakWrapper *)unwrapManagedObject(componentRef);
57
+
58
+ if (weakWrapper != nullptr) {
55
59
  id componentObject = weakWrapper.object;
56
- EnrichedTextInputView *typedComponentObject = (EnrichedTextInputView *) componentObject;
57
-
58
- if(typedComponentObject != nullptr) {
60
+ EnrichedTextInputView *typedComponentObject =
61
+ (EnrichedTextInputView *)componentObject;
62
+
63
+ if (typedComponentObject != nullptr) {
59
64
  __block CGSize estimatedSize;
60
-
65
+
61
66
  // synchronously dispatch to main thread if needed
62
- if([NSThread isMainThread]) {
63
- estimatedSize = [typedComponentObject measureSize:layoutConstraints.maximumSize.width];
67
+ if ([NSThread isMainThread]) {
68
+ estimatedSize = [typedComponentObject
69
+ measureSize:layoutConstraints.maximumSize.width];
64
70
  } else {
65
71
  dispatch_sync(dispatch_get_main_queue(), ^{
66
- estimatedSize = [typedComponentObject measureSize:layoutConstraints.maximumSize.width];
72
+ estimatedSize = [typedComponentObject
73
+ measureSize:layoutConstraints.maximumSize.width];
67
74
  });
68
75
  }
69
-
70
- return {
71
- estimatedSize.width,
72
- MIN(estimatedSize.height, layoutConstraints.maximumSize.height)
73
- };
76
+
77
+ return {estimatedSize.width,
78
+ MIN(estimatedSize.height, layoutConstraints.maximumSize.height)};
74
79
  }
75
80
  } else {
76
81
  __block CGSize estimatedSize;
77
-
82
+
78
83
  // synchronously dispatch to main thread if needed
79
- if([NSThread isMainThread]) {
84
+ if ([NSThread isMainThread]) {
80
85
  EnrichedTextInputView *mockTextInputView = setupMockTextInputView_();
81
- estimatedSize = [mockTextInputView measureSize:layoutConstraints.maximumSize.width];
86
+ estimatedSize =
87
+ [mockTextInputView measureSize:layoutConstraints.maximumSize.width];
82
88
  } else {
83
89
  dispatch_sync(dispatch_get_main_queue(), ^{
84
90
  EnrichedTextInputView *mockTextInputView = setupMockTextInputView_();
85
- estimatedSize = [mockTextInputView measureSize:layoutConstraints.maximumSize.width];
91
+ estimatedSize =
92
+ [mockTextInputView measureSize:layoutConstraints.maximumSize.width];
86
93
  });
87
94
  }
88
95
 
89
- return {
90
- estimatedSize.width,
91
- MIN(estimatedSize.height, layoutConstraints.maximumSize.height)
92
- };
96
+ return {estimatedSize.width,
97
+ MIN(estimatedSize.height, layoutConstraints.maximumSize.height)};
93
98
  }
94
-
99
+
95
100
  return Size();
96
101
  }
97
-
102
+
98
103
  } // namespace facebook::react
@@ -5,13 +5,15 @@ namespace facebook::react {
5
5
 
6
6
  class EnrichedTextInputViewState {
7
7
  public:
8
- EnrichedTextInputViewState(): forceHeightRecalculationCounter_(0), componentViewRef_(nullptr) {}
8
+ EnrichedTextInputViewState()
9
+ : forceHeightRecalculationCounter_(0), componentViewRef_(nullptr) {}
9
10
  EnrichedTextInputViewState(int counter, std::shared_ptr<void> ref) {
10
11
  forceHeightRecalculationCounter_ = counter;
11
12
  componentViewRef_ = ref;
12
13
  }
13
14
  int getForceHeightRecalculationCounter() const;
14
15
  std::shared_ptr<void> getComponentViewRef() const;
16
+
15
17
  private:
16
18
  int forceHeightRecalculationCounter_{};
17
19
  std::shared_ptr<void> componentViewRef_{};
@@ -1,18 +1,22 @@
1
- #import "StyleHeaders.h"
1
+ #import "ColorExtension.h"
2
2
  #import "EnrichedTextInputView.h"
3
3
  #import "OccurenceUtils.h"
4
4
  #import "ParagraphsUtils.h"
5
+ #import "StyleHeaders.h"
5
6
  #import "TextInsertionUtils.h"
6
- #import "ColorExtension.h"
7
7
 
8
8
  @implementation BlockQuoteStyle {
9
9
  EnrichedTextInputView *_input;
10
10
  NSArray *_stylesToExclude;
11
11
  }
12
12
 
13
- + (StyleType)getStyleType { return BlockQuote; }
13
+ + (StyleType)getStyleType {
14
+ return BlockQuote;
15
+ }
14
16
 
15
- + (BOOL)isParagraphStyle { return YES; }
17
+ + (BOOL)isParagraphStyle {
18
+ return YES;
19
+ }
16
20
 
17
21
  - (instancetype)initWithInput:(id)input {
18
22
  self = [super init];
@@ -23,118 +27,158 @@
23
27
 
24
28
  - (CGFloat)getHeadIndent {
25
29
  // rectangle width + gap
26
- return [_input->config blockquoteBorderWidth] + [_input->config blockquoteGapWidth];
30
+ return [_input->config blockquoteBorderWidth] +
31
+ [_input->config blockquoteGapWidth];
27
32
  }
28
33
 
29
34
  // the range will already be the full paragraph/s range
30
35
  - (void)applyStyle:(NSRange)range {
31
36
  BOOL isStylePresent = [self detectStyle:range];
32
- if(range.length >= 1) {
33
- isStylePresent ? [self removeAttributes:range] : [self addAttributes:range];
37
+ if (range.length >= 1) {
38
+ isStylePresent ? [self removeAttributes:range]
39
+ : [self addAttributes:range withTypingAttr:YES];
34
40
  } else {
35
41
  isStylePresent ? [self removeTypingAttributes] : [self addTypingAttributes];
36
42
  }
37
43
  }
38
44
 
39
- - (void)addAttributes:(NSRange)range {
40
- NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView range:range];
41
- // if we fill empty lines with zero width spaces, we need to offset later ranges
45
+ - (void)addAttributes:(NSRange)range withTypingAttr:(BOOL)withTypingAttr {
46
+ NSArray *paragraphs =
47
+ [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView
48
+ range:range];
49
+ // if we fill empty lines with zero width spaces, we need to offset later
50
+ // ranges
42
51
  NSInteger offset = 0;
43
52
  NSRange preModificationRange = _input->textView.selectedRange;
44
-
53
+
45
54
  // to not emit any space filling selection/text changes
46
55
  _input->blockEmitting = YES;
47
-
48
- for(NSValue *value in paragraphs) {
49
- NSRange pRange = NSMakeRange([value rangeValue].location + offset, [value rangeValue].length);
50
-
51
- // length 0 with first line, length 1 and newline with some empty lines in the middle
52
- if(pRange.length == 0 ||
53
- (pRange.length == 1 &&
54
- [[NSCharacterSet newlineCharacterSet] characterIsMember: [_input->textView.textStorage.string characterAtIndex:pRange.location]])
55
- ) {
56
- [TextInsertionUtils insertText:@"\u200B" at:pRange.location additionalAttributes:nullptr input:_input withSelection:NO];
56
+
57
+ for (NSValue *value in paragraphs) {
58
+ NSRange pRange = NSMakeRange([value rangeValue].location + offset,
59
+ [value rangeValue].length);
60
+
61
+ // length 0 with first line, length 1 and newline with some empty lines in
62
+ // the middle
63
+ if (pRange.length == 0 ||
64
+ (pRange.length == 1 &&
65
+ [[NSCharacterSet newlineCharacterSet]
66
+ characterIsMember:[_input->textView.textStorage.string
67
+ characterAtIndex:pRange.location]])) {
68
+ [TextInsertionUtils insertText:@"\u200B"
69
+ at:pRange.location
70
+ additionalAttributes:nullptr
71
+ input:_input
72
+ withSelection:NO];
57
73
  pRange = NSMakeRange(pRange.location, pRange.length + 1);
58
74
  offset += 1;
59
75
  }
60
-
61
- [_input->textView.textStorage enumerateAttribute:NSParagraphStyleAttributeName inRange:pRange options:0
62
- usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
63
- NSMutableParagraphStyle *pStyle = [(NSParagraphStyle *)value mutableCopy];
64
- pStyle.headIndent = [self getHeadIndent];
65
- pStyle.firstLineHeadIndent = [self getHeadIndent];
66
- [_input->textView.textStorage addAttribute:NSParagraphStyleAttributeName value:pStyle range:range];
67
- }
68
- ];
76
+
77
+ [_input->textView.textStorage
78
+ enumerateAttribute:NSParagraphStyleAttributeName
79
+ inRange:pRange
80
+ options:0
81
+ usingBlock:^(id _Nullable value, NSRange range,
82
+ BOOL *_Nonnull stop) {
83
+ NSMutableParagraphStyle *pStyle =
84
+ [(NSParagraphStyle *)value mutableCopy];
85
+ pStyle.headIndent = [self getHeadIndent];
86
+ pStyle.firstLineHeadIndent = [self getHeadIndent];
87
+ [_input->textView.textStorage
88
+ addAttribute:NSParagraphStyleAttributeName
89
+ value:pStyle
90
+ range:range];
91
+ }];
69
92
  }
70
-
93
+
71
94
  // back to emitting
72
95
  _input->blockEmitting = NO;
73
-
74
- if(preModificationRange.length == 0) {
75
- // fix selection if only one line was possibly made a list and filled with a space
96
+
97
+ if (preModificationRange.length == 0) {
98
+ // fix selection if only one line was possibly made a list and filled with a
99
+ // space
76
100
  _input->textView.selectedRange = preModificationRange;
77
101
  } else {
78
102
  // in other cases, fix the selection with newly made offsets
79
- _input->textView.selectedRange = NSMakeRange(preModificationRange.location, preModificationRange.length + offset);
103
+ _input->textView.selectedRange = NSMakeRange(
104
+ preModificationRange.location, preModificationRange.length + offset);
80
105
  }
81
-
106
+
82
107
  // also add typing attributes
83
- NSMutableDictionary *typingAttrs = [_input->textView.typingAttributes mutableCopy];
84
- NSMutableParagraphStyle *pStyle = [typingAttrs[NSParagraphStyleAttributeName] mutableCopy];
85
- pStyle.headIndent = [self getHeadIndent];
86
- pStyle.firstLineHeadIndent = [self getHeadIndent];
87
- typingAttrs[NSParagraphStyleAttributeName] = pStyle;
88
- _input->textView.typingAttributes = typingAttrs;
108
+ if (withTypingAttr) {
109
+ NSMutableDictionary *typingAttrs =
110
+ [_input->textView.typingAttributes mutableCopy];
111
+ NSMutableParagraphStyle *pStyle =
112
+ [typingAttrs[NSParagraphStyleAttributeName] mutableCopy];
113
+ pStyle.headIndent = [self getHeadIndent];
114
+ pStyle.firstLineHeadIndent = [self getHeadIndent];
115
+ typingAttrs[NSParagraphStyleAttributeName] = pStyle;
116
+ _input->textView.typingAttributes = typingAttrs;
117
+ }
89
118
  }
90
119
 
91
120
  // does pretty much the same as addAttributes
92
121
  - (void)addTypingAttributes {
93
- [self addAttributes:_input->textView.selectedRange];
122
+ [self addAttributes:_input->textView.selectedRange withTypingAttr:YES];
94
123
  }
95
124
 
96
125
  - (void)removeAttributes:(NSRange)range {
97
- NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView range:range];
98
-
99
- for(NSValue *value in paragraphs) {
126
+ NSArray *paragraphs =
127
+ [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView
128
+ range:range];
129
+
130
+ for (NSValue *value in paragraphs) {
100
131
  NSRange pRange = [value rangeValue];
101
- [_input->textView.textStorage enumerateAttribute:NSParagraphStyleAttributeName inRange:pRange options:0
102
- usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
103
- NSMutableParagraphStyle *pStyle = [(NSParagraphStyle *)value mutableCopy];
104
- pStyle.headIndent = 0;
105
- pStyle.firstLineHeadIndent = 0;
106
- [_input->textView.textStorage addAttribute:NSParagraphStyleAttributeName value:pStyle range:range];
107
- }
108
- ];
132
+ [_input->textView.textStorage
133
+ enumerateAttribute:NSParagraphStyleAttributeName
134
+ inRange:pRange
135
+ options:0
136
+ usingBlock:^(id _Nullable value, NSRange range,
137
+ BOOL *_Nonnull stop) {
138
+ NSMutableParagraphStyle *pStyle =
139
+ [(NSParagraphStyle *)value mutableCopy];
140
+ pStyle.headIndent = 0;
141
+ pStyle.firstLineHeadIndent = 0;
142
+ [_input->textView.textStorage
143
+ addAttribute:NSParagraphStyleAttributeName
144
+ value:pStyle
145
+ range:range];
146
+ }];
109
147
  }
110
-
148
+
111
149
  // also remove typing attributes
112
- NSMutableDictionary *typingAttrs = [_input->textView.typingAttributes mutableCopy];
113
- NSMutableParagraphStyle *pStyle = [typingAttrs[NSParagraphStyleAttributeName] mutableCopy];
150
+ NSMutableDictionary *typingAttrs =
151
+ [_input->textView.typingAttributes mutableCopy];
152
+ NSMutableParagraphStyle *pStyle =
153
+ [typingAttrs[NSParagraphStyleAttributeName] mutableCopy];
114
154
  pStyle.headIndent = 0;
115
155
  pStyle.firstLineHeadIndent = 0;
116
156
  typingAttrs[NSParagraphStyleAttributeName] = pStyle;
117
157
  _input->textView.typingAttributes = typingAttrs;
118
158
  }
119
159
 
120
- // needed for the sake of style conflicts, needs to do exactly the same as removeAttribtues
160
+ // needed for the sake of style conflicts, needs to do exactly the same as
161
+ // removeAttribtues
121
162
  - (void)removeTypingAttributes {
122
163
  [self removeAttributes:_input->textView.selectedRange];
123
164
  }
124
165
 
125
166
  - (BOOL)handleBackspaceInRange:(NSRange)range replacementText:(NSString *)text {
126
- if([self detectStyle:_input->textView.selectedRange] && text.length == 0) {
167
+ if ([self detectStyle:_input->textView.selectedRange] && text.length == 0) {
127
168
  // backspace while the style is active
128
-
129
- NSRange paragraphRange = [_input->textView.textStorage.string paragraphRangeForRange:_input->textView.selectedRange];
130
-
131
- if(NSEqualRanges(_input->textView.selectedRange, NSMakeRange(0, 0))) {
169
+
170
+ NSRange paragraphRange = [_input->textView.textStorage.string
171
+ paragraphRangeForRange:_input->textView.selectedRange];
172
+
173
+ if (NSEqualRanges(_input->textView.selectedRange, NSMakeRange(0, 0))) {
132
174
  // a backspace on the very first input's line quote
133
- // it doesn't run textVieDidChange so we need to manually remove attributes
175
+ // it doesn't run textVieDidChange so we need to manually remove
176
+ // attributes
134
177
  [self removeAttributes:paragraphRange];
135
178
  return YES;
136
- } else if(range.location == paragraphRange.location - 1) {
137
- // same case in other lines; here, the removed range location will be exactly 1 less than paragraph range location
179
+ } else if (range.location == paragraphRange.location - 1) {
180
+ // same case in other lines; here, the removed range location will be
181
+ // exactly 1 less than paragraph range location
138
182
  [self removeAttributes:paragraphRange];
139
183
  return YES;
140
184
  }
@@ -142,79 +186,106 @@
142
186
  return NO;
143
187
  }
144
188
 
145
- - (BOOL)styleCondition:(id _Nullable)value :(NSRange)range {
189
+ - (BOOL)styleCondition:(id _Nullable)value range:(NSRange)range {
146
190
  NSParagraphStyle *pStyle = (NSParagraphStyle *)value;
147
- return pStyle != nullptr && pStyle.headIndent == [self getHeadIndent] && pStyle.firstLineHeadIndent == [self getHeadIndent] && pStyle.textLists.count == 0;
191
+ return pStyle != nullptr && pStyle.headIndent == [self getHeadIndent] &&
192
+ pStyle.firstLineHeadIndent == [self getHeadIndent] &&
193
+ pStyle.textLists.count == 0;
148
194
  }
149
195
 
150
196
  - (BOOL)detectStyle:(NSRange)range {
151
- if(range.length >= 1) {
152
- return [OccurenceUtils detect:NSParagraphStyleAttributeName withInput:_input inRange:range
153
- withCondition: ^BOOL(id _Nullable value, NSRange range) {
154
- return [self styleCondition:value :range];
155
- }
156
- ];
197
+ if (range.length >= 1) {
198
+ return [OccurenceUtils detect:NSParagraphStyleAttributeName
199
+ withInput:_input
200
+ inRange:range
201
+ withCondition:^BOOL(id _Nullable value, NSRange range) {
202
+ return [self styleCondition:value range:range];
203
+ }];
157
204
  } else {
158
- return [OccurenceUtils detect:NSParagraphStyleAttributeName withInput:_input atIndex:range.location checkPrevious:YES
159
- withCondition:^BOOL(id _Nullable value, NSRange range) {
160
- return [self styleCondition:value :range];
161
- }
162
- ];
205
+ return [OccurenceUtils detect:NSParagraphStyleAttributeName
206
+ withInput:_input
207
+ atIndex:range.location
208
+ checkPrevious:YES
209
+ withCondition:^BOOL(id _Nullable value, NSRange range) {
210
+ return [self styleCondition:value range:range];
211
+ }];
163
212
  }
164
213
  }
165
214
 
166
215
  - (BOOL)anyOccurence:(NSRange)range {
167
- return [OccurenceUtils any:NSParagraphStyleAttributeName withInput:_input inRange:range
168
- withCondition:^BOOL(id _Nullable value, NSRange range) {
169
- return [self styleCondition:value :range];
170
- }
171
- ];
216
+ return [OccurenceUtils any:NSParagraphStyleAttributeName
217
+ withInput:_input
218
+ inRange:range
219
+ withCondition:^BOOL(id _Nullable value, NSRange range) {
220
+ return [self styleCondition:value range:range];
221
+ }];
172
222
  }
173
223
 
174
224
  - (NSArray<StylePair *> *_Nullable)findAllOccurences:(NSRange)range {
175
- return [OccurenceUtils all:NSParagraphStyleAttributeName withInput:_input inRange:range
176
- withCondition:^BOOL(id _Nullable value, NSRange range) {
177
- return [self styleCondition:value :range];
178
- }
179
- ];
225
+ return [OccurenceUtils all:NSParagraphStyleAttributeName
226
+ withInput:_input
227
+ inRange:range
228
+ withCondition:^BOOL(id _Nullable value, NSRange range) {
229
+ return [self styleCondition:value range:range];
230
+ }];
180
231
  }
181
232
 
182
233
  // general checkup correcting blockquote color
183
- // since links, mentions and inline code affects coloring, the checkup gets done only outside of them
234
+ // since links, mentions and inline code affects coloring, the checkup gets done
235
+ // only outside of them
184
236
  - (void)manageBlockquoteColor {
185
- if([[_input->config blockquoteColor] isEqualToColor:[_input->config primaryColor]]) {
237
+ if ([[_input->config blockquoteColor]
238
+ isEqualToColor:[_input->config primaryColor]]) {
186
239
  return;
187
240
  }
188
-
189
- NSRange wholeRange = NSMakeRange(0, _input->textView.textStorage.string.length);
190
-
191
- NSArray *paragraphs = [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView range:wholeRange];
192
- for(NSValue *pValue in paragraphs) {
241
+
242
+ NSRange wholeRange =
243
+ NSMakeRange(0, _input->textView.textStorage.string.length);
244
+
245
+ NSArray *paragraphs =
246
+ [ParagraphsUtils getSeparateParagraphsRangesIn:_input->textView
247
+ range:wholeRange];
248
+ for (NSValue *pValue in paragraphs) {
193
249
  NSRange paragraphRange = [pValue rangeValue];
194
- NSArray *properRanges = [OccurenceUtils getRangesWithout:_stylesToExclude withInput:_input inRange:paragraphRange];
195
-
196
- for(NSValue *value in properRanges) {
250
+ NSArray *properRanges = [OccurenceUtils getRangesWithout:_stylesToExclude
251
+ withInput:_input
252
+ inRange:paragraphRange];
253
+
254
+ for (NSValue *value in properRanges) {
197
255
  NSRange currRange = [value rangeValue];
198
256
  BOOL selfDetected = [self detectStyle:currRange];
199
-
200
- [_input->textView.textStorage enumerateAttribute:NSForegroundColorAttributeName inRange:currRange options:0
201
- usingBlock:^(id _Nullable value, NSRange range, BOOL * _Nonnull stop) {
202
- UIColor *newColor = nullptr;
203
- BOOL colorApplied = [(UIColor *)value isEqualToColor:[_input->config blockquoteColor]];
204
-
205
- if(colorApplied && !selfDetected) {
206
- newColor = [_input->config primaryColor];
207
- } else if(!colorApplied && selfDetected) {
208
- newColor = [_input->config blockquoteColor];
209
- }
210
-
211
- if(newColor != nullptr) {
212
- [_input->textView.textStorage addAttribute:NSForegroundColorAttributeName value:newColor range:currRange];
213
- [_input->textView.textStorage addAttribute:NSUnderlineColorAttributeName value:newColor range:currRange];
214
- [_input->textView.textStorage addAttribute:NSStrikethroughColorAttributeName value:newColor range:currRange];
215
- }
216
- }
217
- ];
257
+
258
+ [_input->textView.textStorage
259
+ enumerateAttribute:NSForegroundColorAttributeName
260
+ inRange:currRange
261
+ options:0
262
+ usingBlock:^(id _Nullable value, NSRange range,
263
+ BOOL *_Nonnull stop) {
264
+ UIColor *newColor = nullptr;
265
+ BOOL colorApplied = [(UIColor *)value
266
+ isEqualToColor:[_input->config blockquoteColor]];
267
+
268
+ if (colorApplied && !selfDetected) {
269
+ newColor = [_input->config primaryColor];
270
+ } else if (!colorApplied && selfDetected) {
271
+ newColor = [_input->config blockquoteColor];
272
+ }
273
+
274
+ if (newColor != nullptr) {
275
+ [_input->textView.textStorage
276
+ addAttribute:NSForegroundColorAttributeName
277
+ value:newColor
278
+ range:currRange];
279
+ [_input->textView.textStorage
280
+ addAttribute:NSUnderlineColorAttributeName
281
+ value:newColor
282
+ range:currRange];
283
+ [_input->textView.textStorage
284
+ addAttribute:NSStrikethroughColorAttributeName
285
+ value:newColor
286
+ range:currRange];
287
+ }
288
+ }];
218
289
  }
219
290
  }
220
291
  }