Skip to content

Commit e01dfa4

Browse files
committed
[Draft] Add visionOS support
1 parent 50bec0c commit e01dfa4

File tree

59 files changed

+725
-119
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+725
-119
lines changed

packages/react-native/Libraries/AppDelegate/RCTAppDelegate.mm

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#import <react/renderer/runtimescheduler/RuntimeScheduler.h>
1313
#import "RCTAppSetupUtils.h"
1414
#import "RCTLegacyInteropComponents.h"
15+
#import "RCTUtils.h" // [visionOS]
1516

1617
#if RCT_NEW_ARCH_ENABLED
1718
#if RN_DISABLE_OSS_PLUGIN_HEADER
@@ -133,7 +134,11 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification
133134
rootView = [self createRootViewWithBridge:self.bridge moduleName:self.moduleName initProps:initProps];
134135
}
135136
#if !TARGET_OS_OSX // [macOS]
137+
#if !TARGET_OS_VISION // [visionOS]
136138
self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
139+
#else // [visionOS
140+
self.window = [[UIWindow alloc] initWithFrame:RCTForegroundWindow().bounds];
141+
#endif // visionOS]
137142
UIViewController *rootViewController = [self createRootViewController];
138143
[self setRootView:rootView toRootViewController:rootViewController];
139144
self.window.rootViewController = rootViewController;

packages/react-native/Libraries/PushNotificationIOS/RCTPushNotificationManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ typedef void (^RCTRemoteNotificationCallback)(UIBackgroundFetchResult result);
1616
#endif // [macOS]
1717

1818
#if !TARGET_OS_UIKITFORMAC
19-
#if !TARGET_OS_OSX // [macOS]
19+
#if !TARGET_OS_OSX && !TARGET_OS_VISION // [macOS]
2020
+ (void)didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;
2121
#endif // [macOS]
2222
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;
2323
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification;
24-
#if !TARGET_OS_OSX // [macOS]
24+
#if !TARGET_OS_OSX && !TARGET_OS_VISION // [macOS]
2525
+ (void)didReceiveRemoteNotification:(NSDictionary *)notification
2626
fetchCompletionHandler:(RCTRemoteNotificationCallback)completionHandler;
2727
+ (void)didReceiveLocalNotification:(UILocalNotification *)notification;

packages/react-native/Libraries/PushNotificationIOS/RCTPushNotificationManager.mm

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ @interface RCTPushNotificationManager () <NativePushNotificationManagerIOSSpec>
4848

4949
@implementation RCTConvert (UILocalNotification)
5050

51-
#if !TARGET_OS_OSX // [macOS]
51+
#if !TARGET_OS_OSX // [macOS]
52+
#if !TARGET_OS_VISION // [visionOS] TODO SAAD
5253
+ (UILocalNotification *)UILocalNotification:(id)json
5354
{
5455
NSDictionary<NSString *, id> *details = [self NSDictionary:json];
@@ -69,6 +70,7 @@ + (UILocalNotification *)UILocalNotification:(id)json
6970
}
7071
return notification;
7172
}
73+
#endif // [visionOS] TODO SAAD
7274
#else // [macOS
7375
+ (NSUserNotification *)NSUserNotification:(id)json
7476
{
@@ -126,7 +128,7 @@ @interface RCTPushNotificationManager () <NativePushNotificationManagerIOSSpec>
126128

127129
@implementation RCTPushNotificationManager
128130

129-
#if !TARGET_OS_UIKITFORMAC && !TARGET_OS_OSX // [macOS]
131+
#if !TARGET_OS_UIKITFORMAC && !TARGET_OS_OSX && !TARGET_OS_VISION // [macOS]
130132

131133
static NSDictionary *RCTFormatLocalNotification(UILocalNotification *notification)
132134
{
@@ -236,9 +238,11 @@ - (void)stopObserving
236238
}
237239

238240
#if !TARGET_OS_OSX // [macOS]
241+
#if !TARGET_OS_VISION // [visionOS]
239242
+ (void)didRegisterUserNotificationSettings:(__unused UIUserNotificationSettings *)notificationSettings
240243
{
241244
}
245+
#endif // [visionOS]
242246
#endif // [macOS]
243247

244248
+ (void)didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
@@ -279,12 +283,14 @@ + (void)didReceiveRemoteNotification:(NSDictionary *)notification
279283
userInfo:userInfo];
280284
}
281285

286+
#if !TARGET_OS_VISION // [visionOS]
282287
+ (void)didReceiveLocalNotification:(UILocalNotification *)notification
283288
{
284289
[[NSNotificationCenter defaultCenter] postNotificationName:kLocalNotificationReceived
285290
object:self
286291
userInfo:RCTFormatLocalNotification(notification)];
287292
}
293+
#endif // [visionOS]
288294

289295
#else // [macOS
290296

@@ -401,6 +407,7 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
401407
// Add a listener to make sure that startObserving has been called
402408
[self addListener:@"remoteNotificationsRegistered"];
403409

410+
#if !TARGET_OS_VISION // [visionOS]
404411
#if !TARGET_OS_OSX // [macOS
405412
UIUserNotificationType types = UIUserNotificationTypeNone;
406413

@@ -442,6 +449,7 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
442449
});
443450
}
444451
}];
452+
#endif // [visionOS]
445453
}
446454

447455
RCT_EXPORT_METHOD(abandonPermissions)
@@ -518,7 +526,9 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
518526
notificationDict[@"soundName"] = notification.soundName();
519527
}
520528
}
529+
#if !TARGET_OS_VISION // [visionOS]
521530
[RCTSharedApplication() presentLocalNotificationNow:[RCTConvert UILocalNotification:notificationDict]];
531+
#endif // [visionOS]
522532
}
523533
#else // [macOS
524534
RCT_EXPORT_METHOD(presentLocalNotification:(NSUserNotification *)notification)
@@ -549,7 +559,9 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
549559
notificationDict[@"soundName"] = notification.soundName();
550560
}
551561
}
562+
#if !TARGET_OS_VISION // [visionOS]
552563
[RCTSharedApplication() scheduleLocalNotification:[RCTConvert UILocalNotification:notificationDict]];
564+
#endif // [visionOS]
553565
}
554566
#else // [macOS
555567
RCT_EXPORT_METHOD(scheduleLocalNotification:(NSUserNotification *)notification)
@@ -561,7 +573,9 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
561573
RCT_EXPORT_METHOD(cancelAllLocalNotifications)
562574
{
563575
#if !TARGET_OS_OSX // [macOS]
576+
#if !TARGET_OS_VISION // [visionOS]
564577
[RCTSharedApplication() cancelAllLocalNotifications];
578+
#endif // [visionOS]
565579
#else // [macOS
566580
for (NSUserNotification *notif in [NSUserNotificationCenter defaultUserNotificationCenter].scheduledNotifications) {
567581
[[NSUserNotificationCenter defaultUserNotificationCenter] removeScheduledNotification:notif];
@@ -571,6 +585,7 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
571585

572586
RCT_EXPORT_METHOD(cancelLocalNotifications : (NSDictionary<NSString *, id> *)userInfo)
573587
{
588+
#if !TARGET_OS_VISION // [visionOS]
574589
#if !TARGET_OS_OSX // [macOS]
575590
for (UILocalNotification *notification in RCTSharedApplication().scheduledLocalNotifications) {
576591
#else // [macOS
@@ -598,12 +613,14 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
598613
}
599614
#endif // macOS]
600615
}
616+
#endif // [visionOS]
601617
}
602618

603619
RCT_EXPORT_METHOD(getInitialNotification
604620
: (RCTPromiseResolveBlock)resolve reject
605621
: (__unused RCTPromiseRejectBlock)reject)
606622
{
623+
#if !TARGET_OS_VISION // [visionOS]
607624
#if !TARGET_OS_OSX // [macOS]
608625
NSMutableDictionary<NSString *, id> *initialNotification =
609626
[self.bridge.launchOptions[UIApplicationLaunchOptionsRemoteNotificationKey] mutableCopy];
@@ -627,10 +644,12 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
627644
resolve((id)kCFNull);
628645
}
629646
#endif // macOS]
647+
#endif // [visionOS]
630648
}
631649

632650
RCT_EXPORT_METHOD(getScheduledLocalNotifications : (RCTResponseSenderBlock)callback)
633651
{
652+
#if !TARGET_OS_VISION // [visionOS]
634653
#if !TARGET_OS_OSX // [macOS]
635654
NSArray<UILocalNotification *> *scheduledLocalNotifications = RCTSharedApplication().scheduledLocalNotifications;
636655
#endif // [macOS]
@@ -645,6 +664,7 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
645664
}
646665
#endif // macOS]
647666
callback(@[ formattedScheduledLocalNotifications ]);
667+
#endif // [visionOS]
648668
}
649669

650670
RCT_EXPORT_METHOD(removeAllDeliveredNotifications)
@@ -674,6 +694,7 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
674694

675695
RCT_EXPORT_METHOD(getDeliveredNotifications : (RCTResponseSenderBlock)callback)
676696
{
697+
#if !TARGET_OS_VISION // [visionOS]
677698
#if !TARGET_OS_OSX // [macOS]
678699
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
679700
[center getDeliveredNotificationsWithCompletionHandler:^(NSArray<UNNotification *> *_Nonnull notifications) {
@@ -691,6 +712,7 @@ - (void)handleRemoteNotificationRegistrationError:(NSNotification *)notification
691712
}
692713
callback(@[formattedNotifications]);
693714
#endif // macOS]
715+
#endif // [visionOS]
694716
}
695717

696718
RCT_EXPORT_METHOD(getAuthorizationStatus : (RCTResponseSenderBlock)callback)

packages/react-native/Libraries/Text/React-RCTText.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ Pod::Spec.new do |s|
2828
s.source = source
2929
s.source_files = "**/*.{h,m,mm}"
3030
s.ios.exclude_files = "**/macOS/*" # [macOS]
31+
s.visionos.exclude_files = "**/macOS/*" # [macOS]
3132
s.preserve_paths = "package.json", "LICENSE", "LICENSE-docs"
3233
s.header_dir = "RCTText"
3334
s.ios.framework = ["MobileCoreServices"] # [macOS] Restrict to iOS

packages/react-native/Libraries/Text/Text/RCTTextView.mm

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ - (void)handleLongPress:(UILongPressGestureRecognizer *)gesture
364364
{
365365
// TODO: Adopt showMenuFromRect (necessary for UIKitForMac)
366366
#if !TARGET_OS_UIKITFORMAC
367+
#if !TARGET_OS_VISION // [visionOS]
367368
UIMenuController *menuController = [UIMenuController sharedMenuController];
368369

369370
if (menuController.isMenuVisible) {
@@ -376,6 +377,7 @@ - (void)handleLongPress:(UILongPressGestureRecognizer *)gesture
376377

377378
[menuController setTargetRect:self.bounds inView:self];
378379
[menuController setMenuVisible:YES animated:YES];
380+
#endif // [visionOS]
379381
#endif
380382
}
381383
#else // [macOS

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,7 @@ - (void)didSetProps:(NSArray<NSString *> *)changedProps
863863
- (void)setCustomInputAccessoryViewWithNativeID:(NSString *)nativeID
864864
{
865865
#if !TARGET_OS_OSX // [macOS]
866+
#if !TARGET_OS_VISION // [visionOS]
866867
__weak RCTBaseTextInputView *weakSelf = self;
867868
[_bridge.uiManager rootViewForReactTag:self.reactTag
868869
withCompletion:^(UIView *rootView) {
@@ -877,12 +878,14 @@ - (void)setCustomInputAccessoryViewWithNativeID:(NSString *)nativeID
877878
}
878879
}
879880
}];
881+
#endif // [visionOS]
880882
#endif // [macOS]
881883
}
882884

883885
- (void)setDefaultInputAccessoryView
884886
{
885887
#if !TARGET_OS_OSX // [macOS]
888+
#if !TARGET_OS_VISION // [visionOS]
886889
UIView<RCTBackedTextInputViewProtocol> *textInputView = self.backedTextInputView;
887890
UIKeyboardType keyboardType = textInputView.keyboardType;
888891

@@ -914,6 +917,7 @@ - (void)setDefaultInputAccessoryView
914917
textInputView.inputAccessoryView = nil;
915918
}
916919
[self reloadInputViewsIfNecessary];
920+
#endif // [visionOS]
917921
#endif // [macOS]
918922
}
919923

packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
// [macOS]
99

10+
#if TARGET_OS_OSX // [macOS
11+
1012
#define RCT_SUBCLASS_SECURETEXTFIELD 1
1113

1214
#include <React/RCTUITextField.h>
15+
16+
#endif // [macOS]

packages/react-native/Libraries/Text/TextInput/Singleline/macOS/RCTUISecureTextField.m

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77

88
// [macOS]
99

10+
#if !TARGET_OS_OSX // [macOS]
11+
1012
#define RCT_SUBCLASS_SECURETEXTFIELD 1
1113

1214
#include "../RCTUITextField.mm"
15+
16+
#endif // [macOS]

packages/react-native/React-Core.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ end
1818

1919
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -DFOLLY_CFG_NO_COROUTINES=1 -DFOLLY_HAVE_CLOCK_GETTIME=1 -Wno-comma -Wno-shorten-64-to-32'
2020
folly_version = '2023.08.07.00'
21-
socket_rocket_version = '0.7.0' # [macOS]
21+
socket_rocket_version = '0.7.0.1' # [macOS]
2222
boost_compiler_flags = '-Wno-documentation'
2323

2424
use_hermes = ENV['USE_HERMES'] == nil || ENV['USE_HERMES'] == '1'

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,6 @@ + (UIKeyboardType)UIKeyboardType:(id)json RCT_DYNAMIC
489489
UIReturnKeyDefault,
490490
integerValue)
491491

492-
#if !TARGET_OS_OSX // [macOS]
493492
RCT_ENUM_CONVERTER(
494493
UIUserInterfaceStyle,
495494
(@{
@@ -499,7 +498,6 @@ + (UIKeyboardType)UIKeyboardType:(id)json RCT_DYNAMIC
499498
}),
500499
UIUserInterfaceStyleUnspecified,
501500
integerValue)
502-
#endif // [macOS]
503501

504502
RCT_ENUM_CONVERTER(
505503
UIInterfaceOrientationMask,
@@ -542,12 +540,16 @@ + (UIKeyboardType)UIKeyboardType:(id)json RCT_DYNAMIC
542540
(@{
543541
@"default" : @(UIBarStyleDefault),
544542
@"black" : @(UIBarStyleBlack),
543+
#if !TARGET_OS_VISION // [macOS] Github #NNN - visionOS Support
545544
@"blackOpaque" : @(UIBarStyleBlackOpaque),
546545
@"blackTranslucent" : @(UIBarStyleBlackTranslucent),
546+
#endif
547547
}),
548548
UIBarStyleDefault,
549549
integerValue)
550-
#else // [macOS
550+
#endif // [macOS]
551+
552+
#if !TARGET_OS_OX // [macOS
551553
RCT_MULTI_ENUM_CONVERTER(NSTextCheckingTypes, (@{
552554
@"ortography": @(NSTextCheckingTypeOrthography),
553555
@"spelling": @(NSTextCheckingTypeSpelling),

0 commit comments

Comments
 (0)