-
-
Notifications
You must be signed in to change notification settings - Fork 464
Open
Description
When using viewDocument() from @react-native-documents/viewer, if a user dismisses the native popup that shows available apps to open documents, no error is thrown to indicate that the operation was canceled. This makes it impossible to handle the user cancellation scenario in the calling code.
I have searched open and closed issues for this issue.
- I have searched open and closed issues.
I have read and understood the license (link below).
- I have read and understood the license.
Minimal reproducible example
Sharing the code below.
What platform(s) does this occur on?
Android
Did you reproduce on a real device or emulator / simulator?
real device
Steps to reproduce
Code Example
import {viewDocument} from '@react-native-documents/viewer';
import {getMimeType} from '../../models/data/File';
export const fileViewer = async (
fileURI: string,
title?: string,
): Promise<void> => {
try {
if (fileURI) {
const formattedURI = fileURI.startsWith('file://')
? fileURI
: `file://${fileURI}`;
const fileExtension = formattedURI.substring(
formattedURI.lastIndexOf('.') + 1,
);
const mimeType = getMimeType(fileExtension);
await viewDocument({
uri: formattedURI,
grantPermissions: 'read',
headerTitle: title,
presentationStyle: 'fullScreen',
mimeType: mimeType,
});
// This code runs even when user dismisses the popup
console.log('Document opened successfully'); // This shouldn't run on cancellation
}
} catch (error) {
// This catch block is never reached when user cancels
console.log('Error or cancellation:', error);
throw error;
}
};Steps to Reproduce
- Call
viewDocument()with a valid file URI - Wait for the native pop-up to appear showing available apps
- Dismiss/cancel the pop-up instead of selecting an app
- Observe that no error is thrown and the promise resolves successfully
- It should show "OPERATION_CANCELLED" error in the catch function so that we can handle that
If the issue is related to specific file(s), I have linked the files so that others can reproduce exactly what I see.
- I have attached files necessary to reproduce the problem (if applicable).
Stacktrace of the crash (if applicable)
There was no crash.
Your computer environment
System:
OS: macOS 15.4.1
CPU: (10) arm64 Apple M4
Memory: 105.97 MB / 16.00 GB
Shell:
version: "5.9"
path: /bin/zsh
Binaries:
Node:
version: 23.2.0
path: /opt/homebrew/bin/node
Yarn:
version: 1.22.22
path: /opt/homebrew/bin/yarn
npm:
version: 11.1.0
path: /opt/homebrew/bin/npm
Watchman:
version: 2024.11.18.00
path: /opt/homebrew/bin/watchman
Managers:
CocoaPods:
version: 1.15.2
path: /opt/homebrew/bin/pod
SDKs:
iOS SDK:
Platforms:
- DriverKit 24.5
- iOS 18.5
- macOS 15.5
- tvOS 18.5
- visionOS 2.5
- watchOS 11.5
Android SDK:
API Levels:
- "33"
- "34"
- "35"
Build Tools:
- 33.0.1
- 34.0.0
- 35.0.0
- 35.0.0
System Images:
- android-30 | Google APIs ARM 64 v8a
- android-33 | Google APIs ARM 64 v8a
- android-34 | Intel x86_64 Atom
- android-34 | Google APIs ARM 64 v8a
- android-34 | Google Play ARM 64 v8a
- android-VanillaIceCream | Google Play ARM 64 v8a
Android NDK: Not Found
IDEs:
Android Studio: 2024.2 AI-242.23726.103.2422.12816248
Xcode:
version: 16.4/16F6
path: /usr/bin/xcodebuild
Languages:
Java:
version: 17.0.13
path: /usr/bin/javac
Ruby:
version: 2.6.10
path: /usr/bin/ruby
npmPackages:
"@react-native-community/cli":
installed: 15.0.1
wanted: 15.0.1
react:
installed: 18.3.1
wanted: 18.3.1
react-native:
installed: 0.76.8
wanted: 0.76.9
react-native-macos: Not Found
npmGlobalPackages:
"*react-native*": Not Found
Android:
hermesEnabled: true
newArchEnabled: false
iOS:
hermesEnabled: true
newArchEnabled: false
Metadata
Metadata
Assignees
Labels
No labels