1717#if !TARGET_OS_OSX // [macOS]
1818#import < React/RCTUITextField.h>
1919#else // [macOS
20- #include < React/RCTUISecureTextField.h>
2120#include < React/RCTUITextField.h>
21+ #include < React/RCTUISecureTextField.h>
2222#endif // macOS]
2323
2424#import < React/RCTUITextView.h>
2525#import < React/RCTUtils.h>
2626#if TARGET_OS_OSX // [macOS
27- #import < React/RCTViewKeyboardEvent.h>
2827#import < React/RCTWrappedTextView.h>
28+ #import < React/RCTViewKeyboardEvent.h>
2929#endif // macOS]
3030
3131#import " RCTConversions.h"
4343static NSString *kEscapeKeyCode = @" \x1B " ;
4444#endif // macOS]
4545
46+
4647using namespace facebook ::react;
4748
4849@interface RCTTextInputComponentView () <RCTBackedTextInputDelegate, RCTTextInputViewProtocol>
@@ -104,8 +105,7 @@ - (instancetype)initWithFrame:(CGRect)frame
104105#if !TARGET_OS_OSX // [macOS]
105106 _backedTextInputView = defaultProps->multiline ? [RCTUITextView new ] : [RCTUITextField new ];
106107#else // [macOS
107- _backedTextInputView =
108- defaultProps->multiline ? [[RCTWrappedTextView alloc ] initWithFrame: self .bounds] : [RCTUITextField new ];
108+ _backedTextInputView = defaultProps->multiline ? [[RCTWrappedTextView alloc ] initWithFrame: self .bounds] : [RCTUITextField new ];
109109#endif // macOS]
110110 _backedTextInputView.textInputDelegate = self;
111111 _ignoreNextTextInputCall = NO ;
@@ -221,6 +221,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
221221 [self _setMultiline: newTextInputProps.multiline];
222222 }
223223
224+
224225#if !TARGET_OS_OSX // [macOS]
225226 if (newTextInputProps.traits .autocapitalizationType != oldTextInputProps.traits .autocapitalizationType ) {
226227 _backedTextInputView.autocapitalizationType =
@@ -234,9 +235,9 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
234235 RCTUITextAutocorrectionTypeFromOptionalBool (newTextInputProps.traits .autoCorrect );
235236 }
236237#else // [macOS
237- if (newTextInputProps.traits .autoCorrect != oldTextInputProps.traits .autoCorrect &&
238- newTextInputProps. traits . autoCorrect . has_value ()) {
239- _backedTextInputView. automaticSpellingCorrectionEnabled = newTextInputProps.traits .autoCorrect .value ();
238+ if (newTextInputProps.traits .autoCorrect != oldTextInputProps.traits .autoCorrect && newTextInputProps. traits . autoCorrect . has_value ()) {
239+ _backedTextInputView. automaticSpellingCorrectionEnabled =
240+ newTextInputProps.traits .autoCorrect .value ();
240241 }
241242#endif // macOS]
242243
@@ -274,16 +275,16 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
274275 RCTUITextSpellCheckingTypeFromOptionalBool (newTextInputProps.traits .spellCheck );
275276 }
276277#else // [macOS
277- if (newTextInputProps.traits .spellCheck != oldTextInputProps.traits .spellCheck &&
278- newTextInputProps. traits . spellCheck . has_value ()) {
279- _backedTextInputView. continuousSpellCheckingEnabled = newTextInputProps.traits .spellCheck .value ();
278+ if (newTextInputProps.traits .spellCheck != oldTextInputProps.traits .spellCheck && newTextInputProps. traits . spellCheck . has_value ()) {
279+ _backedTextInputView. continuousSpellCheckingEnabled =
280+ newTextInputProps.traits .spellCheck .value ();
280281 }
281282#endif // macOS]
282283
283284#if TARGET_OS_OSX // [macOS
284- if (newTextInputProps.traits .grammarCheck != oldTextInputProps.traits .grammarCheck &&
285- newTextInputProps. traits . grammarCheck . has_value ()) {
286- _backedTextInputView. grammarCheckingEnabled = newTextInputProps.traits .grammarCheck .value ();
285+ if (newTextInputProps.traits .grammarCheck != oldTextInputProps.traits .grammarCheck && newTextInputProps. traits . grammarCheck . has_value ()) {
286+ _backedTextInputView. grammarCheckingEnabled =
287+ newTextInputProps.traits .grammarCheck .value ();
287288 }
288289#endif // macOS]
289290
@@ -379,7 +380,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
379380 }
380381
381382#if TARGET_OS_OSX // [macOS
382- if (newTextInputProps.traits .pastedTypes != oldTextInputProps.traits .pastedTypes ) {
383+ if (newTextInputProps.traits .pastedTypes != oldTextInputProps.traits .pastedTypes ) {
383384 NSArray <NSPasteboardType > *types = RCTPasteboardTypeArrayFromProps (newTextInputProps.traits .pastedTypes );
384385 [_backedTextInputView setReadablePasteBoardTypes: types];
385386 }
@@ -606,47 +607,45 @@ - (void)textInputDidChangeSelection
606607}
607608
608609#if TARGET_OS_OSX // [macOS
609- - (void )setEnableFocusRing : (BOOL )enableFocusRing
610- {
610+ - (void )setEnableFocusRing : (BOOL )enableFocusRing {
611611 [super setEnableFocusRing: enableFocusRing];
612612 if ([_backedTextInputView respondsToSelector: @selector (setEnableFocusRing: )]) {
613613 [_backedTextInputView setEnableFocusRing: enableFocusRing];
614614 }
615615}
616616
617- - (void )automaticSpellingCorrectionDidChange : (BOOL )enabled
618- {
617+ - (void )automaticSpellingCorrectionDidChange : (BOOL )enabled {
619618 if (_eventEmitter) {
620- std::static_pointer_cast<const TextInputEventEmitter>(_eventEmitter)
621- ->onAutoCorrectChange ({.autoCorrectEnabled = static_cast <bool >(enabled)});
619+ std::static_pointer_cast<TextInputEventEmitter const >(_eventEmitter)->onAutoCorrectChange ({.autoCorrectEnabled = static_cast <bool >(enabled)});
622620 }
623621}
624622
625623- (void )continuousSpellCheckingDidChange : (BOOL )enabled
626624{
627625 if (_eventEmitter) {
628- std::static_pointer_cast<const TextInputEventEmitter>(_eventEmitter)
629- ->onSpellCheckChange ({.spellCheckEnabled = static_cast <bool >(enabled)});
626+ std::static_pointer_cast<TextInputEventEmitter const >(_eventEmitter)->onSpellCheckChange ({.spellCheckEnabled = static_cast <bool >(enabled)});
630627 }
631628}
632629
633630- (void )grammarCheckingDidChange : (BOOL )enabled
634631{
635632 if (_eventEmitter) {
636- std::static_pointer_cast<const TextInputEventEmitter>(_eventEmitter)
637- ->onGrammarCheckChange ({.grammarCheckEnabled = static_cast <bool >(enabled)});
633+ std::static_pointer_cast<TextInputEventEmitter const >(_eventEmitter)->onGrammarCheckChange ({.grammarCheckEnabled = static_cast <bool >(enabled)});
638634 }
639635}
640636
641637- (void )submitOnKeyDownIfNeeded : (nonnull NSEvent *)event
642638{
643639 BOOL shouldSubmit = NO ;
644640 NSDictionary *keyEvent = [RCTViewKeyboardEvent bodyFromEvent: event];
645- const auto &props = *std::static_pointer_cast<const TextInputProps>(_props);
641+ auto const &props = *std::static_pointer_cast<TextInputProps const >(_props);
646642 if (props.traits .submitKeyEvents .empty ()) {
647- shouldSubmit = [keyEvent[@" key" ] isEqualToString: @" Enter" ] && ![keyEvent[@" altKey" ] boolValue ] &&
648- ![keyEvent[@" shiftKey" ] boolValue ] && ![keyEvent[@" ctrlKey" ] boolValue ] && ![keyEvent[@" metaKey" ] boolValue ] &&
649- ![keyEvent[@" functionKey" ] boolValue ]; // Default clearTextOnSubmit key
643+ shouldSubmit = [keyEvent[@" key" ] isEqualToString: @" Enter" ]
644+ && ![keyEvent[@" altKey" ] boolValue ]
645+ && ![keyEvent[@" shiftKey" ] boolValue ]
646+ && ![keyEvent[@" ctrlKey" ] boolValue ]
647+ && ![keyEvent[@" metaKey" ] boolValue ]
648+ && ![keyEvent[@" functionKey" ] boolValue ]; // Default clearTextOnSubmit key
650649 } else {
651650 NSString *keyValue = keyEvent[@" key" ];
652651 const char *keyCString = [keyValue UTF8String ];
@@ -659,17 +658,19 @@ - (void)submitOnKeyDownIfNeeded:(nonnull NSEvent *)event
659658 const bool functionKey = [keyEvent[@" functionKey" ] boolValue ];
660659
661660 shouldSubmit = std::any_of (
662- props.traits .submitKeyEvents .begin (), props.traits .submitKeyEvents .end (), [&](const auto &submitKeyEvent) {
663- return submitKeyEvent.key == key && submitKeyEvent.altKey == altKey &&
664- submitKeyEvent.shiftKey == shiftKey && submitKeyEvent.ctrlKey == ctrlKey &&
665- submitKeyEvent.metaKey == metaKey && submitKeyEvent.functionKey == functionKey;
666- });
661+ props.traits .submitKeyEvents .begin (),
662+ props.traits .submitKeyEvents .end (),
663+ [&](auto const &submitKeyEvent) {
664+ return submitKeyEvent.key == key && submitKeyEvent.altKey == altKey &&
665+ submitKeyEvent.shiftKey == shiftKey && submitKeyEvent.ctrlKey == ctrlKey &&
666+ submitKeyEvent.metaKey == metaKey && submitKeyEvent.functionKey == functionKey;
667+ });
667668 }
668669 }
669-
670+
670671 if (shouldSubmit) {
671672 if (_eventEmitter) {
672- const auto &textInputEventEmitter = *std::static_pointer_cast<const TextInputEventEmitter>(_eventEmitter);
673+ auto const &textInputEventEmitter = *std::static_pointer_cast<TextInputEventEmitter const >(_eventEmitter);
673674 textInputEventEmitter.onSubmitEditing ([self _textInputMetrics ]);
674675 }
675676
@@ -683,33 +684,30 @@ - (void)submitOnKeyDownIfNeeded:(nonnull NSEvent *)event
683684- (void )textInputDidCancel
684685{
685686 if (_eventEmitter) {
686- const auto &textInputEventEmitter = *std::static_pointer_cast<const TextInputEventEmitter>(_eventEmitter);
687+ auto const &textInputEventEmitter = *std::static_pointer_cast<TextInputEventEmitter const >(_eventEmitter);
687688 textInputEventEmitter.onKeyPress ({
688- .text = RCTStringFromNSString (kEscapeKeyCode ),
689- .eventCount = static_cast <int >(_mostRecentEventCount),
689+ .text = RCTStringFromNSString (kEscapeKeyCode ),
690+ .eventCount = static_cast <int >(_mostRecentEventCount),
690691 });
691692 }
692-
693+
693694 [self textInputDidEndEditing ];
694695}
695696
696- - (NSDragOperation )textInputDraggingEntered : (nonnull id <NSDraggingInfo >)draggingInfo
697- {
697+ - (NSDragOperation )textInputDraggingEntered : (nonnull id <NSDraggingInfo >)draggingInfo {
698698 if ([draggingInfo.draggingPasteboard availableTypeFromArray: self .registeredDraggedTypes]) {
699699 return [self draggingEntered: draggingInfo];
700700 }
701701 return NSDragOperationNone;
702702}
703703
704- - (void )textInputDraggingExited : (nonnull id <NSDraggingInfo >)draggingInfo
705- {
704+ - (void )textInputDraggingExited : (nonnull id <NSDraggingInfo >)draggingInfo {
706705 if ([draggingInfo.draggingPasteboard availableTypeFromArray: self .registeredDraggedTypes]) {
707706 [self draggingExited: draggingInfo];
708707 }
709708}
710709
711- - (BOOL )textInputShouldHandleDragOperation : (nonnull id <NSDraggingInfo >)draggingInfo
712- {
710+ - (BOOL )textInputShouldHandleDragOperation : (nonnull id <NSDraggingInfo >)draggingInfo {
713711 if ([draggingInfo.draggingPasteboard availableTypeFromArray: self .registeredDraggedTypes]) {
714712 [self performDragOperation: draggingInfo];
715713 return NO ;
@@ -718,33 +716,28 @@ - (BOOL)textInputShouldHandleDragOperation:(nonnull id<NSDraggingInfo>)draggingI
718716 return YES ;
719717}
720718
721- - (BOOL )textInputShouldHandleDeleteBackward : (nonnull id <RCTBackedTextInputViewProtocol>)sender
722- {
719+ - (BOOL )textInputShouldHandleDeleteBackward : (nonnull id <RCTBackedTextInputViewProtocol>)sender {
723720 return YES ;
724721}
725722
726- - (BOOL )textInputShouldHandleDeleteForward : (nonnull id <RCTBackedTextInputViewProtocol>)sender
727- {
723+ - (BOOL )textInputShouldHandleDeleteForward : (nonnull id <RCTBackedTextInputViewProtocol>)sender {
728724 return YES ;
729725}
730726
731- - (BOOL )textInputShouldHandleKeyEvent : (nonnull NSEvent *)event
732- {
727+ - (BOOL )textInputShouldHandleKeyEvent : (nonnull NSEvent *)event {
733728 return ![self handleKeyboardEvent: event];
734729}
735730
736- - (BOOL )textInputShouldHandlePaste : (nonnull id <RCTBackedTextInputViewProtocol>)sender
737- {
731+ - (BOOL )textInputShouldHandlePaste : (nonnull id <RCTBackedTextInputViewProtocol>)sender {
738732 NSPasteboard *pasteboard = [NSPasteboard generalPasteboard ];
739- NSPasteboardType fileType =
740- [pasteboard availableTypeFromArray: @[ NSFilenamesPboardType , NSPasteboardTypePNG , NSPasteboardTypeTIFF ]];
741- NSArray <NSPasteboardType > *pastedTypes = ((RCTUITextView *)_backedTextInputView).readablePasteboardTypes ;
742-
733+ NSPasteboardType fileType = [pasteboard availableTypeFromArray: @[NSFilenamesPboardType , NSPasteboardTypePNG , NSPasteboardTypeTIFF ]];
734+ NSArray <NSPasteboardType >* pastedTypes = ((RCTUITextView*) _backedTextInputView).readablePasteboardTypes ;
735+
743736 // If there's a fileType that is of interest, notify JS. Also blocks notifying JS if it's a text paste
744737 if (_eventEmitter && fileType != nil && [pastedTypes containsObject: fileType]) {
745- const auto &textInputEventEmitter = *std::static_pointer_cast<const TextInputEventEmitter>(_eventEmitter);
746- DataTransfer dataTransfer = [self dataTransferForPasteboard: pasteboard];
747- textInputEventEmitter.onPaste ({.dataTransfer = std::move (dataTransfer)});
738+ auto const &textInputEventEmitter = *std::static_pointer_cast<TextInputEventEmitter const >(_eventEmitter);
739+ DataTransfer dataTransfer = [self dataTransferForPasteboard: pasteboard];
740+ textInputEventEmitter.onPaste ({.dataTransfer = std::move (dataTransfer)});
748741 }
749742
750743 // Only allow pasting text.
@@ -761,8 +754,7 @@ - (void)scrollViewDidScroll:(RCTUIScrollView *)scrollView // [macOS]
761754#if !TARGET_OS_OSX // [macOS]
762755 static_cast <const TextInputEventEmitter &>(*_eventEmitter).onScroll ([self _textInputMetrics ]);
763756#else // [macOS
764- static_cast <const TextInputEventEmitter &>(*_eventEmitter)
765- .onScroll ([self _textInputMetricsWithScrollView: scrollView]);
757+ static_cast <const TextInputEventEmitter &>(*_eventEmitter).onScroll ([self _textInputMetricsWithScrollView: scrollView]);
766758#endif // macOS]
767759 }
768760}
@@ -839,8 +831,7 @@ - (void)setTextAndSelection:(NSInteger)eventCount
839831#else // [macOS
840832 NSInteger startPosition = MIN (start, end);
841833 NSInteger endPosition = MAX (start, end);
842- [_backedTextInputView setSelectedTextRange: NSMakeRange (startPosition, endPosition - startPosition)
843- notifyDelegate: YES ];
834+ [_backedTextInputView setSelectedTextRange: NSMakeRange (startPosition, endPosition - startPosition) notifyDelegate: YES ];
844835#endif // macOS]
845836 _comingFromJS = NO ;
846837}
@@ -991,6 +982,7 @@ - (void)handleInputAccessoryDoneButton
991982}
992983#endif // macOS]
993984
985+
994986- (void )_updateState
995987{
996988 if (!_state) {
@@ -1079,7 +1071,8 @@ - (void)_setAttributedString:(NSAttributedString *)attributedString
10791071 NSInteger start = selectedRange.location ;
10801072 NSInteger offsetFromEnd = oldTextLength - start;
10811073 NSInteger newOffset = _backedTextInputView.attributedText .length - offsetFromEnd;
1082- [_backedTextInputView setSelectedTextRange: NSMakeRange (newOffset, 0 ) notifyDelegate: YES ];
1074+ [_backedTextInputView setSelectedTextRange: NSMakeRange (newOffset, 0 )
1075+ notifyDelegate: YES ];
10831076 }
10841077#endif // macOS]
10851078}
@@ -1122,11 +1115,9 @@ - (void)_setMultiline:(BOOL)multiline
11221115{
11231116 [_backedTextInputView removeFromSuperview ];
11241117#if !TARGET_OS_OSX // [macOS]
1125- RCTUIView<RCTBackedTextInputViewProtocol> *backedTextInputView =
1126- multiline ? [RCTUITextView new ] : [RCTUITextField new ];
1118+ RCTUIView<RCTBackedTextInputViewProtocol> *backedTextInputView = multiline ? [RCTUITextView new ] : [RCTUITextField new ];
11271119#else // [macOS
1128- RCTPlatformView<RCTBackedTextInputViewProtocol> *backedTextInputView =
1129- multiline ? [RCTWrappedTextView new ] : [RCTUITextField new ];
1120+ RCTPlatformView<RCTBackedTextInputViewProtocol> *backedTextInputView = multiline ? [RCTWrappedTextView new ] : [RCTUITextField new ];
11301121#endif // macOS]
11311122 backedTextInputView.frame = _backedTextInputView.frame ;
11321123 RCTCopyBackedTextInput (_backedTextInputView, backedTextInputView);
@@ -1157,11 +1148,10 @@ - (void)_setShowSoftInputOnFocus:(BOOL)showSoftInputOnFocus
11571148- (void )_setSecureTextEntry : (BOOL )secureTextEntry
11581149{
11591150 [_backedTextInputView removeFromSuperview ];
1160- RCTPlatformView<RCTBackedTextInputViewProtocol> *backedTextInputView =
1161- secureTextEntry ? [RCTUISecureTextField new ] : [RCTUITextField new ];
1151+ RCTPlatformView<RCTBackedTextInputViewProtocol> *backedTextInputView = secureTextEntry ? [RCTUISecureTextField new ] : [RCTUITextField new ];
11621152 backedTextInputView.frame = _backedTextInputView.frame ;
11631153 RCTCopyBackedTextInput (_backedTextInputView, backedTextInputView);
1164-
1154+
11651155 // Copy the text field specific properties if we came from a single line input before the switch
11661156 if ([_backedTextInputView isKindOfClass: [RCTUITextField class ]]) {
11671157 RCTUITextField *previousTextField = (RCTUITextField *)_backedTextInputView;
@@ -1199,16 +1189,17 @@ - (BOOL)_textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldTe
11991189
12001190 BOOL shouldFallbackToBareTextComparison =
12011191#if !TARGET_OS_OSX // [macOS]
1202- [_backedTextInputView.textInputMode.primaryLanguage isEqualToString: @" dictation" ] ||
1203- [_backedTextInputView.textInputMode.primaryLanguage isEqualToString: @" ko-KR" ] ||
1204- _backedTextInputView.markedTextRange || _backedTextInputView.isSecureTextEntry ||
1192+ [_backedTextInputView.textInputMode.primaryLanguage isEqualToString: @" dictation" ] ||
1193+ [_backedTextInputView.textInputMode.primaryLanguage isEqualToString: @" ko-KR" ] ||
1194+ _backedTextInputView.markedTextRange ||
1195+ _backedTextInputView.isSecureTextEntry ||
12051196#else // [macOS
1206- // There are multiple Korean input sources (2-Set, 3-Set, etc). Check substring instead instead
1207- [[[_backedTextInputView inputContext ] selectedKeyboardInputSource ]
1208- containsString: @" com.apple.inputmethod.Korean " ] ||
1209- [_backedTextInputView hasMarkedText ] || [_backedTextInputView isKindOfClass: [NSSecureTextField class ]] ||
1197+ // There are multiple Korean input sources (2-Set, 3-Set, etc). Check substring instead instead
1198+ [[[_backedTextInputView inputContext ] selectedKeyboardInputSource ] containsString: @" com.apple.inputmethod.Korean " ] ||
1199+ [_backedTextInputView hasMarkedText ] ||
1200+ [_backedTextInputView isKindOfClass: [NSSecureTextField class ]] ||
12101201#endif // macOS]
1211- fontHasBeenUpdatedBySystem;
1202+ fontHasBeenUpdatedBySystem;
12121203
12131204 if (shouldFallbackToBareTextComparison) {
12141205 return [newText.string isEqualToString: oldText.string];
0 commit comments