diff --git a/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h b/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h index 6f6feba2f198fd..74720372ff6ed1 100644 --- a/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h +++ b/Libraries/Text/TextInput/RCTBackedTextInputViewProtocol.h @@ -25,9 +25,9 @@ NS_ASSUME_NONNULL_END NS_ASSUME_NONNULL_BEGIN -#if !TARGET_OS_OSX // TODO(macOS GH#774) +#if !TARGET_OS_OSX // [TODO(macOS GH#774) @protocol RCTBackedTextInputViewProtocol -#else // [TODO(macOS GH#774) +#else @protocol RCTBackedTextInputViewProtocol #endif // ]TODO(macOS GH#774) diff --git a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm index 9a623ca3a10b5d..30ca8ccbb93c9c 100644 --- a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +++ b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm @@ -116,6 +116,8 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & [self _setMultiline:newTextInputProps.traits.multiline]; } + +#if !TARGET_OS_OSX // [TODO(macOS GH#774) if (newTextInputProps.traits.autocapitalizationType != oldTextInputProps.traits.autocapitalizationType) { _backedTextInputView.autocapitalizationType = RCTUITextAutocapitalizationTypeFromAutocapitalizationType(newTextInputProps.traits.autocapitalizationType); @@ -125,6 +127,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & _backedTextInputView.autocorrectionType = RCTUITextAutocorrectionTypeFromOptionalBool(newTextInputProps.traits.autoCorrect); } +#endif // ]TODO(macOS GH#774) if (newTextInputProps.traits.contextMenuHidden != oldTextInputProps.traits.contextMenuHidden) { _backedTextInputView.contextMenuHidden = newTextInputProps.traits.contextMenuHidden; @@ -139,6 +142,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & _backedTextInputView.enablesReturnKeyAutomatically = newTextInputProps.traits.enablesReturnKeyAutomatically; } +#if !TARGET_OS_OSX // [TODO(macOS GH#774) if (newTextInputProps.traits.keyboardAppearance != oldTextInputProps.traits.keyboardAppearance) { _backedTextInputView.keyboardAppearance = RCTUIKeyboardAppearanceFromKeyboardAppearance(newTextInputProps.traits.keyboardAppearance); @@ -148,20 +152,24 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & _backedTextInputView.spellCheckingType = RCTUITextSpellCheckingTypeFromOptionalBool(newTextInputProps.traits.spellCheck); } +#endif // ]TODO(macOS GH#774) if (newTextInputProps.traits.caretHidden != oldTextInputProps.traits.caretHidden) { _backedTextInputView.caretHidden = newTextInputProps.traits.caretHidden; } +#if !TARGET_OS_OSX // [TODO(macOS GH#774) if (newTextInputProps.traits.clearButtonMode != oldTextInputProps.traits.clearButtonMode) { _backedTextInputView.clearButtonMode = RCTUITextFieldViewModeFromTextInputAccessoryVisibilityMode(newTextInputProps.traits.clearButtonMode); } +#endif // ]TODO(macOS GH#774) if (newTextInputProps.traits.scrollEnabled != oldTextInputProps.traits.scrollEnabled) { _backedTextInputView.scrollEnabled = newTextInputProps.traits.scrollEnabled; } +#if !TARGET_OS_OSX // [TODO(macOS GH#774) if (newTextInputProps.traits.secureTextEntry != oldTextInputProps.traits.secureTextEntry) { _backedTextInputView.secureTextEntry = newTextInputProps.traits.secureTextEntry; } @@ -184,6 +192,7 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & RCTUITextInputPasswordRulesFromString(newTextInputProps.traits.passwordRules); } } +#endif // ]TODO(macOS GH#774) // Traits `blurOnSubmit`, `clearTextOnFocus`, and `selectTextOnFocus` were omitted intentially here // because they are being checked on-demand. @@ -202,9 +211,11 @@ - (void)updateProps:(Props::Shared const &)props oldProps:(Props::Shared const & RCTNSTextAttributesFromTextAttributes(newTextInputProps.getEffectiveTextAttributes(RCTFontSizeMultiplier())); } +#if !TARGET_OS_OSX // [TODO(macOS GH#774) if (newTextInputProps.selectionColor != oldTextInputProps.selectionColor) { _backedTextInputView.tintColor = RCTUIColorFromSharedColor(newTextInputProps.selectionColor); } +#endif // ]TODO(macOS GH#774) if (newTextInputProps.inputAccessoryViewID != oldTextInputProps.inputAccessoryViewID) { _backedTextInputView.inputAccessoryViewID = RCTNSStringFromString(newTextInputProps.inputAccessoryViewID); @@ -449,6 +460,7 @@ - (void)setTextAndSelection:(NSInteger)eventCount [self _updateState]; } +#if !TARGET_OS_OSX // [TODO(macOS GH#774) UITextPosition *startPosition = [_backedTextInputView positionFromPosition:_backedTextInputView.beginningOfDocument offset:start]; UITextPosition *endPosition = [_backedTextInputView positionFromPosition:_backedTextInputView.beginningOfDocument @@ -458,6 +470,7 @@ - (void)setTextAndSelection:(NSInteger)eventCount UITextRange *range = [_backedTextInputView textRangeFromPosition:startPosition toPosition:endPosition]; [_backedTextInputView setSelectedTextRange:range notifyDelegate:NO]; } +#endif // ]TODO(macOS GH#774) _comingFromJS = NO; } @@ -468,11 +481,14 @@ - (void)setDefaultInputAccessoryView // InputAccessoryView component sets the inputAccessoryView when inputAccessoryViewID exists if (_backedTextInputView.inputAccessoryViewID) { if (_backedTextInputView.isFirstResponder) { +#if !TARGET_OS_OSX // [TODO(macOS GH#774) [_backedTextInputView reloadInputViews]; +#endif } return; } +#if !TARGET_OS_OSX // [TODO(macOS GH#774) UIKeyboardType keyboardType = _backedTextInputView.keyboardType; // These keyboard types (all are number pads) don't have a "Done" button by default, @@ -500,16 +516,21 @@ - (void)setDefaultInputAccessoryView } else { _backedTextInputView.inputAccessoryView = nil; } +#endif // ]TODO(macOS GH#774) if (_backedTextInputView.isFirstResponder) { +#if !TARGET_OS_OSX // [TODO(macOS GH#774) [_backedTextInputView reloadInputViews]; +#endif // ]TODO(macOS GH#774) } } - (void)handleInputAccessoryDoneButton { if ([self textInputShouldReturn]) { +#if !TARGET_OS_OSX // [TODO(macOS GH#774) [_backedTextInputView endEditing:YES]; +#endif // ]TODO(macOS GH#774) } } @@ -556,12 +577,17 @@ - (void)_updateState - (AttributedString::Range)_selectionRange { +#if !TARGET_OS_OSX // [TODO(macOS GH#774) UITextRange *selectedTextRange = _backedTextInputView.selectedTextRange; NSInteger start = [_backedTextInputView offsetFromPosition:_backedTextInputView.beginningOfDocument toPosition:selectedTextRange.start]; NSInteger end = [_backedTextInputView offsetFromPosition:_backedTextInputView.beginningOfDocument toPosition:selectedTextRange.end]; return AttributedString::Range{(int)start, (int)(end - start)}; +#else + // [Fabric] Placeholder till we implement selection in Fabric + return AttributedString::Range({0, 1}); +#endif // ]TODO(macOS GH#774) } - (void)_restoreTextSelection @@ -570,11 +596,13 @@ - (void)_restoreTextSelection if (!selection.has_value()) { return; } +#if !TARGET_OS_OSX // [TODO(macOS GH#774) auto start = [_backedTextInputView positionFromPosition:_backedTextInputView.beginningOfDocument offset:selection->start]; auto end = [_backedTextInputView positionFromPosition:_backedTextInputView.beginningOfDocument offset:selection->end]; auto range = [_backedTextInputView textRangeFromPosition:start toPosition:end]; [_backedTextInputView setSelectedTextRange:range notifyDelegate:YES]; +#endif // ]TODO(macOS GH#774) } - (void)_setAttributedString:(NSAttributedString *)attributedString @@ -582,6 +610,7 @@ - (void)_setAttributedString:(NSAttributedString *)attributedString if ([self _textOf:attributedString equals:_backedTextInputView.attributedText]) { return; } +#if !TARGET_OS_OSX // [TODO(macOS GH#774) UITextRange *selectedRange = _backedTextInputView.selectedTextRange; NSInteger oldTextLength = _backedTextInputView.attributedText.string.length; _backedTextInputView.attributedText = attributedString; @@ -598,6 +627,7 @@ - (void)_setAttributedString:(NSAttributedString *)attributedString } [self _restoreTextSelection]; _lastStringStateWasUpdatedWith = attributedString; +#endif // ]TODO(macOS GH#774) } - (void)_setMultiline:(BOOL)multiline @@ -631,6 +661,7 @@ - (BOOL)_textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldTe } }]; +#if !TARGET_OS_OSX // [TODO(macOS GH#774) BOOL shouldFallbackToBareTextComparison = [_backedTextInputView.textInputMode.primaryLanguage isEqualToString:@"dictation"] || _backedTextInputView.markedTextRange || _backedTextInputView.isSecureTextEntry || fontHasBeenUpdatedBySystem; @@ -638,8 +669,11 @@ - (BOOL)_textOf:(NSAttributedString *)newText equals:(NSAttributedString *)oldTe if (shouldFallbackToBareTextComparison) { return ([newText.string isEqualToString:oldText.string]); } else { +#endif // ]TODO(macOS GH#774) return ([newText isEqualToAttributedString:oldText]); +#if !TARGET_OS_OSX // [TODO(macOS GH#774) } +#endif // ]TODO(macOS GH#774) } @end diff --git a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.h b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.h index 2d62c452a72476..0faef32b659f73 100644 --- a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.h +++ b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.h @@ -18,6 +18,7 @@ void RCTCopyBackedTextInput( RCTUIView *fromTextInput, RCTUIView *toTextInput); // TODO(macOS GH#774) +#if !TARGET_OS_OSX // TODO(macOS GH#774) UITextAutocorrectionType RCTUITextAutocorrectionTypeFromOptionalBool(std::optional autoCorrect); UITextAutocapitalizationType RCTUITextAutocapitalizationTypeFromAutocapitalizationType( @@ -40,5 +41,6 @@ UITextContentType RCTUITextContentTypeFromString(std::string const &contentType) API_AVAILABLE(ios(12.0)) UITextInputPasswordRules *RCTUITextInputPasswordRulesFromString(std::string const &passwordRules); +#endif // ]TODO(macOS GH#774) NS_ASSUME_NONNULL_END diff --git a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm index b91311e271b2da..51fadace188af2 100644 --- a/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm +++ b/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm @@ -26,20 +26,29 @@ void RCTCopyBackedTextInput( toTextInput.placeholder = fromTextInput.placeholder; toTextInput.placeholderColor = fromTextInput.placeholderColor; toTextInput.textContainerInset = fromTextInput.textContainerInset; +#if !TARGET_OS_OSX // [TODO(macOS GH#774) toTextInput.inputAccessoryView = fromTextInput.inputAccessoryView; +#endif // ]TODO(macOS GH#774) toTextInput.textInputDelegate = fromTextInput.textInputDelegate; toTextInput.placeholderColor = fromTextInput.placeholderColor; toTextInput.defaultTextAttributes = fromTextInput.defaultTextAttributes; +#if !TARGET_OS_OSX // [TODO(macOS GH#774) toTextInput.autocapitalizationType = fromTextInput.autocapitalizationType; toTextInput.autocorrectionType = fromTextInput.autocorrectionType; +#endif // ]TODO(macOS GH#774) toTextInput.contextMenuHidden = fromTextInput.contextMenuHidden; toTextInput.editable = fromTextInput.editable; toTextInput.enablesReturnKeyAutomatically = fromTextInput.enablesReturnKeyAutomatically; +#if !TARGET_OS_OSX // [TODO(macOS GH#774) toTextInput.keyboardAppearance = fromTextInput.keyboardAppearance; toTextInput.spellCheckingType = fromTextInput.spellCheckingType; +#endif // ]TODO(macOS GH#774) toTextInput.caretHidden = fromTextInput.caretHidden; +#if !TARGET_OS_OSX // [TODO(macOS GH#774) toTextInput.clearButtonMode = fromTextInput.clearButtonMode; +#endif // ]TODO(macOS GH#774) toTextInput.scrollEnabled = fromTextInput.scrollEnabled; +#if !TARGET_OS_OSX // [TODO(macOS GH#774) toTextInput.secureTextEntry = fromTextInput.secureTextEntry; toTextInput.keyboardType = fromTextInput.keyboardType; toTextInput.textContentType = fromTextInput.textContentType; @@ -49,8 +58,10 @@ void RCTCopyBackedTextInput( } [toTextInput setSelectedTextRange:fromTextInput.selectedTextRange notifyDelegate:NO]; +#endif // ]TODO(macOS GH#774) } +#if !TARGET_OS_OSX // [TODO(macOS GH#774) UITextAutocorrectionType RCTUITextAutocorrectionTypeFromOptionalBool(std::optional autoCorrect) { return autoCorrect.has_value() ? (*autoCorrect ? UITextAutocorrectionTypeYes : UITextAutocorrectionTypeNo) @@ -232,3 +243,4 @@ UITextContentType RCTUITextContentTypeFromString(std::string const &contentType) { return [UITextInputPasswordRules passwordRulesWithDescriptor:RCTNSStringFromStringNilIfEmpty(passwordRules)]; } +#endif // ]TODO(macOS GH#774)