Skip to content

Commit 1b9b225

Browse files
committed
fix: rebase with latest main
1 parent ec86b49 commit 1b9b225

19 files changed

Lines changed: 716 additions & 562 deletions

ios/EnrichedTextInputView.mm

Lines changed: 65 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#import "EnrichedTextInputView.h"
2+
#import "ColorExtension.h"
23
#import "CoreText/CoreText.h"
34
#import "LayoutManagerExtension.h"
45
#import "ParagraphAttributesUtils.h"
@@ -15,7 +16,6 @@
1516
#import <ReactNativeEnriched/RCTComponentViewHelpers.h>
1617
#import <folly/dynamic.h>
1718
#import <react/utils/ManagedObjectWrapper.h>
18-
#import "ColorExtension.h"
1919

2020
using namespace facebook::react;
2121

@@ -123,13 +123,16 @@ - (void)setDefaults {
123123
@([ItalicStyle getStyleType]) : @[],
124124
@([UnderlineStyle getStyleType]) : @[],
125125
@([StrikethroughStyle getStyleType]) : @[],
126-
@([InlineCodeStyle getStyleType]) :
127-
@[ @([LinkStyle getStyleType]), @([MentionStyle getStyleType]) ],
126+
@([InlineCodeStyle getStyleType]) : @[
127+
@([LinkStyle getStyleType]), @([MentionStyle getStyleType]),
128+
@([ColorStyle getStyleType])
129+
],
128130
@([LinkStyle getStyleType]) : @[
129131
@([InlineCodeStyle getStyleType]), @([LinkStyle getStyleType]),
130132
@([MentionStyle getStyleType])
131133
],
132-
@([ColorStyle getStyleType]) : @[@([InlineCodeStyle getStyleType]), @([MentionStyle getStyleType])],
134+
@([ColorStyle getStyleType]) :
135+
@[ @([InlineCodeStyle getStyleType]), @([MentionStyle getStyleType]) ],
133136
@([MentionStyle getStyleType]) :
134137
@[ @([InlineCodeStyle getStyleType]), @([LinkStyle getStyleType]) ],
135138
@([H1Style getStyleType]) : @[
@@ -193,7 +196,7 @@ - (void)setDefaults {
193196
@([H3Style getStyleType]), @([H4Style getStyleType]),
194197
@([H5Style getStyleType]), @([H6Style getStyleType]),
195198
@([UnorderedListStyle getStyleType]), @([OrderedListStyle getStyleType]),
196-
@([CodeBlockStyle getStyleType])
199+
@([CodeBlockStyle getStyleType]), @([ColorStyle getStyleType])
197200
],
198201
@([CodeBlockStyle getStyleType]) : @[
199202
@([H1Style getStyleType]), @([H2Style getStyleType]),
@@ -966,7 +969,8 @@ - (void)tryUpdatingActiveStyles {
966969
[_activeStyles containsObject:@([UnderlineStyle getStyleType])],
967970
.isStrikeThrough =
968971
[_activeStyles containsObject:@([StrikethroughStyle getStyleType])],
969-
.isColored = [_activeStyles containsObject: @([ColorStyle getStyleType])],
972+
.isColored =
973+
[_activeStyles containsObject:@([ColorStyle getStyleType])],
970974
.isInlineCode =
971975
[_activeStyles containsObject:@([InlineCodeStyle getStyleType])],
972976
.isLink = [_activeStyles containsObject:@([LinkStyle getStyleType])],
@@ -1022,24 +1026,24 @@ - (void)handleCommand:(const NSString *)commandName args:(const NSArray *)args {
10221026
} else if ([commandName isEqualToString:@"setValue"]) {
10231027
NSString *value = (NSString *)args[0];
10241028
[self setValue:value];
1025-
} else if([commandName isEqualToString:@"toggleBold"]) {
1026-
[self toggleRegularStyle: [BoldStyle getStyleType]];
1027-
} else if([commandName isEqualToString:@"toggleItalic"]) {
1028-
[self toggleRegularStyle: [ItalicStyle getStyleType]];
1029-
} else if([commandName isEqualToString:@"toggleUnderline"]) {
1030-
[self toggleRegularStyle: [UnderlineStyle getStyleType]];
1031-
} else if([commandName isEqualToString:@"toggleStrikeThrough"]) {
1032-
[self toggleRegularStyle: [StrikethroughStyle getStyleType]];
1033-
} else if([commandName isEqualToString:@"setColor"]) {
1029+
} else if ([commandName isEqualToString:@"toggleBold"]) {
1030+
[self toggleRegularStyle:[BoldStyle getStyleType]];
1031+
} else if ([commandName isEqualToString:@"toggleItalic"]) {
1032+
[self toggleRegularStyle:[ItalicStyle getStyleType]];
1033+
} else if ([commandName isEqualToString:@"toggleUnderline"]) {
1034+
[self toggleRegularStyle:[UnderlineStyle getStyleType]];
1035+
} else if ([commandName isEqualToString:@"toggleStrikeThrough"]) {
1036+
[self toggleRegularStyle:[StrikethroughStyle getStyleType]];
1037+
} else if ([commandName isEqualToString:@"setColor"]) {
10341038
NSString *colorText = (NSString *)args[0];
1035-
[self setColor: colorText];
1039+
[self setColor:colorText];
10361040
} else if ([commandName isEqualToString:@"removeColor"]) {
10371041
[self removeColor];
1038-
} else if([commandName isEqualToString:@"toggleInlineCode"]) {
1039-
[self toggleRegularStyle: [InlineCodeStyle getStyleType]];
1040-
} else if([commandName isEqualToString:@"addLink"]) {
1041-
NSInteger start = [((NSNumber*)args[0]) integerValue];
1042-
NSInteger end = [((NSNumber*)args[1]) integerValue];
1042+
} else if ([commandName isEqualToString:@"toggleInlineCode"]) {
1043+
[self toggleRegularStyle:[InlineCodeStyle getStyleType]];
1044+
} else if ([commandName isEqualToString:@"addLink"]) {
1045+
NSInteger start = [((NSNumber *)args[0]) integerValue];
1046+
NSInteger end = [((NSNumber *)args[1]) integerValue];
10431047
NSString *text = (NSString *)args[2];
10441048
NSString *url = (NSString *)args[3];
10451049
[self addLinkAt:start end:end text:text url:url];
@@ -1177,47 +1181,51 @@ - (void)emitOnLinkDetectedEvent:(NSString *)text
11771181
- (void)emitCurrentSelectionColorIfChanged {
11781182
NSRange selRange = textView.selectedRange;
11791183
UIColor *uniformColor = nil;
1180-
1184+
11811185
if (selRange.length == 0) {
11821186
id colorAttr = textView.typingAttributes[NSForegroundColorAttributeName];
11831187
uniformColor = colorAttr ? (UIColor *)colorAttr : [config primaryColor];
11841188
} else {
11851189
// Selection range: check for uniform color
11861190
__block UIColor *firstColor = nil;
11871191
__block BOOL hasMultiple = NO;
1188-
1189-
[textView.textStorage enumerateAttribute:NSForegroundColorAttributeName
1190-
inRange:selRange
1191-
options:0
1192-
usingBlock:^(id _Nullable value, NSRange range, BOOL *_Nonnull stop) {
1193-
UIColor *thisColor = value ? (UIColor *)value : [config primaryColor];
1194-
if (firstColor == nil) {
1195-
firstColor = thisColor;
1196-
} else if (![firstColor isEqual:thisColor]) {
1197-
hasMultiple = YES;
1198-
*stop = YES;
1199-
}
1200-
}];
1201-
1192+
1193+
[textView.textStorage
1194+
enumerateAttribute:NSForegroundColorAttributeName
1195+
inRange:selRange
1196+
options:0
1197+
usingBlock:^(id _Nullable value, NSRange range,
1198+
BOOL *_Nonnull stop) {
1199+
UIColor *thisColor =
1200+
value ? (UIColor *)value : [config primaryColor];
1201+
if (firstColor == nil) {
1202+
firstColor = thisColor;
1203+
} else if (![firstColor isEqual:thisColor]) {
1204+
hasMultiple = YES;
1205+
*stop = YES;
1206+
}
1207+
}];
1208+
12021209
if (!hasMultiple && firstColor != nil) {
12031210
uniformColor = firstColor;
12041211
}
12051212
}
1206-
1207-
NSString *hexColor = uniformColor ? [uniformColor hexString] : [config.primaryColor hexString];
1208-
1209-
if(![_recentlyEmittedColor isEqual: hexColor]) {
1213+
1214+
NSString *hexColor =
1215+
uniformColor ? [uniformColor hexString] : [config.primaryColor hexString];
1216+
1217+
if (![_recentlyEmittedColor isEqual:hexColor]) {
12101218
auto emitter = [self getEventEmitter];
1211-
if(emitter != nullptr) {
1212-
emitter->onColorChangeInSelection({
1213-
.color = [hexColor toCppString]
1214-
});
1219+
if (emitter != nullptr) {
1220+
emitter->onColorChangeInSelection({.color = [hexColor toCppString]});
12151221
}
12161222
_recentlyEmittedColor = hexColor;
12171223
}
12181224
}
12191225

1220-
- (void)emitOnMentionDetectedEvent:(NSString *)text indicator:(NSString *)indicator attributes:(NSString *)attributes {
1226+
- (void)emitOnMentionDetectedEvent:(NSString *)text
1227+
indicator:(NSString *)indicator
1228+
attributes:(NSString *)attributes {
12211229
auto emitter = [self getEventEmitter];
12221230
if (emitter != nullptr) {
12231231
emitter->onMentionDetected({.text = [text toCppString],
@@ -1276,9 +1284,9 @@ - (void)requestHTML:(NSInteger)requestId {
12761284

12771285
- (void)setColor:(NSString *)colorText {
12781286
ColorStyle *colorStyle = stylesDict[@(Colored)];
1279-
UIColor *color = [UIColor colorFromString: colorText];
1280-
1281-
[colorStyle applyStyle:textView.selectedRange color: color];
1287+
UIColor *color = [UIColor colorFromString:colorText];
1288+
1289+
[colorStyle applyStyle:textView.selectedRange color:color];
12821290
[self anyTextMayHaveBeenModified];
12831291
}
12841292

@@ -1659,13 +1667,15 @@ - (void)textViewDidBeginEditing:(UITextView *)textView {
16591667
if (_emitFocusBlur) {
16601668
emitter->onInputFocus({});
16611669
}
1662-
1663-
NSString *textAtSelection = [[[NSMutableString alloc] initWithString:textView.textStorage.string] substringWithRange: textView.selectedRange];
1664-
emitter->onChangeSelection({
1665-
.start = static_cast<int>(textView.selectedRange.location),
1666-
.end = static_cast<int>(textView.selectedRange.location + textView.selectedRange.length),
1667-
.text = [textAtSelection toCppString]
1668-
});
1670+
1671+
NSString *textAtSelection =
1672+
[[[NSMutableString alloc] initWithString:textView.textStorage.string]
1673+
substringWithRange:textView.selectedRange];
1674+
emitter->onChangeSelection(
1675+
{.start = static_cast<int>(textView.selectedRange.location),
1676+
.end = static_cast<int>(textView.selectedRange.location +
1677+
textView.selectedRange.length),
1678+
.text = [textAtSelection toCppString]});
16691679
[self emitCurrentSelectionColorIfChanged];
16701680
}
16711681
// manage selection changes since textViewDidChangeSelection sometimes doesn't

0 commit comments

Comments
 (0)