@@ -37,6 +37,7 @@ @implementation ReactNativeRichTextEditorView {
3737 BOOL _emitHtml;
3838 UILabel *_placeholderLabel;
3939 UIColor *_placeholderColor;
40+ BOOL _emitFocusBlur;
4041}
4142
4243// MARK: - Component utils
@@ -76,6 +77,7 @@ - (void)setDefaults {
7677 _recentlyEmittedString = @" " ;
7778 _recentlyEmittedHtml = @" " ;
7879 _emitHtml = NO ;
80+ _emitFocusBlur = YES ;
7981
8082 defaultTypingAttributes = [[NSMutableDictionary <NSAttributedStringKey , id > alloc] init ];
8183
@@ -288,6 +290,29 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const &
288290 }
289291 }
290292
293+ // autoCapitalize
294+ if (newViewProps.autoCapitalize != oldViewProps.autoCapitalize ) {
295+ NSString *str = [NSString fromCppString: newViewProps.autoCapitalize];
296+ if ([str isEqualToString: @" none" ]) {
297+ textView.autocapitalizationType = UITextAutocapitalizationTypeNone;
298+ } else if ([str isEqualToString: @" sentences" ]) {
299+ textView.autocapitalizationType = UITextAutocapitalizationTypeSentences;
300+ } else if ([str isEqualToString: @" words" ]) {
301+ textView.autocapitalizationType = UITextAutocapitalizationTypeWords;
302+ } else if ([str isEqualToString: @" characters" ]) {
303+ textView.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
304+ } else {
305+ // default value
306+ textView.autocapitalizationType = UITextAutocapitalizationTypeSentences;
307+ }
308+
309+ // textView needs to be refocused on autocapitalization type change and we don't want to emit these events
310+ _emitFocusBlur = NO ;
311+ [textView reactBlur ];
312+ [textView reactFocus ];
313+ _emitFocusBlur = YES ;
314+ }
315+
291316 // isOnChangeHtmlSet
292317 _emitHtml = newViewProps.isOnChangeHtmlSet ;
293318
@@ -805,8 +830,10 @@ - (void)anyTextMayHaveBeenModified {
805830- (void )textViewDidBeginEditing : (UITextView *)textView {
806831 auto emitter = [self getEventEmitter ];
807832 if (emitter != nullptr ) {
808- // send onFocus event
809- emitter->onInputFocus ({});
833+ // send onFocus event if allowed
834+ if (_emitFocusBlur) {
835+ emitter->onInputFocus ({});
836+ }
810837
811838 NSString *textAtSelection = [[[NSMutableString alloc ] initWithString: textView.textStorage.string] substringWithRange: textView.selectedRange];
812839 emitter->onChangeSelection ({
@@ -821,7 +848,7 @@ - (void)textViewDidBeginEditing:(UITextView *)textView {
821848
822849- (void )textViewDidEndEditing : (UITextView *)textView {
823850 auto emitter = [self getEventEmitter ];
824- if (emitter != nullptr ) {
851+ if (emitter != nullptr && _emitFocusBlur ) {
825852 // send onBlur event
826853 emitter->onInputBlur ({});
827854 }
0 commit comments