Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions ios/ReactNativeRichTextEditorView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ @implementation ReactNativeRichTextEditorView {
BOOL _emitHtml;
UILabel *_placeholderLabel;
UIColor *_placeholderColor;
BOOL _emitFocusBlur;
}

// MARK: - Component utils
Expand Down Expand Up @@ -76,6 +77,7 @@ - (void)setDefaults {
_recentlyEmittedString = @"";
_recentlyEmittedHtml = @"";
_emitHtml = NO;
_emitFocusBlur = YES;

defaultTypingAttributes = [[NSMutableDictionary<NSAttributedStringKey, id> alloc] init];

Expand Down Expand Up @@ -288,6 +290,28 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
}
}

// autoCapitalize
if(newViewProps.autoCapitalize != oldViewProps.autoCapitalize) {
NSString *str = [NSString fromCppString:newViewProps.autoCapitalize];
if([str isEqualToString: @"none"]) {
textView.autocapitalizationType = UITextAutocapitalizationTypeNone;
} else if([str isEqualToString: @"sentences"]) {
textView.autocapitalizationType = UITextAutocapitalizationTypeSentences;
} else if([str isEqualToString: @"words"]) {
textView.autocapitalizationType = UITextAutocapitalizationTypeWords;
} else if([str isEqualToString: @"characters"]) {
textView.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
}

// textView needs to be refocused on autocapitalization type change and we don't want to emit these events
if([textView isFirstResponder]) {
_emitFocusBlur = NO;
[textView reactBlur];
[textView reactFocus];
_emitFocusBlur = YES;
}
}

// isOnChangeHtmlSet
_emitHtml = newViewProps.isOnChangeHtmlSet;

Expand Down Expand Up @@ -805,8 +829,10 @@ - (void)anyTextMayHaveBeenModified {
- (void)textViewDidBeginEditing:(UITextView *)textView {
auto emitter = [self getEventEmitter];
if(emitter != nullptr) {
//send onFocus event
emitter->onInputFocus({});
//send onFocus event if allowed
if(_emitFocusBlur) {
emitter->onInputFocus({});
}

NSString *textAtSelection = [[[NSMutableString alloc] initWithString:textView.textStorage.string] substringWithRange: textView.selectedRange];
emitter->onChangeSelection({
Expand All @@ -821,7 +847,7 @@ - (void)textViewDidBeginEditing:(UITextView *)textView {

- (void)textViewDidEndEditing:(UITextView *)textView {
auto emitter = [self getEventEmitter];
if(emitter != nullptr) {
if(emitter != nullptr && _emitFocusBlur) {
//send onBlur event
emitter->onInputBlur({});
}
Expand Down
Loading