From fce872d2ef0e75e7eb83844b4e7cc91e0c74f7e6 Mon Sep 17 00:00:00 2001 From: Devan Buggay Date: Tue, 13 Jan 2026 16:09:38 -0800 Subject: [PATCH] Compile out various unsupported TextInput APIs for AppleTV (#55129) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/55129 TextInput uses a lot of UIKit APIs that are unavailable on AppleTV, compiling them out. Changelog: [internal] Reviewed By: shwanton Differential Revision: D90514227 fbshipit-source-id: 68f120b66a49a7541a6ec11e66ca76662af08bef --- .../Text/TextInput/Multiline/RCTUITextView.mm | 12 ++++++-- .../RCTBackedTextInputDelegateAdapter.mm | 28 +++++++++++++++++-- .../TextInput/Singleline/RCTUITextField.mm | 4 +-- .../react-native/React/Base/RCTConvert.mm | 6 ++++ .../TextInput/RCTTextInputComponentView.mm | 12 ++++++-- .../TextInput/RCTTextInputUtils.h | 2 ++ .../TextInput/RCTTextInputUtils.mm | 4 ++- 7 files changed, 59 insertions(+), 9 deletions(-) diff --git a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm index 6e9c3841cee..cbda3771e97 100644 --- a/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm +++ b/packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm @@ -21,6 +21,7 @@ NSArray *_initialValueLeadingBarButtonGroups; NSArray *_initialValueTrailingBarButtonGroups; NSArray *_acceptDragAndDropTypes; + BOOL _disableKeyboardShortcuts; } static UIFont *defaultPlaceholderFont(void) @@ -53,7 +54,9 @@ static UIColor *defaultPlaceholderColor(void) self.textColor = [UIColor blackColor]; // This line actually removes 5pt (default value) left and right padding in UITextView. self.textContainer.lineFragmentPadding = 0; +#if !TARGET_OS_TV self.scrollsToTop = NO; +#endif self.scrollEnabled = YES; _initialValueLeadingBarButtonGroups = nil; _initialValueTrailingBarButtonGroups = nil; @@ -149,6 +152,7 @@ static UIColor *defaultPlaceholderColor(void) - (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts { + _disableKeyboardShortcuts = disableKeyboardShortcuts; #if TARGET_OS_IOS // Initialize the initial values only once if (_initialValueLeadingBarButtonGroups == nil) { @@ -165,10 +169,14 @@ static UIColor *defaultPlaceholderColor(void) self.inputAssistantItem.leadingBarButtonGroups = _initialValueLeadingBarButtonGroups; self.inputAssistantItem.trailingBarButtonGroups = _initialValueTrailingBarButtonGroups; } - _disableKeyboardShortcuts = disableKeyboardShortcuts; #endif } +- (BOOL)disableKeyboardShortcuts +{ + return _disableKeyboardShortcuts; +} + #pragma mark - Overrides - (void)setFont:(UIFont *)font @@ -306,7 +314,7 @@ static UIColor *defaultPlaceholderColor(void) - (void)buildMenuWithBuilder:(id)builder { -#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 +#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 && !TARGET_OS_TV if (@available(iOS 17.0, *)) { if (_contextMenuHidden) { [builder removeMenuForIdentifier:UIMenuAutoFill]; diff --git a/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.mm b/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.mm index 82d9a79af73..8db8703fb66 100644 --- a/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.mm +++ b/packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.mm @@ -11,7 +11,13 @@ static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingContext; -@interface RCTBackedTextFieldDelegateAdapter () +@interface RCTBackedTextFieldDelegateAdapter () < + UITextFieldDelegate +#if !TARGET_OS_TV + , + UITextDropDelegate +#endif + > @end @implementation RCTBackedTextFieldDelegateAdapter { @@ -25,7 +31,9 @@ static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingCo if (self = [super init]) { _backedTextInputView = backedTextInputView; backedTextInputView.delegate = self; +#if !TARGET_OS_TV backedTextInputView.textDropDelegate = self; +#endif [_backedTextInputView addTarget:self action:@selector(textFieldDidChange) @@ -160,6 +168,8 @@ static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingCo [_backedTextInputView.textInputDelegate textInputDidChangeSelection]; } +#if !TARGET_OS_TV + #pragma mark - UITextDropDelegate - (UITextDropEditability)textDroppableView:(UIView *)textDroppableView @@ -196,11 +206,19 @@ static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingCo } } +#endif + @end #pragma mark - RCTBackedTextViewDelegateAdapter (for UITextView) -@interface RCTBackedTextViewDelegateAdapter () +@interface RCTBackedTextViewDelegateAdapter () < + UITextViewDelegate +#if !TARGET_OS_TV + , + UITextDropDelegate +#endif + > @end @implementation RCTBackedTextViewDelegateAdapter { @@ -216,7 +234,9 @@ static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingCo if (self = [super init]) { _backedTextInputView = backedTextInputView; backedTextInputView.delegate = self; +#if !TARGET_OS_TV backedTextInputView.textDropDelegate = self; +#endif } return self; @@ -342,6 +362,8 @@ static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingCo [_backedTextInputView.textInputDelegate textInputDidChangeSelection]; } +#if !TARGET_OS_TV + #pragma mark - UITextDropDelegate - (UITextDropEditability)textDroppableView:(UIView *)textDroppableView @@ -378,4 +400,6 @@ static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingCo } } +#endif + @end diff --git a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm index 377f41e4182..052c003476d 100644 --- a/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm +++ b/packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm @@ -136,6 +136,7 @@ - (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts { + _disableKeyboardShortcuts = disableKeyboardShortcuts; #if TARGET_OS_IOS // Initialize the initial values only once if (_initialValueLeadingBarButtonGroups == nil) { @@ -152,7 +153,6 @@ self.inputAssistantItem.leadingBarButtonGroups = _initialValueLeadingBarButtonGroups; self.inputAssistantItem.trailingBarButtonGroups = _initialValueTrailingBarButtonGroups; } - _disableKeyboardShortcuts = disableKeyboardShortcuts; #endif } @@ -186,7 +186,7 @@ - (void)buildMenuWithBuilder:(id)builder { #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 - if (@available(iOS 17.0, *)) { + if (@available(iOS 17.0, tvOS 17.0, *)) { if (_contextMenuHidden) { [builder removeMenuForIdentifier:UIMenuAutoFill]; } diff --git a/packages/react-native/React/Base/RCTConvert.mm b/packages/react-native/React/Base/RCTConvert.mm index 0194bfa6695..0aacbd85610 100644 --- a/packages/react-native/React/Base/RCTConvert.mm +++ b/packages/react-native/React/Base/RCTConvert.mm @@ -445,6 +445,7 @@ RCT_ENUM_CONVERTER( return type; } +#if !TARGET_OS_TV RCT_MULTI_ENUM_CONVERTER( UIDataDetectorTypes, (@{ @@ -460,6 +461,7 @@ RCT_MULTI_ENUM_CONVERTER( }), UIDataDetectorTypePhoneNumber, unsignedLongLongValue) +#endif RCT_ENUM_CONVERTER( UIKeyboardAppearance, @@ -517,8 +519,12 @@ RCT_ENUM_CONVERTER( UIModalPresentationStyle, (@{ @"fullScreen" : @(UIModalPresentationFullScreen), +#if !TARGET_OS_TV @"pageSheet" : @(UIModalPresentationPageSheet), +#endif +#if !TARGET_OS_TV || __TV_OS_VERSION_MIN_REQUIRED >= 260000 @"formSheet" : @(UIModalPresentationFormSheet), +#endif @"overFullScreen" : @(UIModalPresentationOverFullScreen), }), UIModalPresentationFullScreen, diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm index d02e003a439..cbbc402de42 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm @@ -32,8 +32,12 @@ using namespace facebook::react; @interface RCTTextInputComponentView () < RCTBackedTextInputDelegate, - RCTTextInputViewProtocol, - UIDropInteractionDelegate> + RCTTextInputViewProtocol +#if !TARGET_OS_TV + , + UIDropInteractionDelegate +#endif + > @end static NSSet *returnKeyTypesSet; @@ -211,11 +215,13 @@ static NSSet *returnKeyTypesSet; _backedTextInputView.editable = newTextInputProps.traits.editable; } +#if !TARGET_OS_TV if (newTextInputProps.multiline && newTextInputProps.traits.dataDetectorTypes != oldTextInputProps.traits.dataDetectorTypes) { _backedTextInputView.dataDetectorTypes = RCTUITextViewDataDetectorTypesFromStringVector(newTextInputProps.traits.dataDetectorTypes); } +#endif if (newTextInputProps.traits.enablesReturnKeyAutomatically != oldTextInputProps.traits.enablesReturnKeyAutomatically) { @@ -665,6 +671,7 @@ static NSSet *returnKeyTypesSet; _hasInputAccessoryView = shouldHaveInputAccessoryView; +#if !TARGET_OS_TV if (shouldHaveInputAccessoryView) { NSString *buttonLabel = inputAccessoryViewButtonLabel != nil ? inputAccessoryViewButtonLabel : [self returnKeyTypeToString:returnKeyType]; @@ -682,6 +689,7 @@ static NSSet *returnKeyTypesSet; } else { _backedTextInputView.inputAccessoryView = nil; } +#endif if (_backedTextInputView.isFirstResponder) { [_backedTextInputView reloadInputViews]; diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.h b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.h index 5f20d8762f4..90a2816bf2a 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.h +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.h @@ -41,6 +41,8 @@ UITextInputPasswordRules *RCTUITextInputPasswordRulesFromString(const std::strin UITextSmartInsertDeleteType RCTUITextSmartInsertDeleteTypeFromOptionalBool(std::optional smartInsertDelete); +#if !TARGET_OS_TV UIDataDetectorTypes RCTUITextViewDataDetectorTypesFromStringVector(const std::vector &dataDetectorTypes); +#endif NS_ASSUME_NONNULL_END diff --git a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm index 92467e2953f..d53eee5271d 100644 --- a/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm +++ b/packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm @@ -225,7 +225,7 @@ UITextContentType RCTUITextContentTypeFromString(const std::string &contentType) } #if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 /* __IPHONE_17_0 */ - if (@available(iOS 17.0, *)) { + if (@available(iOS 17.0, tvOS 17.0, *)) { [mutableContentTypeMap addEntriesFromDictionary:@{ @"creditCardExpiration" : UITextContentTypeCreditCardExpiration, @"creditCardExpirationMonth" : UITextContentTypeCreditCardExpirationMonth, @@ -271,6 +271,7 @@ UITextSmartInsertDeleteType RCTUITextSmartInsertDeleteTypeFromOptionalBool(std:: : UITextSmartInsertDeleteTypeDefault; } +#if !TARGET_OS_TV UIDataDetectorTypes RCTUITextViewDataDetectorTypesFromStringVector(const std::vector &dataDetectorTypes) { static dispatch_once_t onceToken; @@ -298,3 +299,4 @@ UIDataDetectorTypes RCTUITextViewDataDetectorTypesFromStringVector(const std::ve } return ret; } +#endif