@onekeyfe/react-native-image-crop-picker 6.7.0-alpha.466 → 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 +109 -110
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,42 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Single photo picker and cropper for OneKey, built on [Nitro Modules](https://nitro.margelo.com/). It replaces `react-native-image-crop-picker` and keeps the part of its API that OneKey uses: `openPicker`, `openCropper`, `clean`, `cleanSingle`, and the `E_*` error codes.
|
|
4
|
-
|
|
5
|
-
Picking never asks for photo library permission:
|
|
1
|
+
<div align="center">
|
|
6
2
|
|
|
7
|
-
|
|
8
|
-
- **Android** picks with the system Photo Picker (`ActivityResultContracts.PickVisualMedia`, which falls back to `ACTION_OPEN_DOCUMENT` on devices without it). The crop gestures come from uCrop `2.2.11-native`'s `UCropView`. Activity results go through the activity's `ActivityResultRegistry`, so no `ActivityEventListener` is needed.
|
|
9
|
-
|
|
10
|
-
- **Web** (browsers, Electron and browser extensions) picks with an `<input type="file">` and crops with a DOM cropper, with no Nitro or native code. Bundlers select it through the `browser` export condition (`lib/module/index.web.js`).
|
|
11
|
-
|
|
12
|
-
All platforms show the same cropper screen, drawn by this package rather than by TOCropViewController, uCrop or a web cropper library. See [Cropper screen](#cropper-screen).
|
|
3
|
+
# @onekeyfe/react-native-image-crop-picker
|
|
13
4
|
|
|
14
|
-
|
|
5
|
+
**Pick one photo and crop it with one API on iOS, Android and the web — without photo-library permission.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@onekeyfe/react-native-image-crop-picker)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
A single-photo picker and cropper for OneKey, replacing the parts of
|
|
17
|
+
`react-native-image-crop-picker` that OneKey uses: `openPicker`, `openCropper`,
|
|
18
|
+
`clean`, `cleanSingle` and the `E_*` error codes. iOS picks with
|
|
19
|
+
`PHPickerViewController`, Android with the system Photo Picker, and the browser
|
|
20
|
+
with a file input, so no platform asks for photo-library permission. The cropper
|
|
21
|
+
is a screen drawn by this package, identical on iOS and Android, with a DOM
|
|
22
|
+
equivalent on the web. Photo saving and its authorization belong to
|
|
23
|
+
`@onekeyfe/react-native-photo-library`; this package exposes no save API.
|
|
24
|
+
|
|
25
|
+
## Features
|
|
26
|
+
|
|
27
|
+
- **No photo-library prompt** — picking grants access only to the selected
|
|
28
|
+
item, so a denied library permission can no longer break the picker.
|
|
29
|
+
- **One shared cropper** — the same header, crop box, dimmed background,
|
|
30
|
+
rotate control and footer on iOS and Android; the same layout on the web with
|
|
31
|
+
zoom and keyboard input for mouse users.
|
|
32
|
+
- **Optional cropping or original bytes** — `cropping: true` returns a JPEG at
|
|
33
|
+
the requested size; `preserveOriginal: true` copies the selected
|
|
34
|
+
representation untouched when cropping is off.
|
|
35
|
+
- **Explicit cleanup** — results live in the module's temporary directory until
|
|
36
|
+
the caller runs `clean()` or `cleanSingle()`.
|
|
37
|
+
- **Typed failures** — every rejection is an `ImageCropPickerError` with a
|
|
38
|
+
stable `E_*` code.
|
|
15
39
|
|
|
16
|
-
##
|
|
40
|
+
## Installation
|
|
17
41
|
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
// Read the selected file before cleaning it.
|
|
21
|
-
await ImageCropPicker.cleanSingle(image.path);
|
|
42
|
+
```sh
|
|
43
|
+
yarn add @onekeyfe/react-native-image-crop-picker react-native-nitro-modules
|
|
22
44
|
```
|
|
23
45
|
|
|
24
|
-
|
|
25
|
-
Compression options are ignored unless cropping is enabled. Originals are limited
|
|
26
|
-
to 64 MiB. Saving and its authorization are provided by the separate
|
|
27
|
-
`@onekeyfe/react-native-photo-library`; this picker exposes neither saving nor
|
|
28
|
-
photo-library permission APIs.
|
|
29
|
-
|
|
30
|
-
## Installation
|
|
46
|
+
Install the native peer packages this package links as well:
|
|
31
47
|
|
|
32
48
|
```sh
|
|
33
|
-
yarn add @onekeyfe/react-native-
|
|
49
|
+
yarn add @onekeyfe/react-native-native-logger
|
|
34
50
|
```
|
|
35
51
|
|
|
36
|
-
To keep existing `react-native-image-crop-picker` imports working, install it
|
|
52
|
+
To keep existing `react-native-image-crop-picker` imports working, install it
|
|
53
|
+
under an npm alias: `react-native-image-crop-picker@npm:@onekeyfe/react-native-image-crop-picker`.
|
|
54
|
+
Install the application's iOS pods and rebuild the native binary; the web entry
|
|
55
|
+
needs no native code.
|
|
37
56
|
|
|
38
|
-
- **iOS**: do not also install the `TOCropViewController` pod. This package
|
|
39
|
-
|
|
57
|
+
- **iOS**: do not also install the `TOCropViewController` pod. This package
|
|
58
|
+
compiles its own copy and duplicate classes clash at link time.
|
|
59
|
+
- **Android**: uCrop is published only to JitPack, so add
|
|
60
|
+
`maven { url "https://www.jitpack.io" }` to the app's `allprojects.repositories`.
|
|
40
61
|
|
|
41
62
|
## Usage
|
|
42
63
|
|
|
@@ -53,7 +74,7 @@ try {
|
|
|
53
74
|
includeBase64: true,
|
|
54
75
|
compressImageQuality: 0.8,
|
|
55
76
|
});
|
|
56
|
-
// image.path is a file:// URI
|
|
77
|
+
// image.path is a file:// URI (blob: URL on the web).
|
|
57
78
|
} catch (error) {
|
|
58
79
|
if (error instanceof ImageCropPickerError && error.code === 'E_PICKER_CANCELLED') {
|
|
59
80
|
return;
|
|
@@ -68,87 +89,65 @@ const cropped = await ImageCropPicker.openCropper({
|
|
|
68
89
|
});
|
|
69
90
|
```
|
|
70
91
|
|
|
71
|
-
`openCropper` accepts `file://` URIs, absolute paths, `http(s)://` URLs,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
`
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
##
|
|
123
|
-
|
|
124
|
-
-
|
|
125
|
-
-
|
|
126
|
-
-
|
|
127
|
-
-
|
|
128
|
-
- On the web, results are JPEG blobs: `path` is a `blob:` URL, and `clean()` / `cleanSingle()` revoke the URLs this package created. The default quality is 0.8, as on iOS. `cropRect` is in the coordinates of the image as the browser decodes it (EXIF orientation applied), rotated with the crop. With `preserveOriginal`, `mime` comes from the file's leading bytes rather than `File.type`, and a file in an unrecognized format rejects `E_NO_IMAGE_DATA_FOUND`. `http(s)` images for `openCropper` must allow CORS, or the crop cannot be read back and rejects `E_CANNOT_SAVE_IMAGE`. `freeStyleCropEnabled` is not implemented on the web; the crop box keeps the `width` / `height` ratio. With `cropperCircleOverlay` the crop box is 1:1 with no frame or grid on every platform, whatever the image or target ratio.
|
|
129
|
-
- Only one picker or cropper can be open at a time. A second call rejects with `E_PICKER_IN_PROGRESS`.
|
|
130
|
-
- On iOS, cancelling the cropper that `openPicker` opened returns to the photo picker. On Android and the web it rejects with `E_PICKER_CANCELLED`, as does dismissing the web file chooser.
|
|
131
|
-
- On Android the cropper keeps the calling activity's requested orientation, so a portrait-only app gets a portrait-only cropper.
|
|
132
|
-
|
|
133
|
-
## Not supported
|
|
134
|
-
|
|
135
|
-
Multiple selection, video, the camera and `includeExif` are not implemented. `mediaType`, `forceJpg` and `sortOrder` are accepted for source compatibility and ignored.
|
|
136
|
-
|
|
137
|
-
## Error codes
|
|
138
|
-
|
|
139
|
-
| Code | Meaning |
|
|
140
|
-
| --- | --- |
|
|
141
|
-
| `E_PICKER_CANCELLED` | The user closed the picker or the cropper. |
|
|
142
|
-
| `E_PICKER_IN_PROGRESS` | Another picker or cropper is still open. |
|
|
143
|
-
| `E_ACTIVITY_DOES_NOT_EXIST` | Android: no current activity. |
|
|
144
|
-
| `E_FAILED_TO_SHOW_PICKER` | The picker or cropper could not be presented. |
|
|
145
|
-
| `E_NO_IMAGE_DATA_FOUND` | The selected item could not be read as an image. |
|
|
146
|
-
| `E_CROPPER_IMAGE_NOT_FOUND` | `openCropper` could not load `path`. |
|
|
147
|
-
| `E_CANNOT_SAVE_IMAGE` | The result could not be written. |
|
|
148
|
-
| `E_LOW_MEMORY_ERROR` | Android: out of memory while processing. |
|
|
149
|
-
| `E_ERROR_WHILE_CLEANING_FILES` | `clean` or `cleanSingle` failed. |
|
|
150
|
-
| `E_UNKNOWN` | Any other native error. |
|
|
92
|
+
`openCropper` accepts `file://` URIs, absolute paths, `http(s)://` URLs,
|
|
93
|
+
`data:` URIs and, on Android, `content://` URIs. Read or save a result before
|
|
94
|
+
cleaning it; only one picker or cropper can be open per app.
|
|
95
|
+
|
|
96
|
+
## API
|
|
97
|
+
|
|
98
|
+
| Method | Result | Platforms | Description |
|
|
99
|
+
| --- | --- | :-: | --- |
|
|
100
|
+
| `openPicker(options?)` | `Promise<Image>` | iOS, Android, Web | Picks one photo, optionally connected to the cropper. |
|
|
101
|
+
| `openCropper({ path, ...options })` | `Promise<Image>` | iOS, Android, Web | Crops an existing image and returns a JPEG. |
|
|
102
|
+
| `clean()` | `Promise<void>` | iOS, Android, Web | Deletes every file this module wrote. |
|
|
103
|
+
| `cleanSingle(path)` | `Promise<void>` | iOS, Android, Web | Deletes one file returned by this module. |
|
|
104
|
+
| `ImageCropPickerError` | `Error` subclass with `code` | iOS, Android, Web | Rejection type for all operations. |
|
|
105
|
+
| `Image` | `{ path, size, width, height, mime, data?, cropRect?, filename? }` | iOS, Android, Web | Pick/crop result; `data` is base64 without a `data:` prefix. |
|
|
106
|
+
|
|
107
|
+
Cropping uses `width`/`height` as both the target size and the aspect ratio;
|
|
108
|
+
`freeStyleCropEnabled` lets the box keep its own ratio and fit inside that size.
|
|
109
|
+
`compressImageMaxWidth`, `compressImageMaxHeight` and `compressImageQuality`
|
|
110
|
+
apply after cropping. `cropperAppearance`, `cropperToolbarTitle`,
|
|
111
|
+
`cropperChooseText`, `cropperCancelText`, `cropperRotateButtonsHidden` and
|
|
112
|
+
`showCropGuidelines` style the cropper. See
|
|
113
|
+
[`src/ReactNativeImageCropPicker.nitro.ts`](src/ReactNativeImageCropPicker.nitro.ts)
|
|
114
|
+
for every option and [`src/shared.ts`](src/shared.ts) for the full error-code list.
|
|
115
|
+
|
|
116
|
+
## Platform support
|
|
117
|
+
|
|
118
|
+
| Capability | iOS | Android | Web |
|
|
119
|
+
| --- | :-: | :-: | :-: |
|
|
120
|
+
| Pick one photo without library permission | ✅ PHPicker | ✅ Photo Picker | ✅ file input |
|
|
121
|
+
| Interactive cropper | ✅ | ✅ | ✅ DOM |
|
|
122
|
+
| `preserveOriginal` (byte-for-byte copy) | ✅ | ✅ | ✅ |
|
|
123
|
+
| Native Nitro module | ✅ | ✅ | — |
|
|
124
|
+
| `freeStyleCropEnabled` | ✅ | ✅ | — |
|
|
125
|
+
|
|
126
|
+
## Caveats
|
|
127
|
+
|
|
128
|
+
> [!NOTE]
|
|
129
|
+
> Cancelling the cropper that `openPicker` opened returns to the photo picker on
|
|
130
|
+
> iOS but rejects with `E_PICKER_CANCELLED` on Android and the web. A second
|
|
131
|
+
> picker or cropper while one is open rejects with `E_PICKER_IN_PROGRESS`.
|
|
132
|
+
|
|
133
|
+
> [!WARNING]
|
|
134
|
+
> On the web, `freeStyleCropEnabled` is not implemented, `path` is a `blob:` URL
|
|
135
|
+
> that `clean()` revokes, and `http(s)` sources for `openCropper` must allow CORS
|
|
136
|
+
> or the crop rejects with `E_CANNOT_SAVE_IMAGE`.
|
|
137
|
+
|
|
138
|
+
> [!IMPORTANT]
|
|
139
|
+
> A picker result proves access to that one item only — never photo-library
|
|
140
|
+
> authorization. Results are temporary files owned by the caller; do not clean a
|
|
141
|
+
> file while a scan or save still reads it.
|
|
142
|
+
|
|
143
|
+
## References
|
|
144
|
+
|
|
145
|
+
- [Package spec](docs/SPEC.md)
|
|
146
|
+
- [Native interface](src/ReactNativeImageCropPicker.nitro.ts)
|
|
147
|
+
- [Example page](../../example/react-native/pages/ImageCropPickerTestPage.tsx)
|
|
148
|
+
- [Changelog](../../CHANGELOG.md)
|
|
151
149
|
|
|
152
150
|
## License
|
|
153
151
|
|
|
154
|
-
MIT. The vendored TOCropViewController in
|
|
152
|
+
MIT. See [LICENSE](LICENSE). The vendored TOCropViewController in
|
|
153
|
+
`ios/TOCropViewController` is MIT licensed by Tim Oliver; see its `LICENSE`.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-image-crop-picker",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.8.0-10",
|
|
4
4
|
"description": "Single photo picker and cropper Nitro module for OneKey, replacing react-native-image-crop-picker",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"react-native": "./lib/module/index.js",
|
|
@@ -97,6 +97,7 @@
|
|
|
97
97
|
"typescript": "^5.9.2"
|
|
98
98
|
},
|
|
99
99
|
"peerDependencies": {
|
|
100
|
+
"@onekeyfe/react-native-native-logger": "*",
|
|
100
101
|
"react": "*",
|
|
101
102
|
"react-native": "*",
|
|
102
103
|
"react-native-nitro-modules": "0.37.0"
|