Skip to content

Commit 87d3a19

Browse files
sbuggaymeta-codesync[bot]
authored andcommitted
Compile out more unsupported UIKit APIs (#55213)
Summary: Pull Request resolved: #55213 Compiling out some various unsupported UIKit APIs. Changelog: [Internal] Reviewed By: cipolleschi Differential Revision: D90825451 fbshipit-source-id: ee88cc3937c5e17540a2951b39a354f297dd3c41
1 parent 7b0dbc1 commit 87d3a19

8 files changed

Lines changed: 51 additions & 5 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,10 +311,12 @@ void RCTUnsafeExecuteOnMainQueueSync(dispatch_block_t block)
311311
return;
312312
}
313313

314+
#if !TARGET_OS_TV
314315
if (ReactNativeFeatureFlags::enableMainQueueCoordinatorOnIOS()) {
315316
unsafeExecuteOnMainThreadSync(block);
316317
return;
317318
}
319+
#endif
318320

319321
dispatch_sync(dispatch_get_main_queue(), ^{
320322
block();
@@ -339,10 +341,12 @@ static void RCTUnsafeExecuteOnMainQueueOnceSync(dispatch_once_t *onceToken, disp
339341
return;
340342
}
341343

344+
#if !TARGET_OS_TV
342345
if (ReactNativeFeatureFlags::enableMainQueueCoordinatorOnIOS()) {
343346
unsafeExecuteOnMainThreadSync(block);
344347
return;
345348
}
349+
#endif
346350

347351
dispatch_sync(dispatch_get_main_queue(), executeOnce);
348352
}
@@ -421,10 +425,9 @@ CGSize RCTViewportSize(void)
421425

422426
CGSize RCTSwitchSize(void)
423427
{
424-
// UISwitch is not supported on AppleTV
425428
#if TARGET_OS_TV
426429
return CGSizeMake(0, 0);
427-
#endif
430+
#else
428431
static CGSize rctSwitchSize;
429432
static dispatch_once_t onceToken;
430433
dispatch_once(&onceToken, ^{
@@ -433,6 +436,7 @@ CGSize RCTSwitchSize(void)
433436
});
434437
});
435438
return rctSwitchSize;
439+
#endif
436440
}
437441

438442
CGFloat RCTRoundPixelValue(CGFloat value)
@@ -642,7 +646,9 @@ BOOL RCTRunningInAppExtension(void)
642646
// We have apps internally that might use UIScenes which are not window scenes.
643647
// Calling keyWindow on a UIScene which is not a UIWindowScene can cause a crash
644648
UIWindowScene *windowScene = (UIWindowScene *)sceneToUse;
645-
return windowScene.keyWindow;
649+
if (@available(iOS 15.0, tvOS 15.0, *)) {
650+
return windowScene.keyWindow;
651+
}
646652
}
647653

648654
return nil;

packages/react-native/React/CoreModules/RCTDeviceInfo.mm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ - (void)_cleanupObservers
166166
static BOOL RCTIsIPhoneNotched()
167167
{
168168
static BOOL isIPhoneNotched = NO;
169-
static dispatch_once_t onceToken;
170169

171170
#if TARGET_OS_IOS
171+
static dispatch_once_t onceToken;
172172
dispatch_once(&onceToken, ^{
173173
RCTAssertMainQueue();
174174

packages/react-native/React/CoreModules/RCTPerfMonitor.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,11 @@ - (UIView *)container
180180
[_container addGestureRecognizer:self.gestureRecognizer];
181181
[_container addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap)]];
182182

183+
#if TARGET_OS_TV
184+
_container.backgroundColor = [UIColor whiteColor];
185+
#else
183186
_container.backgroundColor = [UIColor systemBackgroundColor];
187+
#endif
184188
}
185189

186190
return _container;

packages/react-native/React/Fabric/Mounting/ComponentViews/ScrollView/RCTScrollViewComponentView.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,9 +352,11 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
352352
MAP_SCROLL_VIEW_PROP(maximumZoomScale);
353353
MAP_SCROLL_VIEW_PROP(minimumZoomScale);
354354
MAP_SCROLL_VIEW_PROP(scrollEnabled);
355+
#if !TARGET_OS_TV
355356
MAP_SCROLL_VIEW_PROP(pagingEnabled);
356357
MAP_SCROLL_VIEW_PROP(pinchGestureEnabled);
357358
MAP_SCROLL_VIEW_PROP(scrollsToTop);
359+
#endif
358360
MAP_SCROLL_VIEW_PROP(showsHorizontalScrollIndicator);
359361
MAP_SCROLL_VIEW_PROP(showsVerticalScrollIndicator);
360362

packages/react-native/React/Fabric/Mounting/ComponentViews/Text/RCTParagraphComponentView.mm

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,16 @@ @interface RCTParagraphTextView : UIView
3434

3535
@end
3636

37+
#if !TARGET_OS_TV
3738
@interface RCTParagraphComponentView () <UIEditMenuInteractionDelegate>
3839

3940
@property (nonatomic, nullable) UIEditMenuInteraction *editMenuInteraction API_AVAILABLE(ios(16.0));
4041

4142
@end
43+
#else
44+
@interface RCTParagraphComponentView ()
45+
@end
46+
#endif
4247

4348
@implementation RCTParagraphComponentView {
4449
ParagraphAttributes _paragraphAttributes;
@@ -280,6 +285,7 @@ - (SharedTouchEventEmitter)touchEventEmitterAtPoint:(CGPoint)point
280285

281286
#pragma mark - Context Menu
282287

288+
#if !TARGET_OS_TV
283289
- (void)enableContextMenu
284290
{
285291
_longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self
@@ -357,6 +363,15 @@ - (void)copy:(id)sender
357363
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
358364
pasteboard.items = @[ item ];
359365
}
366+
#else
367+
- (void)enableContextMenu
368+
{
369+
}
370+
371+
- (void)disableContextMenu
372+
{
373+
}
374+
#endif
360375

361376
@end
362377

packages/react-native/React/Fabric/Mounting/ComponentViews/View/RCTViewComponentView.mm

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,6 +378,7 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
378378

379379
// `accessibilityShowsLargeContentViewer`
380380
if (oldViewProps.accessibilityShowsLargeContentViewer != newViewProps.accessibilityShowsLargeContentViewer) {
381+
#if !TARGET_OS_TV
381382
if (@available(iOS 13.0, *)) {
382383
if (newViewProps.accessibilityShowsLargeContentViewer) {
383384
self.showsLargeContentViewer = YES;
@@ -387,13 +388,16 @@ - (void)updateProps:(const Props::Shared &)props oldProps:(const Props::Shared &
387388
self.showsLargeContentViewer = NO;
388389
}
389390
}
391+
#endif
390392
}
391393

392394
// `accessibilityLargeContentTitle`
393395
if (oldViewProps.accessibilityLargeContentTitle != newViewProps.accessibilityLargeContentTitle) {
396+
#if !TARGET_OS_TV
394397
if (@available(iOS 13.0, *)) {
395398
self.largeContentTitle = RCTNSStringFromStringNilIfEmpty(newViewProps.accessibilityLargeContentTitle);
396399
}
400+
#endif
397401
}
398402

399403
// `accessibilityOrder`
@@ -941,7 +945,8 @@ - (void)invalidateLayer
941945
layer.shadowPath = nil;
942946
}
943947

944-
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 /* __IPHONE_17_0 */
948+
#if !TARGET_OS_TV && defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && \
949+
__IPHONE_OS_VERSION_MAX_ALLOWED >= 170000 /* __IPHONE_17_0 */
945950
// Stage 1.5. Cursor / Hover Effects
946951
if (@available(iOS 17.0, *)) {
947952
UIHoverStyle *hoverStyle = nil;

packages/react-native/React/Modules/RCTLayoutAnimation.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,14 @@ static UIViewAnimationOptions UIViewAnimationOptionsFromRCTAnimationType(RCTAnim
3333
}
3434
}
3535

36+
#if TARGET_OS_TV
37+
38+
// No-op on tvOS
39+
+ (void)initializeStatics
40+
{
41+
}
42+
43+
#else
3644
// Use a custom initialization function rather than implementing `+initialize` so that we can control
3745
// when the initialization code runs. `+initialize` runs immediately before the first message is sent
3846
// to the class which may be too late for us. By this time, we may have missed some
@@ -54,6 +62,8 @@ + (void)keyboardWillChangeFrame:(NSNotification *)notification
5462
_currentKeyboardAnimationCurve = [userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue];
5563
}
5664

65+
#endif
66+
5767
- (instancetype)initWithDuration:(NSTimeInterval)duration
5868
delay:(NSTimeInterval)delay
5969
property:(NSString *)property

packages/react-native/React/Profiler/RCTProfile.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ + (void)toggle:(UIButton *)target
393393
RCTProfileEnd(RCTProfilingBridge(), ^(NSString *result) {
394394
NSString *outFile = [NSTemporaryDirectory() stringByAppendingString:@"tmp_trace.json"];
395395
[result writeToFile:outFile atomically:YES encoding:NSUTF8StringEncoding error:nil];
396+
#if !TARGET_OS_TV
396397
UIActivityViewController *activityViewController =
397398
[[UIActivityViewController alloc] initWithActivityItems:@[ [NSURL fileURLWithPath:outFile] ]
398399
applicationActivities:nil];
@@ -409,6 +410,9 @@ + (void)toggle:(UIButton *)target
409410
animated:YES
410411
completion:nil];
411412
});
413+
#else
414+
RCTProfileControlsWindow.hidden = NO;
415+
#endif
412416
});
413417
} else {
414418
RCTProfileInit(RCTProfilingBridge());

0 commit comments

Comments
 (0)