react-native-enriched 0.2.0 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +16 -17
- package/android/build.gradle +77 -72
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerDelegate.java +21 -0
- package/android/generated/java/com/facebook/react/viewmanagers/EnrichedTextInputViewManagerInterface.java +7 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.cpp +156 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/EventEmitters.h +147 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/Props.cpp +10 -0
- package/android/generated/jni/react/renderer/components/RNEnrichedTextInputViewSpec/Props.h +194 -0
- package/android/lint.gradle +70 -0
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputConnectionWrapper.kt +140 -0
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputView.kt +304 -83
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewLayoutManager.kt +3 -1
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewManager.kt +166 -51
- package/android/src/main/java/com/swmansion/enriched/EnrichedTextInputViewPackage.kt +1 -3
- package/android/src/main/java/com/swmansion/enriched/MeasurementStore.kt +70 -21
- package/android/src/main/java/com/swmansion/enriched/events/MentionHandler.kt +21 -11
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeHtmlEvent.kt +8 -9
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeSelectionEvent.kt +10 -9
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeStateDeprecatedEvent.kt +21 -0
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeStateEvent.kt +9 -12
- package/android/src/main/java/com/swmansion/enriched/events/OnChangeTextEvent.kt +10 -10
- package/android/src/main/java/com/swmansion/enriched/events/OnInputBlurEvent.kt +7 -9
- package/android/src/main/java/com/swmansion/enriched/events/OnInputFocusEvent.kt +7 -9
- package/android/src/main/java/com/swmansion/enriched/events/OnInputKeyPressEvent.kt +27 -0
- package/android/src/main/java/com/swmansion/enriched/events/OnLinkDetectedEvent.kt +13 -11
- package/android/src/main/java/com/swmansion/enriched/events/OnMentionDetectedEvent.kt +10 -9
- package/android/src/main/java/com/swmansion/enriched/events/OnMentionEvent.kt +9 -8
- package/android/src/main/java/com/swmansion/enriched/events/OnRequestHtmlResultEvent.kt +32 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBlockQuoteSpan.kt +24 -5
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedBoldSpan.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedCodeBlockSpan.kt +10 -2
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH1Span.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH2Span.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH3Span.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH4Span.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH5Span.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedH6Span.kt +24 -0
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedImageSpan.kt +34 -17
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedInlineCodeSpan.kt +8 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedItalicSpan.kt +7 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedLinkSpan.kt +10 -4
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedMentionSpan.kt +14 -11
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedOrderedListSpan.kt +18 -11
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedSpans.kt +174 -72
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedStrikeThroughSpan.kt +7 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnderlineSpan.kt +7 -1
- package/android/src/main/java/com/swmansion/enriched/spans/EnrichedUnorderedListSpan.kt +11 -5
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedBlockSpan.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedHeadingSpan.kt +1 -2
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedInlineSpan.kt +1 -2
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedParagraphSpan.kt +3 -2
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedSpan.kt +5 -0
- package/android/src/main/java/com/swmansion/enriched/spans/interfaces/EnrichedZeroWidthSpaceSpan.kt +1 -2
- package/android/src/main/java/com/swmansion/enriched/spans/utils/ForceRedrawSpan.kt +2 -1
- package/android/src/main/java/com/swmansion/enriched/styles/HtmlStyle.kt +155 -20
- package/android/src/main/java/com/swmansion/enriched/styles/InlineStyles.kt +25 -8
- package/android/src/main/java/com/swmansion/enriched/styles/ListStyles.kt +60 -20
- package/android/src/main/java/com/swmansion/enriched/styles/ParagraphStyles.kt +161 -25
- package/android/src/main/java/com/swmansion/enriched/styles/ParametrizedStyles.kt +128 -52
- package/android/src/main/java/com/swmansion/enriched/utils/AsyncDrawable.kt +10 -7
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedConstants.kt +11 -0
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedEditableFactory.kt +17 -0
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedParser.java +136 -87
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSelection.kt +71 -42
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpanState.kt +183 -48
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpannable.kt +82 -0
- package/android/src/main/java/com/swmansion/enriched/utils/EnrichedSpannableStringBuilder.kt +15 -0
- package/android/src/main/java/com/swmansion/enriched/utils/Utils.kt +0 -70
- package/android/src/main/java/com/swmansion/enriched/watchers/EnrichedSpanWatcher.kt +46 -14
- package/android/src/main/java/com/swmansion/enriched/watchers/EnrichedTextWatcher.kt +34 -11
- package/android/src/main/new_arch/CMakeLists.txt +6 -0
- package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.cpp +6 -6
- package/android/src/main/new_arch/RNEnrichedTextInputViewSpec.h +6 -6
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputComponentDescriptor.h +19 -19
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.cpp +40 -51
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputMeasurementManager.h +13 -15
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.cpp +23 -21
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputShadowNode.h +35 -36
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.cpp +4 -4
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/EnrichedTextInputState.h +13 -14
- package/android/src/main/new_arch/react/renderer/components/RNEnrichedTextInputViewSpec/conversions.h +33 -14
- package/ios/EnrichedTextInputView.h +26 -14
- package/ios/EnrichedTextInputView.mm +1209 -586
- package/ios/config/InputConfig.h +24 -6
- package/ios/config/InputConfig.mm +154 -38
- package/ios/{utils → extensions}/ColorExtension.mm +7 -5
- package/ios/extensions/FontExtension.mm +106 -0
- package/ios/{utils → extensions}/LayoutManagerExtension.h +1 -1
- package/ios/extensions/LayoutManagerExtension.mm +396 -0
- package/ios/{utils → extensions}/StringExtension.mm +19 -16
- package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.cpp +156 -0
- package/ios/generated/RNEnrichedTextInputViewSpec/EventEmitters.h +147 -0
- package/ios/generated/RNEnrichedTextInputViewSpec/Props.cpp +10 -0
- package/ios/generated/RNEnrichedTextInputViewSpec/Props.h +194 -0
- package/ios/generated/RNEnrichedTextInputViewSpec/RCTComponentViewHelpers.h +95 -0
- package/ios/inputParser/InputParser.h +5 -5
- package/ios/inputParser/InputParser.mm +864 -380
- package/ios/inputTextView/InputTextView.h +1 -1
- package/ios/inputTextView/InputTextView.mm +100 -59
- package/ios/{utils → interfaces}/BaseStyleProtocol.h +2 -2
- package/ios/interfaces/ImageAttachment.h +10 -0
- package/ios/interfaces/ImageAttachment.mm +36 -0
- package/ios/interfaces/LinkRegexConfig.h +19 -0
- package/ios/interfaces/LinkRegexConfig.mm +37 -0
- package/ios/interfaces/MediaAttachment.h +23 -0
- package/ios/interfaces/MediaAttachment.mm +31 -0
- package/ios/{utils → interfaces}/MentionParams.h +0 -1
- package/ios/{utils → interfaces}/MentionStyleProps.mm +27 -20
- package/ios/{utils → interfaces}/StyleHeaders.h +37 -15
- package/ios/{utils → interfaces}/StyleTypeEnum.h +3 -0
- package/ios/internals/EnrichedTextInputViewComponentDescriptor.h +11 -9
- package/ios/internals/EnrichedTextInputViewShadowNode.h +28 -25
- package/ios/internals/EnrichedTextInputViewShadowNode.mm +45 -40
- package/ios/internals/EnrichedTextInputViewState.h +3 -1
- package/ios/styles/BlockQuoteStyle.mm +189 -118
- package/ios/styles/BoldStyle.mm +110 -63
- package/ios/styles/CodeBlockStyle.mm +204 -128
- package/ios/styles/H1Style.mm +10 -4
- package/ios/styles/H2Style.mm +10 -4
- package/ios/styles/H3Style.mm +10 -4
- package/ios/styles/H4Style.mm +17 -0
- package/ios/styles/H5Style.mm +17 -0
- package/ios/styles/H6Style.mm +17 -0
- package/ios/styles/HeadingStyleBase.mm +148 -86
- package/ios/styles/ImageStyle.mm +75 -73
- package/ios/styles/InlineCodeStyle.mm +162 -88
- package/ios/styles/ItalicStyle.mm +76 -52
- package/ios/styles/LinkStyle.mm +411 -232
- package/ios/styles/MentionStyle.mm +363 -246
- package/ios/styles/OrderedListStyle.mm +171 -106
- package/ios/styles/StrikethroughStyle.mm +52 -35
- package/ios/styles/UnderlineStyle.mm +68 -46
- package/ios/styles/UnorderedListStyle.mm +169 -106
- package/ios/utils/OccurenceUtils.h +42 -42
- package/ios/utils/OccurenceUtils.mm +142 -119
- package/ios/utils/ParagraphAttributesUtils.h +10 -2
- package/ios/utils/ParagraphAttributesUtils.mm +182 -71
- package/ios/utils/ParagraphsUtils.h +2 -1
- package/ios/utils/ParagraphsUtils.mm +41 -27
- package/ios/utils/TextInsertionUtils.h +13 -2
- package/ios/utils/TextInsertionUtils.mm +38 -20
- package/ios/utils/WordsUtils.h +2 -1
- package/ios/utils/WordsUtils.mm +32 -22
- package/ios/utils/ZeroWidthSpaceUtils.h +3 -1
- package/ios/utils/ZeroWidthSpaceUtils.mm +145 -79
- package/lib/module/EnrichedTextInput.js +61 -2
- package/lib/module/EnrichedTextInput.js.map +1 -1
- package/lib/module/EnrichedTextInputNativeComponent.ts +149 -12
- package/lib/module/{normalizeHtmlStyle.js → utils/normalizeHtmlStyle.js} +12 -0
- package/lib/module/utils/normalizeHtmlStyle.js.map +1 -0
- package/lib/module/utils/regexParser.js +46 -0
- package/lib/module/utils/regexParser.js.map +1 -0
- package/lib/typescript/src/EnrichedTextInput.d.ts +24 -14
- package/lib/typescript/src/EnrichedTextInput.d.ts.map +1 -1
- package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts +129 -12
- package/lib/typescript/src/EnrichedTextInputNativeComponent.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts +4 -0
- package/lib/typescript/src/utils/normalizeHtmlStyle.d.ts.map +1 -0
- package/lib/typescript/src/utils/regexParser.d.ts +3 -0
- package/lib/typescript/src/utils/regexParser.d.ts.map +1 -0
- package/package.json +17 -6
- package/src/EnrichedTextInput.tsx +96 -13
- package/src/EnrichedTextInputNativeComponent.ts +149 -12
- package/src/index.tsx +2 -0
- package/src/{normalizeHtmlStyle.ts → utils/normalizeHtmlStyle.ts} +14 -2
- package/src/utils/regexParser.ts +56 -0
- package/ios/utils/FontExtension.mm +0 -91
- package/ios/utils/LayoutManagerExtension.mm +0 -286
- package/lib/module/normalizeHtmlStyle.js.map +0 -1
- package/lib/typescript/src/normalizeHtmlStyle.d.ts +0 -4
- package/lib/typescript/src/normalizeHtmlStyle.d.ts.map +0 -1
- package/ios/{utils → extensions}/ColorExtension.h +0 -0
- package/ios/{utils → extensions}/FontExtension.h +0 -0
- package/ios/{utils → extensions}/StringExtension.h +1 -1
- package/ios/{utils → interfaces}/ImageData.h +0 -0
- package/ios/{utils → interfaces}/ImageData.mm +0 -0
- package/ios/{utils → interfaces}/LinkData.h +0 -0
- package/ios/{utils → interfaces}/LinkData.mm +0 -0
- package/ios/{utils → interfaces}/MentionParams.mm +0 -0
- package/ios/{utils → interfaces}/MentionStyleProps.h +1 -1
- /package/ios/{utils → interfaces}/StylePair.h +0 -0
- /package/ios/{utils → interfaces}/StylePair.mm +0 -0
- /package/ios/{utils → interfaces}/TextDecorationLineEnum.h +0 -0
- /package/ios/{utils → interfaces}/TextDecorationLineEnum.mm +0 -0
package/ios/config/InputConfig.h
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
#pragma once
|
|
2
|
-
#import
|
|
3
|
-
#import "TextDecorationLineEnum.h"
|
|
2
|
+
#import "LinkRegexConfig.h"
|
|
4
3
|
#import "MentionStyleProps.h"
|
|
4
|
+
#import "TextDecorationLineEnum.h"
|
|
5
|
+
#import <UIKit/UIKit.h>
|
|
5
6
|
|
|
6
|
-
@interface InputConfig: NSObject<NSCopying>
|
|
7
|
-
- (instancetype)
|
|
7
|
+
@interface InputConfig : NSObject <NSCopying>
|
|
8
|
+
- (instancetype)init;
|
|
8
9
|
- (UIColor *)primaryColor;
|
|
9
10
|
- (void)setPrimaryColor:(UIColor *)newValue;
|
|
10
11
|
- (NSNumber *)primaryFontSize;
|
|
@@ -15,8 +16,8 @@
|
|
|
15
16
|
- (void)setPrimaryFontFamily:(NSString *)newValue;
|
|
16
17
|
- (UIFont *)primaryFont;
|
|
17
18
|
- (UIFont *)monospacedFont;
|
|
18
|
-
- (NSSet<NSNumber
|
|
19
|
-
- (void)setMentionIndicators:(NSSet<NSNumber
|
|
19
|
+
- (NSSet<NSNumber *> *)mentionIndicators;
|
|
20
|
+
- (void)setMentionIndicators:(NSSet<NSNumber *> *)newValue;
|
|
20
21
|
- (CGFloat)h1FontSize;
|
|
21
22
|
- (void)setH1FontSize:(CGFloat)newValue;
|
|
22
23
|
- (BOOL)h1Bold;
|
|
@@ -29,6 +30,18 @@
|
|
|
29
30
|
- (void)setH3FontSize:(CGFloat)newValue;
|
|
30
31
|
- (BOOL)h3Bold;
|
|
31
32
|
- (void)setH3Bold:(BOOL)newValue;
|
|
33
|
+
- (CGFloat)h4FontSize;
|
|
34
|
+
- (void)setH4FontSize:(CGFloat)newValue;
|
|
35
|
+
- (BOOL)h4Bold;
|
|
36
|
+
- (void)setH4Bold:(BOOL)newValue;
|
|
37
|
+
- (CGFloat)h5FontSize;
|
|
38
|
+
- (void)setH5FontSize:(CGFloat)newValue;
|
|
39
|
+
- (BOOL)h5Bold;
|
|
40
|
+
- (void)setH5Bold:(BOOL)newValue;
|
|
41
|
+
- (CGFloat)h6FontSize;
|
|
42
|
+
- (void)setH6FontSize:(CGFloat)newValue;
|
|
43
|
+
- (BOOL)h6Bold;
|
|
44
|
+
- (void)setH6Bold:(BOOL)newValue;
|
|
32
45
|
- (UIColor *)blockquoteBorderColor;
|
|
33
46
|
- (void)setBlockquoteBorderColor:(UIColor *)newValue;
|
|
34
47
|
- (CGFloat)blockquoteBorderWidth;
|
|
@@ -70,4 +83,9 @@
|
|
|
70
83
|
- (void)setCodeBlockBgColor:(UIColor *)newValue;
|
|
71
84
|
- (CGFloat)codeBlockBorderRadius;
|
|
72
85
|
- (void)setCodeBlockBorderRadius:(CGFloat)newValue;
|
|
86
|
+
- (LinkRegexConfig *)linkRegexConfig;
|
|
87
|
+
- (void)setLinkRegexConfig:(LinkRegexConfig *)newValue;
|
|
88
|
+
- (NSRegularExpression *)parsedLinkRegex;
|
|
89
|
+
- (void)invalidateFonts;
|
|
90
|
+
- (NSNumber *)scaledPrimaryFontSize;
|
|
73
91
|
@end
|
|
@@ -10,13 +10,19 @@
|
|
|
10
10
|
UIFont *_monospacedFont;
|
|
11
11
|
BOOL _primaryFontNeedsRecreation;
|
|
12
12
|
BOOL _monospacedFontNeedsRecreation;
|
|
13
|
-
NSSet<NSNumber*> *_mentionIndicators;
|
|
13
|
+
NSSet<NSNumber *> *_mentionIndicators;
|
|
14
14
|
CGFloat _h1FontSize;
|
|
15
15
|
BOOL _h1Bold;
|
|
16
16
|
CGFloat _h2FontSize;
|
|
17
17
|
BOOL _h2Bold;
|
|
18
18
|
CGFloat _h3FontSize;
|
|
19
19
|
BOOL _h3Bold;
|
|
20
|
+
CGFloat _h4FontSize;
|
|
21
|
+
BOOL _h4Bold;
|
|
22
|
+
CGFloat _h5FontSize;
|
|
23
|
+
BOOL _h5Bold;
|
|
24
|
+
CGFloat _h6FontSize;
|
|
25
|
+
BOOL _h6Bold;
|
|
20
26
|
UIColor *_blockquoteBorderColor;
|
|
21
27
|
CGFloat _blockquoteBorderWidth;
|
|
22
28
|
CGFloat _blockquoteGapWidth;
|
|
@@ -39,11 +45,11 @@
|
|
|
39
45
|
UIColor *_codeBlockFgColor;
|
|
40
46
|
CGFloat _codeBlockBorderRadius;
|
|
41
47
|
UIColor *_codeBlockBgColor;
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
LinkRegexConfig *_linkRegexConfig;
|
|
49
|
+
NSRegularExpression *_parsedLinkRegex;
|
|
44
50
|
}
|
|
45
51
|
|
|
46
|
-
- (instancetype)
|
|
52
|
+
- (instancetype)init {
|
|
47
53
|
self = [super init];
|
|
48
54
|
_primaryFontNeedsRecreation = YES;
|
|
49
55
|
_monospacedFontNeedsRecreation = YES;
|
|
@@ -66,6 +72,12 @@
|
|
|
66
72
|
copy->_h2Bold = _h2Bold;
|
|
67
73
|
copy->_h3FontSize = _h3FontSize;
|
|
68
74
|
copy->_h3Bold = _h3Bold;
|
|
75
|
+
copy->_h4FontSize = _h4FontSize;
|
|
76
|
+
copy->_h4Bold = _h4Bold;
|
|
77
|
+
copy->_h5FontSize = _h5FontSize;
|
|
78
|
+
copy->_h5Bold = _h5Bold;
|
|
79
|
+
copy->_h6FontSize = _h6FontSize;
|
|
80
|
+
copy->_h6Bold = _h6Bold;
|
|
69
81
|
copy->_blockquoteBorderColor = [_blockquoteBorderColor copy];
|
|
70
82
|
copy->_blockquoteBorderWidth = _blockquoteBorderWidth;
|
|
71
83
|
copy->_blockquoteGapWidth = _blockquoteGapWidth;
|
|
@@ -87,6 +99,8 @@
|
|
|
87
99
|
copy->_codeBlockFgColor = [_codeBlockFgColor copy];
|
|
88
100
|
copy->_codeBlockBgColor = [_codeBlockBgColor copy];
|
|
89
101
|
copy->_codeBlockBorderRadius = _codeBlockBorderRadius;
|
|
102
|
+
copy->_linkRegexConfig = [_linkRegexConfig copy];
|
|
103
|
+
copy->_parsedLinkRegex = [_parsedLinkRegex copy];
|
|
90
104
|
return copy;
|
|
91
105
|
}
|
|
92
106
|
|
|
@@ -110,7 +124,9 @@
|
|
|
110
124
|
}
|
|
111
125
|
|
|
112
126
|
- (NSString *)primaryFontWeight {
|
|
113
|
-
return _primaryFontWeight != nullptr
|
|
127
|
+
return _primaryFontWeight != nullptr
|
|
128
|
+
? _primaryFontWeight
|
|
129
|
+
: [NSString stringWithFormat:@"%@", @(UIFontWeightRegular)];
|
|
114
130
|
}
|
|
115
131
|
|
|
116
132
|
- (void)setPrimaryFontWeight:(NSString *)newValue {
|
|
@@ -130,46 +146,50 @@
|
|
|
130
146
|
}
|
|
131
147
|
|
|
132
148
|
- (UIFont *)primaryFont {
|
|
133
|
-
if(_primaryFontNeedsRecreation) {
|
|
149
|
+
if (_primaryFontNeedsRecreation) {
|
|
134
150
|
_primaryFontNeedsRecreation = NO;
|
|
135
|
-
|
|
151
|
+
|
|
136
152
|
NSString *newFontWeight = [self primaryFontWeight];
|
|
137
153
|
// fix RCTFontWeight conversion warnings:
|
|
138
154
|
// sometimes changing font family comes with weight '0' if not specified
|
|
139
|
-
// RCTConvert doesn't recognize this value so we just nullify it and it gets
|
|
140
|
-
|
|
155
|
+
// RCTConvert doesn't recognize this value so we just nullify it and it gets
|
|
156
|
+
// a default value
|
|
157
|
+
if ([newFontWeight isEqualToString:@"0"]) {
|
|
141
158
|
newFontWeight = nullptr;
|
|
142
159
|
}
|
|
143
|
-
|
|
160
|
+
|
|
144
161
|
_primaryFont = [RCTFont updateFont:nullptr
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
162
|
+
withFamily:[self primaryFontFamily]
|
|
163
|
+
size:[self scaledPrimaryFontSize]
|
|
164
|
+
weight:newFontWeight
|
|
165
|
+
style:nullptr
|
|
166
|
+
variant:nullptr
|
|
167
|
+
scaleMultiplier:1];
|
|
151
168
|
}
|
|
152
169
|
return _primaryFont;
|
|
153
170
|
}
|
|
154
171
|
|
|
155
172
|
- (UIFont *)monospacedFont {
|
|
156
|
-
if(_monospacedFontNeedsRecreation) {
|
|
173
|
+
if (_monospacedFontNeedsRecreation) {
|
|
157
174
|
_monospacedFontNeedsRecreation = NO;
|
|
158
|
-
_monospacedFont = [UIFont
|
|
175
|
+
_monospacedFont = [UIFont
|
|
176
|
+
monospacedSystemFontOfSize:[[self scaledPrimaryFontSize] floatValue]
|
|
177
|
+
weight:[[self primaryFontWeight] floatValue]];
|
|
159
178
|
}
|
|
160
179
|
return _monospacedFont;
|
|
161
180
|
}
|
|
162
181
|
|
|
163
|
-
- (NSSet<NSNumber
|
|
164
|
-
return _mentionIndicators != nullptr ? _mentionIndicators
|
|
182
|
+
- (NSSet<NSNumber *> *)mentionIndicators {
|
|
183
|
+
return _mentionIndicators != nullptr ? _mentionIndicators
|
|
184
|
+
: [[NSSet alloc] init];
|
|
165
185
|
}
|
|
166
186
|
|
|
167
|
-
- (void)setMentionIndicators:(NSSet<NSNumber
|
|
187
|
+
- (void)setMentionIndicators:(NSSet<NSNumber *> *)newValue {
|
|
168
188
|
_mentionIndicators = newValue;
|
|
169
189
|
}
|
|
170
190
|
|
|
171
191
|
- (CGFloat)h1FontSize {
|
|
172
|
-
return _h1FontSize;
|
|
192
|
+
return [[UIFontMetrics defaultMetrics] scaledValueForValue:_h1FontSize];
|
|
173
193
|
}
|
|
174
194
|
|
|
175
195
|
- (void)setH1FontSize:(CGFloat)newValue {
|
|
@@ -185,7 +205,7 @@
|
|
|
185
205
|
}
|
|
186
206
|
|
|
187
207
|
- (CGFloat)h2FontSize {
|
|
188
|
-
return _h2FontSize;
|
|
208
|
+
return [[UIFontMetrics defaultMetrics] scaledValueForValue:_h2FontSize];
|
|
189
209
|
}
|
|
190
210
|
|
|
191
211
|
- (void)setH2FontSize:(CGFloat)newValue {
|
|
@@ -201,7 +221,7 @@
|
|
|
201
221
|
}
|
|
202
222
|
|
|
203
223
|
- (CGFloat)h3FontSize {
|
|
204
|
-
return _h3FontSize;
|
|
224
|
+
return [[UIFontMetrics defaultMetrics] scaledValueForValue:_h3FontSize];
|
|
205
225
|
}
|
|
206
226
|
|
|
207
227
|
- (void)setH3FontSize:(CGFloat)newValue {
|
|
@@ -216,6 +236,54 @@
|
|
|
216
236
|
_h3Bold = newValue;
|
|
217
237
|
}
|
|
218
238
|
|
|
239
|
+
- (CGFloat)h4FontSize {
|
|
240
|
+
return [[UIFontMetrics defaultMetrics] scaledValueForValue:_h4FontSize];
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
- (void)setH4FontSize:(CGFloat)newValue {
|
|
244
|
+
_h4FontSize = newValue;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
- (BOOL)h4Bold {
|
|
248
|
+
return _h4Bold;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
- (void)setH4Bold:(BOOL)newValue {
|
|
252
|
+
_h4Bold = newValue;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
- (CGFloat)h5FontSize {
|
|
256
|
+
return [[UIFontMetrics defaultMetrics] scaledValueForValue:_h5FontSize];
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
- (void)setH5FontSize:(CGFloat)newValue {
|
|
260
|
+
_h5FontSize = newValue;
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
- (BOOL)h5Bold {
|
|
264
|
+
return _h5Bold;
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
- (void)setH5Bold:(BOOL)newValue {
|
|
268
|
+
_h5Bold = newValue;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
- (CGFloat)h6FontSize {
|
|
272
|
+
return [[UIFontMetrics defaultMetrics] scaledValueForValue:_h6FontSize];
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
- (void)setH6FontSize:(CGFloat)newValue {
|
|
276
|
+
_h6FontSize = newValue;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
- (BOOL)h6Bold {
|
|
280
|
+
return _h6Bold;
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
- (void)setH6Bold:(BOOL)newValue {
|
|
284
|
+
_h6Bold = newValue;
|
|
285
|
+
}
|
|
286
|
+
|
|
219
287
|
- (UIColor *)blockquoteBorderColor {
|
|
220
288
|
return _blockquoteBorderColor;
|
|
221
289
|
}
|
|
@@ -232,7 +300,6 @@
|
|
|
232
300
|
_blockquoteBorderWidth = newValue;
|
|
233
301
|
}
|
|
234
302
|
|
|
235
|
-
|
|
236
303
|
- (CGFloat)blockquoteGapWidth {
|
|
237
304
|
return _blockquoteGapWidth;
|
|
238
305
|
}
|
|
@@ -299,24 +366,25 @@
|
|
|
299
366
|
}
|
|
300
367
|
|
|
301
368
|
- (UIFont *)orderedListMarkerFont {
|
|
302
|
-
if(_olMarkerFontNeedsRecreation) {
|
|
369
|
+
if (_olMarkerFontNeedsRecreation) {
|
|
303
370
|
_olMarkerFontNeedsRecreation = NO;
|
|
304
|
-
|
|
371
|
+
|
|
305
372
|
NSString *newFontWeight = [self orderedListMarkerFontWeight];
|
|
306
373
|
// fix RCTFontWeight conversion warnings:
|
|
307
374
|
// sometimes changing font family comes with weight '0' if not specified
|
|
308
|
-
// RCTConvert doesn't recognize this value so we just nullify it and it gets
|
|
309
|
-
|
|
375
|
+
// RCTConvert doesn't recognize this value so we just nullify it and it gets
|
|
376
|
+
// a default value
|
|
377
|
+
if ([newFontWeight isEqualToString:@"0"]) {
|
|
310
378
|
newFontWeight = nullptr;
|
|
311
379
|
}
|
|
312
|
-
|
|
380
|
+
|
|
313
381
|
_orderedListMarkerFont = [RCTFont updateFont:nullptr
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
382
|
+
withFamily:[self primaryFontFamily]
|
|
383
|
+
size:[self scaledPrimaryFontSize]
|
|
384
|
+
weight:newFontWeight
|
|
385
|
+
style:nullptr
|
|
386
|
+
variant:nullptr
|
|
387
|
+
scaleMultiplier:1];
|
|
320
388
|
}
|
|
321
389
|
return _orderedListMarkerFont;
|
|
322
390
|
}
|
|
@@ -374,10 +442,10 @@
|
|
|
374
442
|
}
|
|
375
443
|
|
|
376
444
|
- (MentionStyleProps *)mentionStylePropsForIndicator:(NSString *)indicator {
|
|
377
|
-
if(_mentionProperties.count == 1 && _mentionProperties[@"all"] != nullptr) {
|
|
445
|
+
if (_mentionProperties.count == 1 && _mentionProperties[@"all"] != nullptr) {
|
|
378
446
|
// single props for all the indicators
|
|
379
447
|
return _mentionProperties[@"all"];
|
|
380
|
-
} else if(_mentionProperties[indicator] != nullptr) {
|
|
448
|
+
} else if (_mentionProperties[indicator] != nullptr) {
|
|
381
449
|
return _mentionProperties[indicator];
|
|
382
450
|
}
|
|
383
451
|
MentionStyleProps *fallbackProps = [[MentionStyleProps alloc] init];
|
|
@@ -411,4 +479,52 @@
|
|
|
411
479
|
_codeBlockBorderRadius = newValue;
|
|
412
480
|
}
|
|
413
481
|
|
|
482
|
+
- (LinkRegexConfig *)linkRegexConfig {
|
|
483
|
+
return _linkRegexConfig;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
- (void)setLinkRegexConfig:(LinkRegexConfig *)newValue {
|
|
487
|
+
_linkRegexConfig = newValue;
|
|
488
|
+
|
|
489
|
+
// try initializing the native regular expression if it applies
|
|
490
|
+
if (_linkRegexConfig.isDefault || _linkRegexConfig.isDisabled) {
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
NSError *regexInitError;
|
|
495
|
+
NSRegularExpressionOptions options =
|
|
496
|
+
(_linkRegexConfig.caseInsensitive ? NSRegularExpressionCaseInsensitive
|
|
497
|
+
: 0) |
|
|
498
|
+
(_linkRegexConfig.dotAll ? NSRegularExpressionDotMatchesLineSeparators
|
|
499
|
+
: 0);
|
|
500
|
+
NSRegularExpression *userRegex =
|
|
501
|
+
[NSRegularExpression regularExpressionWithPattern:_linkRegexConfig.pattern
|
|
502
|
+
options:options
|
|
503
|
+
error:®exInitError];
|
|
504
|
+
|
|
505
|
+
if (regexInitError) {
|
|
506
|
+
RCTLogWarn(@"[EnrichedTextInput]: Couldn't parse the user-defined link "
|
|
507
|
+
@"regex, falling back to a default regex.");
|
|
508
|
+
_parsedLinkRegex = nullptr;
|
|
509
|
+
} else {
|
|
510
|
+
_parsedLinkRegex = userRegex;
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
- (NSRegularExpression *)parsedLinkRegex {
|
|
515
|
+
return _parsedLinkRegex;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
- (void)invalidateFonts {
|
|
519
|
+
_primaryFontNeedsRecreation = YES;
|
|
520
|
+
_monospacedFontNeedsRecreation = YES;
|
|
521
|
+
_olMarkerFontNeedsRecreation = YES;
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
- (NSNumber *)scaledPrimaryFontSize {
|
|
525
|
+
CGFloat scaledSize = [[UIFontMetrics defaultMetrics]
|
|
526
|
+
scaledValueForValue:[[self primaryFontSize] floatValue]];
|
|
527
|
+
return @(scaledSize);
|
|
528
|
+
}
|
|
529
|
+
|
|
414
530
|
@end
|
|
@@ -4,11 +4,13 @@
|
|
|
4
4
|
- (BOOL)isEqualToColor:(UIColor *)otherColor {
|
|
5
5
|
CGColorSpaceRef colorSpaceRGB = CGColorSpaceCreateDeviceRGB();
|
|
6
6
|
|
|
7
|
-
UIColor *(^convertColorToRGBSpace)(UIColor*) = ^(UIColor *color) {
|
|
8
|
-
if(CGColorSpaceGetModel(CGColorGetColorSpace(color.CGColor)) ==
|
|
7
|
+
UIColor * (^convertColorToRGBSpace)(UIColor *) = ^(UIColor *color) {
|
|
8
|
+
if (CGColorSpaceGetModel(CGColorGetColorSpace(color.CGColor)) ==
|
|
9
|
+
kCGColorSpaceModelMonochrome) {
|
|
9
10
|
const CGFloat *oldComponents = CGColorGetComponents(color.CGColor);
|
|
10
|
-
CGFloat components[4] = {oldComponents[0], oldComponents[0],
|
|
11
|
-
|
|
11
|
+
CGFloat components[4] = {oldComponents[0], oldComponents[0],
|
|
12
|
+
oldComponents[0], oldComponents[1]};
|
|
13
|
+
CGColorRef colorRef = CGColorCreate(colorSpaceRGB, components);
|
|
12
14
|
|
|
13
15
|
UIColor *color = [UIColor colorWithCGColor:colorRef];
|
|
14
16
|
CGColorRelease(colorRef);
|
|
@@ -29,7 +31,7 @@
|
|
|
29
31
|
CGFloat alpha = 0.0;
|
|
30
32
|
[self getRed:nil green:nil blue:nil alpha:&alpha];
|
|
31
33
|
if (alpha > 0.0) {
|
|
32
|
-
|
|
34
|
+
return [self colorWithAlphaComponent:newAlpha];
|
|
33
35
|
}
|
|
34
36
|
return self;
|
|
35
37
|
}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
#import "FontExtension.h"
|
|
2
|
+
#import <React/RCTLog.h>
|
|
3
|
+
|
|
4
|
+
@implementation UIFont (FontExtension)
|
|
5
|
+
|
|
6
|
+
- (BOOL)isBold {
|
|
7
|
+
return (self.fontDescriptor.symbolicTraits & UIFontDescriptorTraitBold) ==
|
|
8
|
+
UIFontDescriptorTraitBold;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
- (UIFont *)setBold {
|
|
12
|
+
if ([self isBold]) {
|
|
13
|
+
return self;
|
|
14
|
+
}
|
|
15
|
+
UIFontDescriptorSymbolicTraits newTraits =
|
|
16
|
+
(self.fontDescriptor.symbolicTraits | UIFontDescriptorTraitBold);
|
|
17
|
+
UIFontDescriptor *fontDescriptor =
|
|
18
|
+
[self.fontDescriptor fontDescriptorWithSymbolicTraits:newTraits];
|
|
19
|
+
if (fontDescriptor != nullptr) {
|
|
20
|
+
return [UIFont fontWithDescriptor:fontDescriptor size:0];
|
|
21
|
+
} else {
|
|
22
|
+
RCTLogWarn(@"[EnrichedTextInput]: Couldn't apply bold trait to the font.");
|
|
23
|
+
return self;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
- (UIFont *)removeBold {
|
|
28
|
+
if (![self isBold]) {
|
|
29
|
+
return self;
|
|
30
|
+
}
|
|
31
|
+
UIFontDescriptorSymbolicTraits newTraits =
|
|
32
|
+
(self.fontDescriptor.symbolicTraits ^ UIFontDescriptorTraitBold);
|
|
33
|
+
UIFontDescriptor *fontDescriptor =
|
|
34
|
+
[self.fontDescriptor fontDescriptorWithSymbolicTraits:newTraits];
|
|
35
|
+
if (fontDescriptor != nullptr) {
|
|
36
|
+
return [UIFont fontWithDescriptor:fontDescriptor size:0];
|
|
37
|
+
} else {
|
|
38
|
+
RCTLogWarn(
|
|
39
|
+
@"[EnrichedTextInput]: Couldn't remove bold trait from the font.");
|
|
40
|
+
return self;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
- (BOOL)isItalic {
|
|
45
|
+
return (self.fontDescriptor.symbolicTraits & UIFontDescriptorTraitItalic) ==
|
|
46
|
+
UIFontDescriptorTraitItalic;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
- (UIFont *)setItalic {
|
|
50
|
+
if ([self isItalic]) {
|
|
51
|
+
return self;
|
|
52
|
+
}
|
|
53
|
+
UIFontDescriptorSymbolicTraits newTraits =
|
|
54
|
+
(self.fontDescriptor.symbolicTraits | UIFontDescriptorTraitItalic);
|
|
55
|
+
UIFontDescriptor *fontDescriptor =
|
|
56
|
+
[self.fontDescriptor fontDescriptorWithSymbolicTraits:newTraits];
|
|
57
|
+
if (fontDescriptor != nullptr) {
|
|
58
|
+
return [UIFont fontWithDescriptor:fontDescriptor size:0];
|
|
59
|
+
} else {
|
|
60
|
+
RCTLogWarn(
|
|
61
|
+
@"[EnrichedTextInput]: Couldn't apply italic trait to the font.");
|
|
62
|
+
return self;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
- (UIFont *)removeItalic {
|
|
67
|
+
if (![self isItalic]) {
|
|
68
|
+
return self;
|
|
69
|
+
}
|
|
70
|
+
UIFontDescriptorSymbolicTraits newTraits =
|
|
71
|
+
(self.fontDescriptor.symbolicTraits ^ UIFontDescriptorTraitItalic);
|
|
72
|
+
UIFontDescriptor *fontDescriptor =
|
|
73
|
+
[self.fontDescriptor fontDescriptorWithSymbolicTraits:newTraits];
|
|
74
|
+
if (fontDescriptor != nullptr) {
|
|
75
|
+
return [UIFont fontWithDescriptor:fontDescriptor size:0];
|
|
76
|
+
} else {
|
|
77
|
+
RCTLogWarn(
|
|
78
|
+
@"[EnrichedTextInput]: Couldn't remove italic trait from the font.");
|
|
79
|
+
return self;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
- (UIFont *)withFontTraits:(UIFont *)from {
|
|
84
|
+
UIFont *newFont = self;
|
|
85
|
+
if ([from isBold]) {
|
|
86
|
+
newFont = [newFont setBold];
|
|
87
|
+
}
|
|
88
|
+
if ([from isItalic]) {
|
|
89
|
+
newFont = [newFont setItalic];
|
|
90
|
+
}
|
|
91
|
+
return newFont;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
- (UIFont *)setSize:(CGFloat)size {
|
|
95
|
+
UIFontDescriptor *newFontDescriptor =
|
|
96
|
+
[self.fontDescriptor fontDescriptorWithSize:size];
|
|
97
|
+
if (newFontDescriptor != nullptr) {
|
|
98
|
+
return [UIFont fontWithDescriptor:newFontDescriptor size:0];
|
|
99
|
+
} else {
|
|
100
|
+
RCTLogWarn(
|
|
101
|
+
@"[EnrichedTextInput]: Couldn't apply heading style to the font.");
|
|
102
|
+
return self;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@end
|