@onekeyfe/react-native-image-crop-picker 6.7.0-45 → 6.7.0-47

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.
Files changed (2) hide show
  1. package/README.md +109 -110
  2. package/package.json +2 -1
package/README.md CHANGED
@@ -1,42 +1,63 @@
1
- # @onekeyfe/react-native-image-crop-picker
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
- - **iOS** picks with `PHPickerViewController`, which runs out of process. `react-native-image-crop-picker` requested full photo library access first. Once a user denied it, iOS never showed the prompt again and every later `openPicker` call failed silently (OK-48227). The crop gestures come from a vendored TOCropViewController 3.2.0 `TOCropView`, with the OK-51551 rotation fix that upstream still lacks.
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
- The behavioral contract and pending acceptance cases are in [docs/SPEC.md](docs/SPEC.md).
5
+ **Pick one photo and crop it with one API on iOS, Android and the web — without photo-library permission.**
6
+
7
+ [![npm](https://img.shields.io/npm/v/%40onekeyfe%2Freact-native-image-crop-picker?label=npm&color=4D6BFE)](https://www.npmjs.com/package/@onekeyfe/react-native-image-crop-picker)
8
+ [![license](https://img.shields.io/npm/l/%40onekeyfe%2Freact-native-image-crop-picker?label=license&color=4D6BFE)](LICENSE)
9
+ ![iOS](https://img.shields.io/badge/iOS-000000?logo=apple&logoColor=white)
10
+ ![Android](https://img.shields.io/badge/Android-3DDC84?logo=android&logoColor=white)
11
+ ![Web](https://img.shields.io/badge/Web-4285F4?logo=googlechrome&logoColor=white)
12
+ ![Nitro Modules](https://img.shields.io/badge/Nitro_Modules-4D6BFE)
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
- ## Original selection
40
+ ## Installation
17
41
 
18
- ```ts
19
- const image = await ImageCropPicker.openPicker({ preserveOriginal: true });
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
- Original selection preserves the selected representation without JPEG conversion.
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-image-crop-picker react-native-nitro-modules
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 under that name with an npm alias instead: `react-native-image-crop-picker@npm:@onekeyfe/react-native-image-crop-picker`.
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 compiles its own copy, and the duplicate classes would clash at link time.
39
- - **Android**: uCrop is only published to JitPack. Add `maven { url "https://www.jitpack.io" }` to the app's `allprojects.repositories`.
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; image.data is base64 without a data: prefix.
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, `data:` URIs and, on Android, `content://` URIs.
72
-
73
- ## Cropper screen
74
-
75
- The cropper is a full-screen page with the same layout and metrics on iOS and Android:
76
-
77
- - A 56 pt header with `cropperToolbarTitle` centered and a rotate button on the right. The rotate button turns the image 90° counterclockwise; `cropperRotateButtonsHidden` hides it.
78
- - The crop area. The crop box keeps 20 pt from every edge, and the image outside it shows the page background at 70% opacity. The rule-of-thirds grid shows while the image is moved, unless `showCropGuidelines` is `false`.
79
- - A footer with two capsule buttons, `cropperCancelText` and `cropperChooseText`, 50 pt tall with 10 pt between them. The confirm button shows a spinner while the image is saved.
80
-
81
- On the web the same screen is full screen on windows narrower than 640 px or shorter than 560 px, and a centered 560 × 760 px panel (smaller when the window is) otherwise. The header, crop area, toolbar and footer are a flex column, so the buttons always stay inside the panel. The web screen adds, for mouse and keyboard users:
82
-
83
- - A toolbar under the crop area: zoom out, a zoom slider, zoom in, and reset.
84
- - Wheel to zoom around the pointer (trackpad pinch included), double click to zoom in 2× or back out, and two-finger pinch on touch screens.
85
- - Keyboard: arrow keys move the image (Shift for larger steps), `+` / `-` zoom, `R` rotates, Enter confirms and Escape cancels. Focus stays inside the cropper and returns to the previous element when it closes.
86
-
87
- `cropperAppearance` sets its colors and fonts. The optional font-family fields
88
- below require the app to provide these Roobert faces and own the applicable
89
- font license; this package contains no font files. Omit the fields to use
90
- platform defaults.
91
-
92
- ```ts
93
- await ImageCropPicker.openPicker({
94
- width: 240,
95
- height: 240,
96
- cropping: true,
97
- cropperToolbarTitle: 'Crop image',
98
- cropperAppearance: {
99
- colorScheme: 'dark',
100
- backgroundColor: '#0f0f0f',
101
- confirmButtonColor: '#ffffffed',
102
- confirmButtonTextColor: '#000000df',
103
- titleFontFamily: 'Roobert-SemiBold',
104
- buttonFontFamily: 'Roobert-Medium',
105
- },
106
- });
107
- ```
108
-
109
- | Field | Used for |
110
- | --- | --- |
111
- | `colorScheme` | `'light'` or `'dark'`. Picks the fallback palette and the status bar style. Defaults to the system appearance. |
112
- | `backgroundColor` | The page. The area outside the crop box is this color at 70% opacity. |
113
- | `titleColor` | The title and the crop box border. |
114
- | `iconColor` | The rotate button. |
115
- | `cancelButtonColor`, `cancelButtonPressedColor`, `cancelButtonTextColor` | The cancel button. |
116
- | `confirmButtonColor`, `confirmButtonPressedColor`, `confirmButtonTextColor` | The confirm button. |
117
- | `titleFontFamily`, `buttonFontFamily` | Fonts bundled with the app. iOS looks them up with `UIFont(name:)`, Android with React Native's `ReactFontManager`. On the web they are CSS font families, drawn at weight 600 and 500. |
118
- | `scale` | Multiplies every size, for apps that scale their UI. |
119
-
120
- Colors are CSS hex strings: `#RGB`, `#RRGGBB` or `#RRGGBBAA`. Anything left out falls back to OneKey's light or dark palette.
121
-
122
- ## Behavior
123
-
124
- - Processed results are always JPEG. `width` and `height` set the crop aspect ratio, and the cropped image is scaled to exactly that size, so a crop box a pixel off the ratio still yields the requested dimensions. With `freeStyleCropEnabled`, the crop keeps its own aspect ratio and is scaled to fit inside `width` × `height`.
125
- - `compressImageMaxWidth`, `compressImageMaxHeight` and `compressImageQuality` apply after cropping. The default quality is 0.8 on iOS and 1 on Android, as in `react-native-image-crop-picker`.
126
- - Photos are decoded at most 4096 px on the long side, which keeps very large photos from exhausting memory. `cropRect` is reported in the original image's coordinates on iOS.
127
- - Results are written to `<tmp>/react-native-image-crop-picker/` on iOS and `<cache>/react-native-image-crop-picker/` on Android. `clean()` empties that directory.
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 `ios/TOCropViewController` is MIT licensed by Tim Oliver; see its `LICENSE`.
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.7.0-45",
3
+ "version": "6.7.0-47",
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"