diff --git a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm index af4ab21632214e..52dad4e3887321 100644 --- a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm @@ -30,7 +30,11 @@ @interface RCTTextInputComponentView () *_backedTextInputView; // [macOS] +#if !TARGET_OS_OSX // [macOS] + RCTUIView *_backedTextInputView; +#else // [macOS + RCTUITextView *_backedTextInputView; +#endif // macOS] NSUInteger _mostRecentEventCount; NSAttributedString *_lastStringStateWasUpdatedWith; @@ -67,7 +71,11 @@ - (instancetype)initWithFrame:(CGRect)frame _props = defaultProps; auto &props = *defaultProps; +#if !TARGET_OS_OSX // [macOS] _backedTextInputView = props.traits.multiline ? [RCTUITextView new] : [RCTUITextField new]; +#else // [macOS + _backedTextInputView = [RCTUITextView new]; +#endif // macOS] _backedTextInputView.textInputDelegate = self; _ignoreNextTextInputCall = NO; _comingFromJS = NO; @@ -480,25 +488,23 @@ - (void)setTextAndSelection:(NSInteger)eventCount - (void)setDefaultInputAccessoryView { +#if !TARGET_OS_OSX // [macOS] // InputAccessoryView component sets the inputAccessoryView when inputAccessoryViewID exists if (_backedTextInputView.inputAccessoryViewID) { if (_backedTextInputView.isFirstResponder) { -#if !TARGET_OS_OSX // [macOS] [_backedTextInputView reloadInputViews]; -#endif // [macOS] } return; } -#if !TARGET_OS_OSX // [macOS] UIKeyboardType keyboardType = _backedTextInputView.keyboardType; // These keyboard types (all are number pads) don't have a "Done" button by default, // so we create an `inputAccessoryView` with this button for them. BOOL shouldHaveInputAccesoryView = - (keyboardType == UIKeyboardTypeNumberPad || keyboardType == UIKeyboardTypePhonePad || - keyboardType == UIKeyboardTypeDecimalPad || keyboardType == UIKeyboardTypeASCIICapableNumberPad) && - _backedTextInputView.returnKeyType == UIReturnKeyDone; + (keyboardType == UIKeyboardTypeNumberPad || keyboardType == UIKeyboardTypePhonePad || + keyboardType == UIKeyboardTypeDecimalPad || keyboardType == UIKeyboardTypeASCIICapableNumberPad) && + _backedTextInputView.returnKeyType == UIReturnKeyDone; if ((_backedTextInputView.inputAccessoryView != nil) == shouldHaveInputAccesoryView) { return; @@ -508,32 +514,30 @@ - (void)setDefaultInputAccessoryView UIToolbar *toolbarView = [UIToolbar new]; [toolbarView sizeToFit]; UIBarButtonItem *flexibleSpace = - [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; + [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil]; UIBarButtonItem *doneButton = - [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone - target:self - action:@selector(handleInputAccessoryDoneButton)]; + [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone + target:self + action:@selector(handleInputAccessoryDoneButton)]; toolbarView.items = @[ flexibleSpace, doneButton ]; _backedTextInputView.inputAccessoryView = toolbarView; } else { _backedTextInputView.inputAccessoryView = nil; } -#endif // [macOS] - + if (_backedTextInputView.isFirstResponder) { -#if !TARGET_OS_OSX // [macOS] [_backedTextInputView reloadInputViews]; -#endif // [macOS] } +#endif // [macOS] } - (void)handleInputAccessoryDoneButton { - if ([self textInputShouldReturn]) { #if !TARGET_OS_OSX // [macOS] + if ([self textInputShouldReturn]) { [_backedTextInputView endEditing:YES]; -#endif // [macOS] } +#endif // [macOS] } #pragma mark - Other @@ -635,7 +639,11 @@ - (void)_setAttributedString:(NSAttributedString *)attributedString - (void)_setMultiline:(BOOL)multiline { [_backedTextInputView removeFromSuperview]; - RCTUIView *backedTextInputView = multiline ? [RCTUITextView new] : [RCTUITextField new]; // [macOS] +#if !TARGET_OS_OSX // [macOS] + RCTUIView *backedTextInputView = multiline ? [RCTUITextView new] : [RCTUITextField new]; +#else // [macOS + RCTUITextView *backedTextInputView = [RCTUITextView new]; +#endif // macOS] backedTextInputView.frame = _backedTextInputView.frame; RCTCopyBackedTextInput(_backedTextInputView, backedTextInputView); _backedTextInputView = backedTextInputView; @@ -665,17 +673,19 @@ - (BOOL)_textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldTe }]; BOOL shouldFallbackToBareTextComparison = - [_backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"dictation"] || #if !TARGET_OS_OSX // [macOS] - [_backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"ko-KR"] || - _backedTextInputView.markedTextRange || _backedTextInputView.isSecureTextEntry || fontHasBeenUpdatedBySystem; + [_backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"dictation"] || + [_backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"ko-KR"] || + _backedTextInputView.markedTextRange || + _backedTextInputView.isSecureTextEntry || #else // [macOS - // There are multiple Korean input sources (2-Set, 3-Set, etc). Check substring instead instead - [[[self.backedTextInputView inputContext] selectedKeyboardInputSource] containsString:@"com.apple.inputmethod.Korean"] || - [self.backedTextInputView hasMarkedText] || - [self.backedTextInputView isKindOfClass:[NSSecureTextField class]] || - fontHasBeenUpdatedBySystem; + // There are multiple Korean input sources (2-Set, 3-Set, etc). Check substring instead instead + [[[_backedTextInputView inputContext] selectedKeyboardInputSource] containsString:@"com.apple.inputmethod.Korean"] || + [_backedTextInputView hasMarkedText] || + [_backedTextInputView isKindOfClass:[NSSecureTextField class]] || #endif // macOS] + fontHasBeenUpdatedBySystem; + if (shouldFallbackToBareTextComparison) { return ([newText.string isEqualToString:oldText.string]); } else { diff --git a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.h b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.h index da452fcf21086b..869ae06fef07a1 100644 --- a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.h +++ b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.h @@ -4,10 +4,11 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ +#import #import // [macOS] - -#import +#import // [macOS] +#import // [macOS] #import #import @@ -15,10 +16,16 @@ NS_ASSUME_NONNULL_BEGIN void RCTCopyBackedTextInput( - RCTUIView *fromTextInput, // [macOS] - RCTUIView *toTextInput); // [macOS] - -#if !TARGET_OS_OSX // [macOS] +#if !TARGET_OS_OSX // [macOS] + RCTUIView *fromTextInput, + RCTUIView *toTextInput +#else // [macOS + RCTUITextView *fromTextInput, + RCTUITextView *toTextInput +#endif // macOS] +); + +#if !TARGET_OS_OSX // [macOS] UITextAutocorrectionType RCTUITextAutocorrectionTypeFromOptionalBool(std::optional autoCorrect); UITextAutocapitalizationType RCTUITextAutocapitalizationTypeFromAutocapitalizationType( @@ -41,6 +48,6 @@ UITextContentType RCTUITextContentTypeFromString(std::string const &contentType) API_AVAILABLE(ios(12.0)) UITextInputPasswordRules *RCTUITextInputPasswordRulesFromString(std::string const &passwordRules); -#endif // [macOS] +#endif // [macOS] NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm index 2a3936934a5403..e7258109b5a556 100644 --- a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm +++ b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm @@ -19,8 +19,14 @@ } void RCTCopyBackedTextInput( +#if !TARGET_OS_OSX // [macOS] RCTUIView *fromTextInput, - RCTUIView *toTextInput) // [macOS] + RCTUIView *toTextInput +#else // [macOS + RCTUITextView *fromTextInput, + RCTUITextView *toTextInput +#endif // macOS] +) { toTextInput.attributedText = RCTSanitizeAttributedString(fromTextInput.attributedText); toTextInput.placeholder = fromTextInput.placeholder;