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
This commit is contained in:
Devan Buggay authored and meta-codesync[bot] committed 2026-01-13 16:09:38 -08:00
1 parent b94bf02bda
commit fce872d2ef
7 files changed
+59 -9

No files matched your search

@@ -21,6 +21,7 @@
NSArray<UIBarButtonItemGroup *> *_initialValueLeadingBarButtonGroups;
NSArray<UIBarButtonItemGroup *> *_initialValueTrailingBarButtonGroups;
NSArray<NSString *> *_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<UIMenuBuilder>)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];
@@ -11,7 +11,13 @@
static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingContext;
@interface RCTBackedTextFieldDelegateAdapter () <UITextFieldDelegate, UITextDropDelegate>
@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<UITextDroppable> *)textDroppableView
@@ -196,11 +206,19 @@ static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingCo
}
}
#endif
@end
#pragma mark - RCTBackedTextViewDelegateAdapter (for UITextView)
@interface RCTBackedTextViewDelegateAdapter () <UITextViewDelegate, UITextDropDelegate>
@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<UITextDroppable> *)textDroppableView
@@ -378,4 +400,6 @@ static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingCo
}
}
#endif
@end
@@ -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<UIMenuBuilder>)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];
}
@@ -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,
@@ -32,8 +32,12 @@ using namespace facebook::react;
@interface RCTTextInputComponentView () <
RCTBackedTextInputDelegate,
RCTTextInputViewProtocol,
UIDropInteractionDelegate>
RCTTextInputViewProtocol
#if !TARGET_OS_TV
,
UIDropInteractionDelegate
#endif
>
@end
static NSSet<NSNumber *> *returnKeyTypesSet;
@@ -211,11 +215,13 @@ static NSSet<NSNumber *> *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<NSNumber *> *returnKeyTypesSet;
_hasInputAccessoryView = shouldHaveInputAccessoryView;
#if !TARGET_OS_TV
if (shouldHaveInputAccessoryView) {
NSString *buttonLabel = inputAccessoryViewButtonLabel != nil ? inputAccessoryViewButtonLabel
: [self returnKeyTypeToString:returnKeyType];
@@ -682,6 +689,7 @@ static NSSet<NSNumber *> *returnKeyTypesSet;
} else {
_backedTextInputView.inputAccessoryView = nil;
}
#endif
if (_backedTextInputView.isFirstResponder) {
[_backedTextInputView reloadInputViews];
@@ -41,6 +41,8 @@ UITextInputPasswordRules *RCTUITextInputPasswordRulesFromString(const std::strin
UITextSmartInsertDeleteType RCTUITextSmartInsertDeleteTypeFromOptionalBool(std::optional<bool> smartInsertDelete);
#if !TARGET_OS_TV
UIDataDetectorTypes RCTUITextViewDataDetectorTypesFromStringVector(const std::vector<std::string> &dataDetectorTypes);
#endif
NS_ASSUME_NONNULL_END
@@ -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<std::string> &dataDetectorTypes)
{
static dispatch_once_t onceToken;
@@ -298,3 +299,4 @@ UIDataDetectorTypes RCTUITextViewDataDetectorTypesFromStringVector(const std::ve
}
return ret;
}
#endif