Skip to content

Commit 40d0484

Browse files
sbuggayfacebook-github-bot
authored andcommitted
Compile out various unsupported TextInput APIs for AppleTV (#55129)
Summary: TextInput uses a lot of UIKit APIs that are unavailable on AppleTV, compiling them out. Changelog: [internal] Reviewed By: shwanton Differential Revision: D90514227
1 parent 8186562 commit 40d0484

7 files changed

Lines changed: 59 additions & 9 deletions

File tree

packages/react-native/Libraries/Text/TextInput/Multiline/RCTUITextView.mm

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ @implementation RCTUITextView {
2121
NSArray<UIBarButtonItemGroup *> *_initialValueLeadingBarButtonGroups;
2222
NSArray<UIBarButtonItemGroup *> *_initialValueTrailingBarButtonGroups;
2323
NSArray<NSString *> *_acceptDragAndDropTypes;
24+
BOOL _disableKeyboardShortcuts;
2425
}
2526

2627
static UIFont *defaultPlaceholderFont(void)
@@ -53,7 +54,9 @@ - (instancetype)initWithFrame:(CGRect)frame
5354
self.textColor = [UIColor blackColor];
5455
// This line actually removes 5pt (default value) left and right padding in UITextView.
5556
self.textContainer.lineFragmentPadding = 0;
57+
#if !TARGET_OS_TV
5658
self.scrollsToTop = NO;
59+
#endif
5760
self.scrollEnabled = YES;
5861
_initialValueLeadingBarButtonGroups = nil;
5962
_initialValueTrailingBarButtonGroups = nil;
@@ -149,6 +152,7 @@ - (void)textDidChange
149152

150153
- (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts
151154
{
155+
_disableKeyboardShortcuts = disableKeyboardShortcuts;
152156
#if TARGET_OS_IOS
153157
// Initialize the initial values only once
154158
if (_initialValueLeadingBarButtonGroups == nil) {
@@ -165,10 +169,14 @@ - (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts
165169
self.inputAssistantItem.leadingBarButtonGroups = _initialValueLeadingBarButtonGroups;
166170
self.inputAssistantItem.trailingBarButtonGroups = _initialValueTrailingBarButtonGroups;
167171
}
168-
_disableKeyboardShortcuts = disableKeyboardShortcuts;
169172
#endif
170173
}
171174

175+
- (BOOL)disableKeyboardShortcuts
176+
{
177+
return _disableKeyboardShortcuts;
178+
}
179+
172180
#pragma mark - Overrides
173181

174182
- (void)setFont:(UIFont *)font
@@ -306,7 +314,7 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
306314

307315
- (void)buildMenuWithBuilder:(id<UIMenuBuilder>)builder
308316
{
309-
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000
317+
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 && !TARGET_OS_TV
310318
if (@available(iOS 17.0, *)) {
311319
if (_contextMenuHidden) {
312320
[builder removeMenuForIdentifier:UIMenuAutoFill];

packages/react-native/Libraries/Text/TextInput/RCTBackedTextInputDelegateAdapter.mm

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111

1212
static void *TextFieldSelectionObservingContext = &TextFieldSelectionObservingContext;
1313

14-
@interface RCTBackedTextFieldDelegateAdapter () <UITextFieldDelegate, UITextDropDelegate>
14+
@interface RCTBackedTextFieldDelegateAdapter () <
15+
UITextFieldDelegate
16+
#if !TARGET_OS_TV
17+
,
18+
UITextDropDelegate
19+
#endif
20+
>
1521
@end
1622

1723
@implementation RCTBackedTextFieldDelegateAdapter {
@@ -25,7 +31,9 @@ - (instancetype)initWithTextField:(UITextField<RCTBackedTextInputViewProtocol> *
2531
if (self = [super init]) {
2632
_backedTextInputView = backedTextInputView;
2733
backedTextInputView.delegate = self;
34+
#if !TARGET_OS_TV
2835
backedTextInputView.textDropDelegate = self;
36+
#endif
2937

3038
[_backedTextInputView addTarget:self
3139
action:@selector(textFieldDidChange)
@@ -160,6 +168,8 @@ - (void)textFieldProbablyDidChangeSelection
160168
[_backedTextInputView.textInputDelegate textInputDidChangeSelection];
161169
}
162170

171+
#if !TARGET_OS_TV
172+
163173
#pragma mark - UITextDropDelegate
164174

165175
- (UITextDropEditability)textDroppableView:(UIView<UITextDroppable> *)textDroppableView
@@ -196,11 +206,19 @@ - (bool)_shouldAcceptDrop:(id<UITextDropRequest>)drop
196206
}
197207
}
198208

209+
#endif
210+
199211
@end
200212

201213
#pragma mark - RCTBackedTextViewDelegateAdapter (for UITextView)
202214

203-
@interface RCTBackedTextViewDelegateAdapter () <UITextViewDelegate, UITextDropDelegate>
215+
@interface RCTBackedTextViewDelegateAdapter () <
216+
UITextViewDelegate
217+
#if !TARGET_OS_TV
218+
,
219+
UITextDropDelegate
220+
#endif
221+
>
204222
@end
205223

206224
@implementation RCTBackedTextViewDelegateAdapter {
@@ -216,7 +234,9 @@ - (instancetype)initWithTextView:(UITextView<RCTBackedTextInputViewProtocol> *)b
216234
if (self = [super init]) {
217235
_backedTextInputView = backedTextInputView;
218236
backedTextInputView.delegate = self;
237+
#if !TARGET_OS_TV
219238
backedTextInputView.textDropDelegate = self;
239+
#endif
220240
}
221241

222242
return self;
@@ -342,6 +362,8 @@ - (void)textViewProbablyDidChangeSelection
342362
[_backedTextInputView.textInputDelegate textInputDidChangeSelection];
343363
}
344364

365+
#if !TARGET_OS_TV
366+
345367
#pragma mark - UITextDropDelegate
346368

347369
- (UITextDropEditability)textDroppableView:(UIView<UITextDroppable> *)textDroppableView
@@ -378,4 +400,6 @@ - (bool)_shouldAcceptDrop:(id<UITextDropRequest>)drop
378400
}
379401
}
380402

403+
#endif
404+
381405
@end

packages/react-native/Libraries/Text/TextInput/Singleline/RCTUITextField.mm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ - (void)setSecureTextEntry:(BOOL)secureTextEntry
136136

137137
- (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts
138138
{
139+
_disableKeyboardShortcuts = disableKeyboardShortcuts;
139140
#if TARGET_OS_IOS
140141
// Initialize the initial values only once
141142
if (_initialValueLeadingBarButtonGroups == nil) {
@@ -152,7 +153,6 @@ - (void)setDisableKeyboardShortcuts:(BOOL)disableKeyboardShortcuts
152153
self.inputAssistantItem.leadingBarButtonGroups = _initialValueLeadingBarButtonGroups;
153154
self.inputAssistantItem.trailingBarButtonGroups = _initialValueTrailingBarButtonGroups;
154155
}
155-
_disableKeyboardShortcuts = disableKeyboardShortcuts;
156156
#endif
157157
}
158158

@@ -186,7 +186,7 @@ - (BOOL)canPerformAction:(SEL)action withSender:(id)sender
186186
- (void)buildMenuWithBuilder:(id<UIMenuBuilder>)builder
187187
{
188188
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000
189-
if (@available(iOS 17.0, *)) {
189+
if (@available(iOS 17.0, tvOS 17.0, *)) {
190190
if (_contextMenuHidden) {
191191
[builder removeMenuForIdentifier:UIMenuAutoFill];
192192
}

packages/react-native/React/Base/RCTConvert.mm

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ + (UIKeyboardType)UIKeyboardType:(id)json RCT_DYNAMIC
445445
return type;
446446
}
447447

448+
#if !TARGET_OS_TV
448449
RCT_MULTI_ENUM_CONVERTER(
449450
UIDataDetectorTypes,
450451
(@{
@@ -460,6 +461,7 @@ + (UIKeyboardType)UIKeyboardType:(id)json RCT_DYNAMIC
460461
}),
461462
UIDataDetectorTypePhoneNumber,
462463
unsignedLongLongValue)
464+
#endif
463465

464466
RCT_ENUM_CONVERTER(
465467
UIKeyboardAppearance,
@@ -517,8 +519,12 @@ + (UIKeyboardType)UIKeyboardType:(id)json RCT_DYNAMIC
517519
UIModalPresentationStyle,
518520
(@{
519521
@"fullScreen" : @(UIModalPresentationFullScreen),
522+
#if !TARGET_OS_TV
520523
@"pageSheet" : @(UIModalPresentationPageSheet),
524+
#endif
525+
#if !TARGET_OS_TV || __TV_OS_VERSION_MIN_REQUIRED >= 260000
521526
@"formSheet" : @(UIModalPresentationFormSheet),
527+
#endif
522528
@"overFullScreen" : @(UIModalPresentationOverFullScreen),
523529
}),
524530
UIModalPresentationFullScreen,

packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputComponentView.mm

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@
3232

3333
@interface RCTTextInputComponentView () <
3434
RCTBackedTextInputDelegate,
35-
RCTTextInputViewProtocol,
36-
UIDropInteractionDelegate>
35+
RCTTextInputViewProtocol
36+
#if !TARGET_OS_TV
37+
,
38+
UIDropInteractionDelegate
39+
#endif
40+
>
3741
@end
3842

3943
static NSSet<NSNumber *> *returnKeyTypesSet;
@@ -211,11 +215,13 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
211215
_backedTextInputView.editable = newTextInputProps.traits.editable;
212216
}
213217

218+
#if !TARGET_OS_TV
214219
if (newTextInputProps.multiline &&
215220
newTextInputProps.traits.dataDetectorTypes != oldTextInputProps.traits.dataDetectorTypes) {
216221
_backedTextInputView.dataDetectorTypes =
217222
RCTUITextViewDataDetectorTypesFromStringVector(newTextInputProps.traits.dataDetectorTypes);
218223
}
224+
#endif
219225

220226
if (newTextInputProps.traits.enablesReturnKeyAutomatically !=
221227
oldTextInputProps.traits.enablesReturnKeyAutomatically) {
@@ -665,6 +671,7 @@ - (void)setDefaultInputAccessoryView
665671

666672
_hasInputAccessoryView = shouldHaveInputAccessoryView;
667673

674+
#if !TARGET_OS_TV
668675
if (shouldHaveInputAccessoryView) {
669676
NSString *buttonLabel = inputAccessoryViewButtonLabel != nil ? inputAccessoryViewButtonLabel
670677
: [self returnKeyTypeToString:returnKeyType];
@@ -682,6 +689,7 @@ - (void)setDefaultInputAccessoryView
682689
} else {
683690
_backedTextInputView.inputAccessoryView = nil;
684691
}
692+
#endif
685693

686694
if (_backedTextInputView.isFirstResponder) {
687695
[_backedTextInputView reloadInputViews];

packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ UITextInputPasswordRules *RCTUITextInputPasswordRulesFromString(const std::strin
4141

4242
UITextSmartInsertDeleteType RCTUITextSmartInsertDeleteTypeFromOptionalBool(std::optional<bool> smartInsertDelete);
4343

44+
#if !TARGET_OS_TV
4445
UIDataDetectorTypes RCTUITextViewDataDetectorTypesFromStringVector(const std::vector<std::string> &dataDetectorTypes);
46+
#endif
4547

4648
NS_ASSUME_NONNULL_END

packages/react-native/React/Fabric/Mounting/ComponentViews/TextInput/RCTTextInputUtils.mm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ UITextContentType RCTUITextContentTypeFromString(const std::string &contentType)
225225
}
226226

227227
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 /* __IPHONE_17_0 */
228-
if (@available(iOS 17.0, *)) {
228+
if (@available(iOS 17.0, tvOS 17.0, *)) {
229229
[mutableContentTypeMap addEntriesFromDictionary:@{
230230
@"creditCardExpiration" : UITextContentTypeCreditCardExpiration,
231231
@"creditCardExpirationMonth" : UITextContentTypeCreditCardExpirationMonth,
@@ -271,6 +271,7 @@ UITextSmartInsertDeleteType RCTUITextSmartInsertDeleteTypeFromOptionalBool(std::
271271
: UITextSmartInsertDeleteTypeDefault;
272272
}
273273

274+
#if !TARGET_OS_TV
274275
UIDataDetectorTypes RCTUITextViewDataDetectorTypesFromStringVector(const std::vector<std::string> &dataDetectorTypes)
275276
{
276277
static dispatch_once_t onceToken;
@@ -298,3 +299,4 @@ UIDataDetectorTypes RCTUITextViewDataDetectorTypesFromStringVector(const std::ve
298299
}
299300
return ret;
300301
}
302+
#endif

0 commit comments

Comments
 (0)