-
-
Notifications
You must be signed in to change notification settings - Fork 465
Expand file tree
/
Copy pathindex.ts
More file actions
86 lines (81 loc) · 2.86 KB
/
index.ts
File metadata and controls
86 lines (81 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import { NativeDocumentViewer } from './spec/NativeDocumentViewer'
/**
* iOS only. Configure the presentation style of the picker.
* */
export type PresentationStyle =
| 'fullScreen'
| 'pageSheet'
| 'formSheet'
| 'overFullScreen'
| undefined
/*
* really, PresentationStyle shouldn't be here and we should just use ModalPropsIOS['presentationStyle']>
* but I'm not sure how to get that working with TypeDoc producing a nice output so we duplicate it here
* */
export type BaseOptions = {
/**
* Android only: The type of permission to grant to the receiving app that will open the document.
* This only has an effect if you're viewing a file that lives in the app's sandboxed storage.
*/
grantPermissions?: 'read' | 'write'
/**
* iOS only: The title to display in the header of the document viewer.
* @default the file name.
*/
headerTitle?: string
/**
* Optional, but strongly recommended: the mimetype of the document. This helps the Android OS to find the right app(s) to open the document.
*/
mimeType?: string
/**
* iOS only - Controls how the picker is presented, e.g. on an iPad you may want to present it fullscreen.
* @default `pageSheet`.
* */
presentationStyle?: PresentationStyle
/**
* Android only - Optional, only provide a value if `viewDocument` rejects with `IllegalArgumentException`. Represents the unique identifier for an Android application.
* @default application package name, which usually is the same as the application id.
*/
androidApplicationId?: string
}
/**
* BaseOptions with the uri of the document to view
* */
export type OptionsViewUri = BaseOptions & {
/**
* The uri of the document to view
* */
uri: string
}
/**
* BaseOptions with the bookmark data from the DocumentPicker module. Obtain the bookmark using the "open" mode, with `requestLongTermAccess` flag set to true.
*
* A bookmark enables long-term access to a file.
*/
export type OptionsViewBookmark = BaseOptions & {
/**
* bookmark data from the DocumentPicker module. Obtain it using the "open" mode, with `requestLongTermAccess` flag set to true.
*
* A bookmark allows a long-term permission to access a file.
*/
bookmark: string
}
/**
* options for viewing a document
*
* If you're trying to open a file that you have long-term permission to access, you should use the `bookmark` option (provided by the DocumentPicker module).
*
* */
export type ViewDocumentOptions = OptionsViewBookmark | OptionsViewUri
export function viewDocument(data: ViewDocumentOptions): Promise<null> {
const bookmarkOrUri = 'bookmark' in data ? data.bookmark : data.uri
return NativeDocumentViewer.viewDocument(
bookmarkOrUri,
data?.grantPermissions ?? 'read',
data?.mimeType,
data?.headerTitle,
data?.androidApplicationId,
data?.presentationStyle,
)
}
export { errorCodes, isErrorWithCode } from './errors'