Skip to content

Commit fe30050

Browse files
authored
feat: unify initial text/html iOS emitting with Android (#270)
<!-- Thanks for submitting a pull request! We appreciate you spending the time to work on these changes. Please follow the template so that the reviewers can easily understand what the code changes affect --> # Summary After the latest PRs it also came to my mind that Android and iOS emit the initial events a bit differently. If we have some `defaultValue` set, iOS wouldn't emit text (and would emit html always, even if `defaultValue` was not set), while Android properly emitted both html and text only if the prop is set. This PR changes: - initial `recentlyEmittedHtml` value so that it doesn't emit with no `defaultValue` - sets `recentlyEmittedString` only if the `onChangeText` event properly wen through (event emitter was defined). This way text emits if it's different than the initial `""` ## Test Plan Run the example iOS app once with no `defaultValue` and the other time with `defaultValue`. Observe that in the first scenario no initial events are dispatched, while in the second they are emitted as soon as emitter is ready. ## Screenshots / Videos -- ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ | | Android | ✅ (was fine already) |
1 parent 89ca463 commit fe30050

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

ios/EnrichedTextInputView.mm

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ - (void)setDefaults {
7575
_recentlyActiveMentionRange = NSMakeRange(0, 0);
7676
recentlyChangedRange = NSMakeRange(0, 0);
7777
_recentlyEmittedString = @"";
78-
_recentlyEmittedHtml = @"";
78+
_recentlyEmittedHtml = @"<html>\n<p></p>\n</html>";
7979
_emitHtml = NO;
8080
blockEmitting = NO;
8181
_emitFocusBlur = YES;
@@ -1056,6 +1056,12 @@ - (void)anyTextMayHaveBeenModified {
10561056
[h3Style handleImproperHeadings];
10571057
}
10581058

1059+
// mentions removal management
1060+
MentionStyle *mentionStyleClass = (MentionStyle *)stylesDict[@([MentionStyle getStyleType])];
1061+
if(mentionStyleClass != nullptr) {
1062+
[mentionStyleClass handleExistingMentions];
1063+
}
1064+
10591065
// placholder management
10601066
if(!_placeholderLabel.hidden && textView.textStorage.string.length > 0) {
10611067
[self setPlaceholderLabelShown:NO];
@@ -1064,12 +1070,6 @@ - (void)anyTextMayHaveBeenModified {
10641070
}
10651071

10661072
if(![textView.textStorage.string isEqualToString:_recentlyEmittedString]) {
1067-
// mentions removal management
1068-
MentionStyle *mentionStyleClass = (MentionStyle *)stylesDict[@([MentionStyle getStyleType])];
1069-
if(mentionStyleClass != nullptr) {
1070-
[mentionStyleClass handleExistingMentions];
1071-
}
1072-
10731073
// modified words handling
10741074
NSArray *modifiedWords = [WordsUtils getAffectedWordsFromText:textView.textStorage.string modificationRange:recentlyChangedRange];
10751075
if(modifiedWords != nullptr) {
@@ -1091,13 +1091,13 @@ - (void)anyTextMayHaveBeenModified {
10911091
// emit onChangeText event
10921092
auto emitter = [self getEventEmitter];
10931093
if(emitter != nullptr) {
1094+
// set the recently emitted string only if the emitter is defined
1095+
_recentlyEmittedString = stringToBeEmitted;
1096+
10941097
emitter->onChangeText({
10951098
.value = [stringToBeEmitted toCppString]
10961099
});
10971100
}
1098-
1099-
// set the recently emitted string
1100-
_recentlyEmittedString = stringToBeEmitted;
11011101
}
11021102

11031103
// update height on each character change

0 commit comments

Comments
 (0)