Skip to content

Commit 167eb6e

Browse files
robertyingclaude
andauthored
Offer another app when a document's preview fails on iOS (#1815)
WebKit's Quick Look conversion of a document it can't read, such as a damaged .ppt, fails after the load is committed (didFailNavigation, QuickLookErrorDomain). react-native-webview handled only provisional failures, so File detail never heard of it and showed WebKit's own "This file cannot be previewed" page with nothing to do. The webview patch now reports committed failures through onError, and File detail shows its preview-failed state for them, as for an unreadable PDF. That state now offers the file to another app (share sheet on iOS, Quick Look on the Mac, the chooser on Android, the default app on Windows and Linux) next to Download Again. The patch is native, and 19.1.0's builds are made without it, so the app and runtime versions move to 19.2.0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent c0578d1 commit 167eb6e

13 files changed

Lines changed: 212 additions & 70 deletions

File tree

‎android/app/build.gradle‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ android {
7070
minSdk = rootProject.ext.minSdkVersion
7171
targetSdk = rootProject.ext.targetSdkVersion
7272
versionCode = 9204560
73-
versionName = "19.1.0"
73+
versionName = "19.2.0"
7474
// A release build's number, which is never committed: fastlane's build
7575
// lanes pass -PlearnxBuildNumber=<n> (the Xcode builds get the same n).
7676
def releaseBuild = findProperty("learnxBuildNumber")

‎app.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"displayName": "learnX",
44
"owner": "robertying",
55
"slug": "learnx",
6-
"runtimeVersion": "19.1.0",
6+
"runtimeVersion": "19.2.0",
77
"updates": {
88
"url": "https://ota.tsinghua.app/manifest",
99
"requestHeaders": {

‎ios/learnX.xcodeproj/project.pbxproj‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1001,7 +1001,7 @@
10011001
"$(inherited)",
10021002
);
10031003
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
1004-
MARKETING_VERSION = 19.1.0;
1004+
MARKETING_VERSION = 19.2.0;
10051005
OTHER_LDFLAGS = (
10061006
"$(inherited)",
10071007
"-ObjC",
@@ -1053,7 +1053,7 @@
10531053
"$(inherited)",
10541054
);
10551055
LOCALIZATION_PREFERS_STRING_CATALOGS = YES;
1056-
MARKETING_VERSION = 19.1.0;
1056+
MARKETING_VERSION = 19.2.0;
10571057
OTHER_LDFLAGS = (
10581058
"$(inherited)",
10591059
"-ObjC",
@@ -1374,7 +1374,7 @@
13741374
"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)",
13751375
"$(inherited)",
13761376
);
1377-
MARKETING_VERSION = 19.1.0;
1377+
MARKETING_VERSION = 19.2.0;
13781378
MTL_ENABLE_DEBUG_INFO = YES;
13791379
ONLY_ACTIVE_ARCH = YES;
13801380
OTHER_CFLAGS = (
@@ -1505,7 +1505,7 @@
15051505
"$(TOOLCHAIN_DIR)/usr/lib/swift/$(PLATFORM_NAME)",
15061506
"$(inherited)",
15071507
);
1508-
MARKETING_VERSION = 19.1.0;
1508+
MARKETING_VERSION = 19.2.0;
15091509
MTL_ENABLE_DEBUG_INFO = NO;
15101510
OTHER_CFLAGS = (
15111511
"$(inherited)",

‎ios/learnXTests/Patches/WebViewPatchTests.swift‎

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ import WebKit
44

55
/// What patches/react-native-webview@14.0.1.patch changes on iOS: a JavaScript panel that can't be presented (the
66
/// web view isn't in a window) answers at once (WebKit throws when a panel's completion handler is released without
7-
/// being called, which is what happened when the presentation silently failed), and a page loaded at its top stays
8-
/// below a translucent header until it's scrolled.
7+
/// being called, which is what happened when the presentation silently failed), a page loaded at its top stays
8+
/// below a translucent header until it's scrolled, and a load that fails after it was committed (Quick Look's
9+
/// conversion of a document it can't read) is reported as an error.
910
@MainActor
1011
@Suite struct WebViewPatchTests {
1112
private func webViewDelegate() throws -> WKUIDelegate {
@@ -101,4 +102,44 @@ import WebKit
101102
scrollView.contentOffset = CGPoint(x: 0, y: -50)
102103
#expect(scrollView.contentOffset.y == -50)
103104
}
105+
106+
/// The `onLoadingError` events RNCWebViewImpl sends, as React Native's direct event block.
107+
private func loadingErrors(of impl: UIView) -> () -> [[String: Any]] {
108+
var events: [[String: Any]] = []
109+
let block: @convention(block) ([AnyHashable: Any]?) -> Void = { body in
110+
events.append((body as? [String: Any]) ?? [:])
111+
}
112+
impl.setValue(block, forKey: "onLoadingError")
113+
return { events }
114+
}
115+
116+
@Test func committedLoadThatFailsIsAnError() async throws {
117+
let (impl, webView, window) = try await webViewInWindow()
118+
defer { impl.removeFromSuperview() }
119+
_ = window
120+
let events = loadingErrors(of: impl)
121+
let delegate = try #require(impl as? WKNavigationDelegate)
122+
123+
delegate.webView?(
124+
webView, didFail: nil, withError: NSError(domain: "QuickLookErrorDomain", code: 912)
125+
)
126+
let event = try #require(events().first)
127+
#expect(event["domain"] as? String == "QuickLookErrorDomain")
128+
#expect(event["code"] as? Int == 912)
129+
#expect(event["didFailProvisionalNavigation"] as? Bool == false)
130+
}
131+
132+
@Test func cancelledCommittedLoadIsNotAnError() async throws {
133+
let (impl, webView, window) = try await webViewInWindow()
134+
defer { impl.removeFromSuperview() }
135+
_ = window
136+
let events = loadingErrors(of: impl)
137+
let delegate = try #require(impl as? WKNavigationDelegate)
138+
139+
delegate.webView?(
140+
webView, didFail: nil, withError: NSError(domain: NSURLErrorDomain, code: NSURLErrorCancelled)
141+
)
142+
delegate.webView?(webView, didFail: nil, withError: NSError(domain: "WebKitErrorDomain", code: 102))
143+
#expect(events().isEmpty)
144+
}
104145
}

‎ota-fingerprint.json‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
2-
"runtimeVersion": "19.1.0",
3-
"ios": "775057c2b826afaf8092b025eca12940361b0f60",
4-
"android": "746d8fc0115f07b43bda0345515784256f693173",
2+
"runtimeVersion": "19.2.0",
3+
"ios": "78a5f522e91d9df4c8f2aa0b2e1a072ab359806d",
4+
"android": "26ad9b5116e48c2984715157cadfb3ab4cacb761",
55
"sources": {
66
"ios": {
77
"file src/data/storeVersions.json": "46529c4a96147c7b238c1fb8a460668086e2e2d6",
@@ -17,7 +17,7 @@
1717
"dir modules/spotlight/ios": "0c556f33bb595592925a631602f7e4289090cff0",
1818
"dir modules/toast/ios": "aa4d01b8183803ed5c95a7a366b90a82fedabb94",
1919
"dir modules/windows/ios": "c308265226d7823bc1f418f935212e856e3322a7",
20-
"dir patches": "477ebabcc3aafbb474263e9c0a6c4c7e7f20de3a",
20+
"dir patches": "4b704c3173cb5c4cf55cd2d08d13d4c25144a392",
2121
"contents expoAutolinkingConfig:ios": "0cee0a0307eba7053ff9cfe2b43568b044844ef9",
2222
"contents rncoreAutolinkingConfig:ios": "25ad6be6ee8c52ea1eb5ad8a248eeec2c8bbfa03",
2323
"package node_modules/@expo/log-box/package.json": "7a829699d9363b31a6e475706b30fe66b2076279",
@@ -74,7 +74,7 @@
7474
"dir modules/perf/android": "21ae1391b2a4c5c8c10d1bd92baf353f56171e1e",
7575
"dir modules/share/android": "69760341fd85cb091ac06c209f12d905b601c4d9",
7676
"dir modules/updater/android": "3d10cfa1cc60224856437bbe1568f6eccba83103",
77-
"dir patches": "477ebabcc3aafbb474263e9c0a6c4c7e7f20de3a",
77+
"dir patches": "4b704c3173cb5c4cf55cd2d08d13d4c25144a392",
7878
"contents expoAutolinkingConfig:android": "472ddec8aad3b5a0babc781bef8086958405f32c",
7979
"contents rncoreAutolinkingConfig:android": "5c033b1243c015a26df72398cc955dec086456b4",
8080
"package node_modules/@expo/log-box/package.json": "7a829699d9363b31a6e475706b30fe66b2076279",

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "learnX",
3-
"version": "19.1.0",
3+
"version": "19.2.0",
44
"private": true,
55
"engines": {
66
"node": ">=26"

‎patches/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,7 @@ Mac Catalyst: leaves the pan gesture alone when KVO already subclassed the scrol
154154
## `react-native-webview`
155155

156156
- iOS: JavaScript alerts present from a view controller that is on screen, or are dismissed (crash); a page loaded at its top stays below a translucent header until scrolled (WebKit fits an image to the width and leaves it at offset 0).
157+
- iOS: a load that fails after it was committed (`didFailNavigation`) reaches `onError` like one that fails before (`didFailProvisionalNavigation`). WebKit's Quick Look conversion fails that way for a document it can't read (`QuickLookErrorDomain`), which otherwise showed WebKit's own error page and never ended the load, so File detail couldn't offer anything better.
157158
- Types: props no longer collapse to `never` ([#3977](https://github.com/react-native-webview/react-native-webview/issues/3977)).
158159

159160
**Drop when:** Fixed upstream.

‎patches/react-native-webview@14.0.1.patch‎

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/apple/RNCWebViewImpl.m b/apple/RNCWebViewImpl.m
2-
index 38904266dc37b006274104f4680778ffbfece369..37f90812d5ce295f70d948dcc5b458b4c39f8ed1 100644
2+
index 38904266dc37b006274104f4680778ffbfece369..879dd5e78647b8bd373aeabbccbd05257a3bdb5b 100644
33
--- a/apple/RNCWebViewImpl.m
44
+++ b/apple/RNCWebViewImpl.m
55
@@ -148,6 +148,8 @@ RCTAutoInsetsProtocol>
@@ -124,7 +124,40 @@ index 38904266dc37b006274104f4680778ffbfece369..37f90812d5ce295f70d948dcc5b458b4
124124
#endif // !TARGET_OS_OSX
125125

126126
/**
127-
@@ -1586,6 +1633,15 @@ didFinishNavigation:(WKNavigation *)navigation
127+
@@ -1498,6 +1545,23 @@ RCTAutoInsetsProtocol>
128+
- (void) webView:(WKWebView *)webView
129+
didFailProvisionalNavigation:(WKNavigation *)navigation
130+
withError:(NSError *)error
131+
+{
132+
+ [self sendLoadingError:error provisional:YES];
133+
+}
134+
+
135+
+/**
136+
+ * A load that failed after it was committed, as WebKit's Quick Look conversion
137+
+ * of a document it can't read does (QuickLookErrorDomain): without this the
138+
+ * view never reports an end to the load.
139+
+ */
140+
+- (void) webView:(WKWebView *)webView
141+
+ didFailNavigation:(WKNavigation *)navigation
142+
+ withError:(NSError *)error
143+
+{
144+
+ [self sendLoadingError:error provisional:NO];
145+
+}
146+
+
147+
+- (void)sendLoadingError:(NSError *)error provisional:(BOOL)provisional
148+
{
149+
if (_onLoadingError) {
150+
if ([error.domain isEqualToString:NSURLErrorDomain] && error.code == NSURLErrorCancelled) {
151+
@@ -1518,7 +1582,7 @@ RCTAutoInsetsProtocol>
152+
153+
NSMutableDictionary<NSString *, id> *event = [self baseEvent];
154+
[event addEntriesFromDictionary:@{
155+
- @"didFailProvisionalNavigation": @YES,
156+
+ @"didFailProvisionalNavigation": @(provisional),
157+
@"domain": error.domain,
158+
@"code": @(error.code),
159+
@"description": error.localizedDescription,
160+
@@ -1586,6 +1650,15 @@ didFinishNavigation:(WKNavigation *)navigation
128161
[self forceIgnoreSilentHardwareSwitch:true];
129162
}
130163

0 commit comments

Comments
 (0)