@onekeyfe/react-native-photo-library 6.7.0-alpha.475 → 6.8.0-10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +89 -52
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,21 +1,61 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# @onekeyfe/react-native-photo-library
|
|
2
4
|
|
|
3
|
-
|
|
5
|
+
**Add-only photo saving for OneKey apps, without whole-library read access.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@onekeyfe/react-native-photo-library)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
Saves a local image into the system photo library through a minimal, add-only
|
|
16
|
+
surface. iOS requests Photos `.addOnly` authorization, Android 10+ saves through
|
|
17
|
+
MediaStore, and the legacy write permission is capped at API 28 for Android 8–9.
|
|
18
|
+
The package does not read back assets, request whole-library access, or provide
|
|
19
|
+
picking, cropping or deletion.
|
|
20
|
+
|
|
21
|
+
## Features
|
|
22
|
+
|
|
23
|
+
- **Add-only by design** — no `NSPhotoLibraryUsageDescription` and no asset
|
|
24
|
+
read-back; the module cannot browse the library.
|
|
25
|
+
- **Explicit permission flow** — check without prompting, request from a user
|
|
26
|
+
action, then save; each step is a separate call.
|
|
27
|
+
- **Bounded input** — local images only, up to 64 MiB, kept in caller ownership
|
|
28
|
+
until the save settles.
|
|
29
|
+
- **Typed failures** — `PhotoLibraryError` with stable codes for permission,
|
|
30
|
+
input, activity and save failures.
|
|
31
|
+
- **Lazy native object** — importing the wrapper performs no permission request
|
|
32
|
+
and no file I/O.
|
|
33
|
+
|
|
34
|
+
## Installation
|
|
35
|
+
|
|
36
|
+
```sh
|
|
37
|
+
yarn add @onekeyfe/react-native-photo-library
|
|
38
|
+
```
|
|
4
39
|
|
|
5
|
-
|
|
40
|
+
Install the native peer packages this package links as well:
|
|
6
41
|
|
|
7
42
|
```sh
|
|
8
|
-
yarn add @onekeyfe/react-native-
|
|
43
|
+
yarn add @onekeyfe/react-native-native-logger
|
|
9
44
|
```
|
|
10
45
|
|
|
11
|
-
Install iOS pods and rebuild the native application.
|
|
12
|
-
implementation.
|
|
13
|
-
importing the JavaScript wrapper performs no permission request or file I/O.
|
|
46
|
+
Install the app's iOS pods and rebuild the native application. The package has no
|
|
47
|
+
Web implementation.
|
|
14
48
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
49
|
+
### iOS
|
|
50
|
+
|
|
51
|
+
Add an application-specific `NSPhotoLibraryAddUsageDescription` to `Info.plist`.
|
|
52
|
+
Saving uses `.addOnly` authorization, so `NSPhotoLibraryUsageDescription` is not
|
|
53
|
+
required.
|
|
54
|
+
|
|
55
|
+
### Android
|
|
56
|
+
|
|
57
|
+
Android 10+ saves with MediaStore and needs no storage permission. For Android 8–9
|
|
58
|
+
only, the application declares:
|
|
19
59
|
|
|
20
60
|
```xml
|
|
21
61
|
<uses-permission
|
|
@@ -23,10 +63,9 @@ For Android 8–9 only, the application declares:
|
|
|
23
63
|
android:maxSdkVersion="28" />
|
|
24
64
|
```
|
|
25
65
|
|
|
26
|
-
Android 10+ saves with MediaStore and does not require this legacy permission.
|
|
27
66
|
The application owns these declarations and the user-facing explanation.
|
|
28
67
|
|
|
29
|
-
##
|
|
68
|
+
## Usage
|
|
30
69
|
|
|
31
70
|
```ts
|
|
32
71
|
import PhotoLibrary from '@onekeyfe/react-native-photo-library';
|
|
@@ -38,35 +77,19 @@ if (permission.status === 'granted') {
|
|
|
38
77
|
}
|
|
39
78
|
```
|
|
40
79
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
of at most 64 MiB. Keep the source until completion. General file IO remains in
|
|
44
|
-
RNFS; use the separate OneKey picker for user selection and cropping.
|
|
45
|
-
|
|
46
|
-
iOS uses Photos `.addOnly`; keep `NSPhotoLibraryAddUsageDescription` in the App.
|
|
47
|
-
Android 10+ uses MediaStore with no storage permission. Android 8-9 requires App
|
|
48
|
-
`WRITE_EXTERNAL_STORAGE` capped at `maxSdkVersion=28`; request it only on Save.
|
|
49
|
-
iOS and Android 10+ do not request whole-library read authorization. On Android
|
|
50
|
-
8-9, granting the legacy write permission also implicitly grants storage read
|
|
51
|
-
access, and the system prompt describes access to photos, media and files.
|
|
52
|
-
Permanent denial is returned as `{status: 'denied', canAskAgain: false}`.
|
|
53
|
-
`PhotoLibraryError.code` identifies permission, missing input,
|
|
54
|
-
activity/concurrency and save failures.
|
|
55
|
-
|
|
56
|
-
## API and failure handling
|
|
80
|
+
Pass an absolute local path or `file://` URI and keep the source file in place
|
|
81
|
+
until the promise settles. Saving runs serially on a native background queue.
|
|
57
82
|
|
|
58
|
-
|
|
83
|
+
## API
|
|
59
84
|
|
|
60
|
-
| Method | Result
|
|
61
|
-
| --- | --- |
|
|
62
|
-
| `getSavePermission()` | `Promise<PhotoSavePermission
|
|
63
|
-
| `requestSavePermission()` | `Promise<PhotoSavePermission
|
|
64
|
-
| `saveToLibrary(path)` | `Promise<void
|
|
85
|
+
| Method | Result | Platforms | Description |
|
|
86
|
+
| --- | --- | :-: | --- |
|
|
87
|
+
| `getSavePermission()` | `Promise<PhotoSavePermission>` | iOS, Android | Checks authorization without prompting. |
|
|
88
|
+
| `requestSavePermission()` | `Promise<PhotoSavePermission>` | iOS, Android | Requests authorization; call from a foreground user action. |
|
|
89
|
+
| `saveToLibrary(path)` | `Promise<void>` | iOS, Android | Saves the local image; never requests permission or deletes the source. |
|
|
65
90
|
|
|
66
|
-
`PhotoSavePermission` contains `status` (`granted`, `denied`,
|
|
67
|
-
|
|
68
|
-
do not retry a permanently denied request in a loop. Overlapping Android
|
|
69
|
-
permission requests reject rather than sharing an activity result.
|
|
91
|
+
`PhotoSavePermission` contains `status` (`granted`, `denied`, `undetermined`) and
|
|
92
|
+
`canAskAgain`. Failures reject with `PhotoLibraryError`:
|
|
70
93
|
|
|
71
94
|
| `PhotoLibraryError.code` | Meaning |
|
|
72
95
|
| --- | --- |
|
|
@@ -77,23 +100,37 @@ permission requests reject rather than sharing an activity result.
|
|
|
77
100
|
| `E_ACTIVITY_DOES_NOT_EXIST` | No usable activity, or its lifecycle ended. |
|
|
78
101
|
| `E_UNKNOWN` | A failure without a recognized native error code. |
|
|
79
102
|
|
|
80
|
-
|
|
81
|
-
`
|
|
82
|
-
|
|
103
|
+
The default export and the named exports expose the same methods. See
|
|
104
|
+
[`docs/SPEC.md`](docs/SPEC.md) for the full contract, ownership boundaries and
|
|
105
|
+
acceptance evidence.
|
|
106
|
+
|
|
107
|
+
## Platform support
|
|
108
|
+
|
|
109
|
+
| Capability | iOS | Android | Web |
|
|
110
|
+
| --- | :-: | :-: | :-: |
|
|
111
|
+
| Save a local image | ✅ `.addOnly` | ✅ MediaStore | — |
|
|
112
|
+
| Check/request permission | ✅ | ✅ | — |
|
|
113
|
+
| Read library assets | — | — | — |
|
|
114
|
+
| Legacy write permission | — | ✅ API ≤ 28 only | — |
|
|
115
|
+
|
|
116
|
+
## Caveats
|
|
117
|
+
|
|
118
|
+
> [!IMPORTANT]
|
|
119
|
+
> `saveToLibrary()` never requests permission. Run `requestSavePermission()` from
|
|
120
|
+
> an explicit user action first, and do not infer a successful save from a
|
|
121
|
+
> permission result alone.
|
|
83
122
|
|
|
84
|
-
|
|
123
|
+
> [!NOTE]
|
|
124
|
+
> On Android 8–9 the legacy write permission also implies storage read access,
|
|
125
|
+
> and the system prompt describes access to photos, media and files. On Android
|
|
126
|
+
> 10+ and iOS this package never asks for whole-library read authorization.
|
|
85
127
|
|
|
86
|
-
|
|
87
|
-
content URI. Keep the image unchanged until the promise settles. Saving runs
|
|
88
|
-
serially on a native background queue and leaves the source in caller ownership.
|
|
89
|
-
The module does not queue retries, create an application image cache, or provide
|
|
90
|
-
asset selection/deletion APIs. UI/background JS objects initialize independently;
|
|
91
|
-
the application's foreground runtime owns permission actions.
|
|
128
|
+
## References
|
|
92
129
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
130
|
+
- [Package spec](docs/SPEC.md)
|
|
131
|
+
- [npm package](https://www.npmjs.com/package/@onekeyfe/react-native-photo-library)
|
|
132
|
+
- [Changelog](../../CHANGELOG.md)
|
|
96
133
|
|
|
97
134
|
## License
|
|
98
135
|
|
|
99
|
-
MIT
|
|
136
|
+
MIT. See [LICENSE](LICENSE).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-photo-library",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.8.0-10",
|
|
4
4
|
"description": "Add-only photo saving with version-scoped Android write permission",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -92,6 +92,7 @@
|
|
|
92
92
|
"typescript": "^5.9.2"
|
|
93
93
|
},
|
|
94
94
|
"peerDependencies": {
|
|
95
|
+
"@onekeyfe/react-native-native-logger": "*",
|
|
95
96
|
"react": "*",
|
|
96
97
|
"react-native": "*",
|
|
97
98
|
"react-native-nitro-modules": "0.37.0"
|