Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/ios-scene-warm-links.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@callstack/react-native-brownfield': patch
---

Deliver deep links and universal links that arrive while the app is running in iOS hosts that declare `UISceneConfigurations`. React Native 0.88 ignores `RCTLinkingManager`'s app delegate entry points in such apps, so the `Linking` `url` event never fired.
32 changes: 0 additions & 32 deletions apps/AppleApp/Brownfield Apple App.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -632,8 +632,6 @@
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
Expand Down Expand Up @@ -679,8 +677,6 @@
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
Expand Down Expand Up @@ -726,8 +722,6 @@
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
Expand Down Expand Up @@ -773,8 +767,6 @@
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
Expand Down Expand Up @@ -938,8 +930,6 @@
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
Expand Down Expand Up @@ -985,8 +975,6 @@
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
Expand Down Expand Up @@ -1032,8 +1020,6 @@
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
Expand Down Expand Up @@ -1079,8 +1065,6 @@
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
Expand Down Expand Up @@ -1126,8 +1110,6 @@
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
Expand Down Expand Up @@ -1173,8 +1155,6 @@
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
Expand Down Expand Up @@ -1338,8 +1318,6 @@
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
Expand Down Expand Up @@ -1385,8 +1363,6 @@
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
Expand Down Expand Up @@ -1432,8 +1408,6 @@
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
Expand Down Expand Up @@ -1479,8 +1453,6 @@
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
Expand Down Expand Up @@ -1526,8 +1498,6 @@
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
Expand Down Expand Up @@ -1573,8 +1543,6 @@
ENABLE_USER_SELECTED_FILES = readonly;
GENERATE_INFOPLIST_FILE = YES;
INFOPLIST_FILE = "Brownfield-Apple-App-Info.plist";
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSceneManifest_Generation[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphoneos*]" = YES;
"INFOPLIST_KEY_UIApplicationSupportsIndirectInputEvents[sdk=iphonesimulator*]" = YES;
"INFOPLIST_KEY_UILaunchScreen_Generation[sdk=iphoneos*]" = YES;
Expand Down
10 changes: 10 additions & 0 deletions apps/AppleApp/Brownfield Apple App/BrownfieldAppleApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,16 @@ struct BrownfieldAppleApp: App {
var body: some Scene {
WindowGroup {
RootContentView(appDelegate: appDelegate)
.onOpenURL { url in
_ = ReactNativeBrownfield.shared.application(UIApplication.shared, open: url)
}
.onContinueUserActivity(NSUserActivityTypeBrowsingWeb) { userActivity in
_ = ReactNativeBrownfield.shared.application(
UIApplication.shared,
continue: userActivity,
restorationHandler: { _ in }
)
}
}
}
}
Expand Down
29 changes: 28 additions & 1 deletion apps/AppleApp/Brownfield-Apple-App-Info.plist
Original file line number Diff line number Diff line change
@@ -1,5 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict/>
<dict>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.callstack.brownfield.ios.example</string>
<key>CFBundleURLSchemes</key>
<array>
<string>brownfield-apple-app</string>
</array>
</dict>
</array>
<key>UIApplicationSceneManifest</key>
<dict>
<key>UIApplicationSupportsMultipleScenes</key>
<false/>
<key>UISceneConfigurations</key>
<dict>
<key>UIWindowSceneSessionRoleApplication</key>
<array>
<dict>
<key>UISceneConfigurationName</key>
<string>Default Configuration</string>
</dict>
</array>
</dict>
</dict>
</dict>
</plist>
40 changes: 39 additions & 1 deletion apps/brownfield-example-shared-tests/e2e/appleAppDetoxUtils.cjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const { device, element, by, expect: detoxExpect } = require('detox');
const { execFileSync } = require('node:child_process');
const { device, element, by, system, expect: detoxExpect } = require('detox');
const {
brownfieldE2ETestIds: ids,
} = require('@callstack/brownfield-example-shared-tests/e2e/e2eTestIds');
Expand Down Expand Up @@ -222,12 +223,49 @@ async function sendPostMessageToNativeAndWaitForToast() {
);
}

/**
* Open `url` in the running app the way the system does, so it arrives through the
* scene (`scene(_:openURLContexts:)`) rather than a call Detox makes on the app delegate.
* The simulator may ask before handing a custom-scheme URL to an app; accept that prompt
* when it shows up.
*/
async function openURLThroughSystem(url) {
execFileSync('xcrun', ['simctl', 'openurl', device.id, url]);
await acceptOpenURLPromptIfShown();
}

async function acceptOpenURLPromptIfShown() {
const openButton = by.system.label('Open');
const deadline = Date.now() + DETOX_TIMING.OPEN_URL_PROMPT_TIMEOUT_MS;
let lastError;
while (Date.now() < deadline) {
try {
await system.element(openButton).tap();
return;
} catch (error) {
lastError = error;
await new Promise((resolve) =>
setTimeout(resolve, DETOX_TIMING.POLL_INTERVAL_MS)
);
}
}
console.warn(
`[AppleApp] No "Open" prompt accepted after opening a URL: ${lastError?.message ?? 'no attempt made'}`
);
}

async function waitForExploreTabExpo() {
await waitForExpoMatcher(by.text('Expo documentation'));
}

module.exports = {
detoxLaunchArgs,
waitForAppleAppReady,
openReactNativeVanilla,
openReactNativeExpo,
openHomeTabExpo,
openPostMessageTabExpo,
openURLThroughSystem,
waitForExploreTabExpo,
sendPostMessageToNativeAndWaitForToast,
};
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const {
waitForAppleAppReady,
openHomeTabExpo,
openPostMessageTabExpo,
openURLThroughSystem,
waitForExploreTabExpo,
sendPostMessageToNativeAndWaitForToast,
} = require('@callstack/brownfield-example-shared-tests/e2e/appleAppDetoxUtils');

Expand All @@ -26,6 +28,12 @@ describe('Brownfield (AppleApp — Expo)', () => {
await openHomeTabExpo();
});

it('routes a deep link that arrives while the app is running', async () => {
await openHomeTabExpo();
await openURLThroughSystem('brownfield-apple-app://explore');
await waitForExploreTabExpo();
});

it('shows a native toast when Expo RN sends postMessage', async () => {
await openPostMessageTabExpo();
await sendPostMessageToNativeAndWaitForToast();
Expand Down
3 changes: 3 additions & 0 deletions apps/brownfield-example-shared-tests/e2e/detoxTiming.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ const DETOX_TIMING = {
/** Timeout for the visibility of toasts. */
TOAST_VISIBILITY_TIMEOUT_MS: 60_000,

/** How long to wait for the system "Open in ...?" prompt after opening a URL. */
OPEN_URL_PROMPT_TIMEOUT_MS: 5_000,

/** Timeout for the entire E2E test suite (detox + Jest + Maestro). */
TEST_TIMEOUT_MS: 720_000,
};
Expand Down
47 changes: 47 additions & 0 deletions packages/react-native-brownfield/ios/BrownfieldLinking.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import UIKit
internal import React

enum BrownfieldLinking {
private static let openURLNotification = Notification.Name("RCTOpenURLNotification")

static func open(
_ app: UIApplication,
url: URL,
options: [UIApplication.OpenURLOptionsKey: Any]
) -> Bool {
if RCTLinkingManager.application(app, open: url, options: options) {
return true
}
postOpenURLNotification(url)
return true
}

static func continueUserActivity(
_ application: UIApplication,
userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
) -> Bool {
if RCTLinkingManager.application(
application,
continue: userActivity,
restorationHandler: restorationHandler
) {
return true
}
guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL
else {
return false
}
postOpenURLNotification(url)
return true
}

private static func postOpenURLNotification(_ url: URL) {
NotificationCenter.default.post(
name: openURLNotification,
object: nil,
userInfo: ["url": url.absoluteString]
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ final class ExpoHostRuntime {
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
return (expoDelegate?.application(app, open: url, options: options) ?? false) || RCTLinkingManager.application(app, open: url, options: options)
return (expoDelegate?.application(app, open: url, options: options) ?? false) || BrownfieldLinking.open(app, url: url, options: options)
}

// Universal Links; base implementation courtesy of Expo, licensed under the MIT License - changes were made to call the method on expo delegate - https://github.com/expo/expo/blob/main/apps/bare-expo/ios/AppDelegate.swift
Expand All @@ -167,7 +167,7 @@ final class ExpoHostRuntime {
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
) -> Bool {
let result = RCTLinkingManager.application(application, continue: userActivity, restorationHandler: restorationHandler)
let result = BrownfieldLinking.continueUserActivity(application, userActivity: userActivity, restorationHandler: restorationHandler)
return (expoDelegate?.application(application, continue: userActivity, restorationHandler: restorationHandler) ?? false) || result
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,15 +175,15 @@ final class ReactNativeHostRuntime {
open url: URL,
options: [UIApplication.OpenURLOptionsKey: Any] = [:]
) -> Bool {
return RCTLinkingManager.application(app, open: url, options: options)
return BrownfieldLinking.open(app, url: url, options: options)
}

public func application(
_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void
) -> Bool {
return RCTLinkingManager.application(application, continue: userActivity, restorationHandler: restorationHandler)
return BrownfieldLinking.continueUserActivity(application, userActivity: userActivity, restorationHandler: restorationHandler)
}

/**
Expand Down
Loading