File tree 5 files changed +44
-0
lines changed
rn-tester/RNTester-visionOS
5 files changed +44
-0
lines changed Original file line number Diff line number Diff line change 24
24
continueUserActivity : (nonnull NSUserActivity *)userActivity
25
25
restorationHandler : (nonnull void (^)(NSArray <id <UIUserActivityRestoring>> *_Nullable))restorationHandler;
26
26
27
+ + (void )onOpenURL : (nonnull NSURL *)url NS_SWIFT_NAME(onOpenURL(url:));
28
+
27
29
@end
Original file line number Diff line number Diff line change 15
15
#import " RCTLinkingPlugins.h"
16
16
17
17
static NSString *const kOpenURLNotification = @" RCTOpenURLNotification" ;
18
+ static NSURL *initialURL = nil ;
18
19
19
20
static void postNotificationWithURL (NSURL *URL, id sender)
20
21
{
@@ -81,6 +82,16 @@ + (BOOL)application:(UIApplication *)application
81
82
return YES ;
82
83
}
83
84
85
+
86
+ + (void )onOpenURL : (NSURL *)url
87
+ {
88
+ if (initialURL == nil ) {
89
+ initialURL = url;
90
+ } else {
91
+ postNotificationWithURL (url, self);
92
+ }
93
+ }
94
+
84
95
- (void )handleOpenURLNotification : (NSNotification *)notification
85
96
{
86
97
[self sendEventWithName: @" url" body: notification.userInfo];
@@ -153,6 +164,7 @@ - (void)handleOpenURLNotification:(NSNotification *)notification
153
164
154
165
RCT_EXPORT_METHOD (getInitialURL : (RCTPromiseResolveBlock)resolve reject : (__unused RCTPromiseRejectBlock)reject)
155
166
{
167
+ #if !TARGET_OS_VISION
156
168
NSURL *initialURL = nil ;
157
169
if (self.bridge .launchOptions [UIApplicationLaunchOptionsURLKey]) {
158
170
initialURL = self.bridge .launchOptions [UIApplicationLaunchOptionsURLKey];
@@ -163,6 +175,8 @@ - (void)handleOpenURLNotification:(NSNotification *)notification
163
175
initialURL = ((NSUserActivity *)userActivityDictionary[@" UIApplicationLaunchOptionsUserActivityKey" ]).webpageURL ;
164
176
}
165
177
}
178
+ #endif
179
+ // React Native visionOS uses static property to retrieve initialURL.
166
180
resolve (RCTNullIfNil (initialURL.absoluteString ));
167
181
}
168
182
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import SwiftUI
20
20
public struct RCTMainWindow : Scene {
21
21
var moduleName : String
22
22
var initialProps : RCTRootViewRepresentable . InitialPropsType
23
+ var onOpenURLCallback : ( ( URL ) -> ( ) ) ?
23
24
24
25
public init ( moduleName: String , initialProps: RCTRootViewRepresentable . InitialPropsType = nil ) {
25
26
self . moduleName = moduleName
@@ -30,10 +31,21 @@ public struct RCTMainWindow: Scene {
30
31
WindowGroup {
31
32
RCTRootViewRepresentable ( moduleName: moduleName, initialProps: initialProps)
32
33
. modifier ( WindowHandlingModifier ( ) )
34
+ . onOpenURL ( perform: { url in
35
+ onOpenURLCallback ? ( url)
36
+ } )
33
37
}
34
38
}
35
39
}
36
40
41
+ extension RCTMainWindow {
42
+ public func onOpenURL( perform action: @escaping ( URL ) -> ( ) ) -> some Scene {
43
+ var scene = self
44
+ scene. onOpenURLCallback = action
45
+ return scene
46
+ }
47
+ }
48
+
37
49
/**
38
50
Handles data sharing between React Native and SwiftUI views.
39
51
*/
Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ struct RNTesterApp: App {
11
11
12
12
var body : some Scene {
13
13
RCTMainWindow ( moduleName: " RNTesterApp " )
14
+ . onOpenURL ( perform: { url in
15
+ RCTLinkingManager . onOpenURL ( url: url)
16
+ } )
14
17
15
18
RCTWindow ( id: " SecondWindow " , sceneData: reactContext. getSceneData ( id: " SecondWindow " ) )
16
19
. defaultSize ( CGSize ( width: 400 , height: 700 ) )
Original file line number Diff line number Diff line change 2
2
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
3
<plist version =" 1.0" >
4
4
<dict >
5
+ <key >CFBundleURLTypes </key >
6
+ <array >
7
+ <dict >
8
+ <key >CFBundleTypeRole </key >
9
+ <string >Editor </string >
10
+ <key >CFBundleURLName </key >
11
+ <string >com.reactjs.ios </string >
12
+ <key >CFBundleURLSchemes </key >
13
+ <array >
14
+ <string >rntester </string >
15
+ </array >
16
+ </dict >
17
+ </array >
5
18
<key >UIApplicationSceneManifest </key >
6
19
<dict >
7
20
<key >UIApplicationPreferredDefaultSceneSessionRole </key >
You can’t perform that action at this time.
0 commit comments