Skip to content

Commit f62b418

Browse files
fix: add TARGET_OS_VISION guards for 0.83 APIs unavailable on visionOS
1 parent 0e40ec5 commit f62b418

4 files changed

Lines changed: 21 additions & 2 deletions

File tree

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,11 @@ CGFloat RCTFontSizeMultiplier(void)
383383

384384
UIDeviceOrientation RCTDeviceOrientation(void)
385385
{
386+
#if TARGET_OS_VISION
387+
return UIDeviceOrientationPortrait;
388+
#else
386389
return [[UIDevice currentDevice] orientation];
390+
#endif
387391
}
388392

389393
CGSize RCTScreenSize(void)
@@ -402,11 +406,12 @@ CGSize RCTScreenSize(void)
402406
});
403407
});
404408

409+
#if !TARGET_OS_VISION
405410
if (UIDeviceOrientationIsLandscape(RCTDeviceOrientation())) {
406411
return CGSizeMake(portraitSize.height, portraitSize.width);
407-
} else {
408-
return CGSizeMake(portraitSize.width, portraitSize.height);
409412
}
413+
#endif
414+
return CGSizeMake(portraitSize.width, portraitSize.height);
410415
}
411416

412417
CGSize RCTViewportSize(void)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ - (UIWindow *)alertWindow
3838
if (scene != nil) {
3939
_alertWindow = [[UIWindow alloc] initWithWindowScene:scene];
4040
} else {
41+
#if TARGET_OS_VISION
42+
_alertWindow = [[UIWindow alloc] initWithFrame:CGRectZero];
43+
#else
4144
_alertWindow = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
45+
#endif
4246
}
4347

4448
if (_alertWindow != nullptr) {

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,9 @@ - (void)prepareForRecycle
379379
_ignoreNextTextInputCall = NO;
380380
_didMoveToWindow = NO;
381381
_backedTextInputView.inputAccessoryViewID = nil;
382+
#if !TARGET_OS_VISION
382383
_backedTextInputView.inputAccessoryView = nil;
384+
#endif
383385
_hasInputAccessoryView = false;
384386
[_backedTextInputView resignFirstResponder];
385387
}

packages/react-native/React/Fabric/Utils/RCTBoxShadow.mm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,11 @@ static CGColorRef colorRefFromSharedColor(const SharedColor &color)
6565
// with the radius. This is an eyeballed adjustment that has the blur looking
6666
// more like the web.
6767
shadowLayer.shadowRadius = shadow.blurRadius / 2;
68+
#if TARGET_OS_VISION
69+
shadowLayer.contentsScale = [UITraitCollection currentTraitCollection].displayScale;
70+
#else
6871
shadowLayer.contentsScale = [UIScreen mainScreen].scale;
72+
#endif
6973

7074
return shadowLayer;
7175
}
@@ -84,7 +88,11 @@ static CGColorRef colorRefFromSharedColor(const SharedColor &color)
8488
shadowLayer.shadowPath = shadowRectPath;
8589

8690
CAShapeLayer *mask = [CAShapeLayer new];
91+
#if TARGET_OS_VISION
92+
[mask setContentsScale:[UITraitCollection currentTraitCollection].displayScale];
93+
#else
8794
[mask setContentsScale:[UIScreen mainScreen].scale];
95+
#endif
8896
CGMutablePathRef path = CGPathCreateMutable();
8997
CGPathRef layerPath =
9098
RCTPathCreateWithRoundedRect(shadowLayer.bounds, RCTGetCornerInsets(cornerRadii, UIEdgeInsetsZero), nil, NO);

0 commit comments

Comments
 (0)