@onekeyfe/react-native-image 6.7.0-46 → 6.7.0-48
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 +144 -86
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,109 +1,167 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# @onekeyfe/react-native-image
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
**Native image loading for OneKey apps — SDWebImage on iOS, Glide on Android, and a Nitro image view with cache control.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@onekeyfe/react-native-image)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
14
|
+
</div>
|
|
15
|
+
|
|
16
|
+
Renders remote and bundled images through a Nitro view backed by SDWebImage on
|
|
17
|
+
iOS and Glide on Android. The native view owns loading and terminal presentation,
|
|
18
|
+
cache control, animated images, request cancellation and safe reuse of recycled
|
|
19
|
+
cells; the application owns sizing, source selection and business fallbacks. A
|
|
20
|
+
separate `OneKeyIcon` entry renders host-provided named SVG icons on native and
|
|
21
|
+
Web. The package has no Web renderer for `OneKeyImage` itself.
|
|
22
|
+
|
|
23
|
+
## Features
|
|
24
|
+
|
|
25
|
+
- **Native image pipeline** — SDWebImage on iOS and Glide on Android with
|
|
26
|
+
`memory-disk`, `memory`, `disk` or `none` cache policies.
|
|
27
|
+
- **Native loading and fallback states** — static placeholders, opt-in skeleton
|
|
28
|
+
loading, and terminal error/fallback presentation drawn by the native view.
|
|
29
|
+
- **Explicit cache control** — `preload` and `clearMemory`/`clearDisk`/`clearAll`
|
|
30
|
+
resolve only after the requested native cache work completes.
|
|
31
|
+
- **Bounded TOS rendition** — `optimizeTos` may swap eligible OneKey asset URLs
|
|
32
|
+
for a rendition sized from `resizeWidth`/`resizeHeight` and `overscan`.
|
|
33
|
+
- **Recycled-cell safety** — `recyclingKey` and `reload()`/`cancel()` keep stale
|
|
34
|
+
work out of reused native views.
|
|
35
|
+
- **Named SVG icons** — a separate `OneKeyIcon` entry renders host-owned artwork
|
|
36
|
+
with no network request, on native and on Web.
|
|
37
|
+
|
|
38
|
+
## Installation
|
|
39
|
+
|
|
40
|
+
```sh
|
|
41
|
+
yarn add @onekeyfe/react-native-image \
|
|
42
|
+
@onekeyfe/react-native-skeleton \
|
|
43
|
+
react-native-nitro-modules@0.37.0
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Peer dependencies: `react`, `react-native`, `react-native-nitro-modules` 0.37.0
|
|
47
|
+
and `@onekeyfe/react-native-skeleton` (the native skeleton renderer). Install the
|
|
48
|
+
app's iOS pods and rebuild the native binary; a JavaScript-only install does not
|
|
49
|
+
register the views:
|
|
7
50
|
|
|
8
|
-
|
|
9
|
-
|
|
51
|
+
```sh
|
|
52
|
+
cd ios && pod install
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Android links through autolinking; deployment floors are iOS 15.1 and Android
|
|
56
|
+
API 24. For a CocoaPods static-library integration, declare the SDWebImage coders
|
|
57
|
+
as modular headers in the application `Podfile`: SDWebImage `5.21.7`,
|
|
58
|
+
SDWebImageWebPCoder `0.14.6` and SDWebImageSVGCoder `1.7.0`.
|
|
59
|
+
|
|
60
|
+
## Usage
|
|
10
61
|
|
|
11
62
|
```tsx
|
|
63
|
+
import {
|
|
64
|
+
OneKeyImage,
|
|
65
|
+
OneKeyImageLoadingStrategy,
|
|
66
|
+
OneKeyImageVariant,
|
|
67
|
+
} from '@onekeyfe/react-native-image';
|
|
68
|
+
|
|
12
69
|
<OneKeyImage
|
|
13
|
-
source={{ uri:
|
|
70
|
+
source={{ uri: avatarUrl }}
|
|
14
71
|
variant={OneKeyImageVariant.AVATAR}
|
|
15
|
-
|
|
16
|
-
|
|
72
|
+
loadingStrategy={OneKeyImageLoadingStrategy.SKELETON}
|
|
73
|
+
style={{ width: 48, height: 48, borderRadius: 24 }}
|
|
74
|
+
/>;
|
|
17
75
|
```
|
|
18
76
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
state semantics match the native image libraries:
|
|
77
|
+
Give the view explicit dimensions: it does not derive its own size from the
|
|
78
|
+
image, and a reused list cell must receive a new `recyclingKey`.
|
|
22
79
|
|
|
23
|
-
|
|
24
|
-
- `fallback`: shown when `source` is null, cannot be resolved, or fails to load.
|
|
80
|
+
### Named icons
|
|
25
81
|
|
|
26
|
-
`
|
|
27
|
-
|
|
82
|
+
`OneKeyIcon` lives in the separate `icon` entry and renders artwork the host
|
|
83
|
+
supplies at build time:
|
|
28
84
|
|
|
29
|
-
|
|
85
|
+
```tsx
|
|
86
|
+
import { OneKeyIcon } from '@onekeyfe/react-native-image/icon';
|
|
30
87
|
|
|
31
|
-
|
|
32
|
-
onLoad={({ source: { url, width, height }, cacheType }) => {}}
|
|
33
|
-
onError={({ error }) => {}}
|
|
88
|
+
<OneKeyIcon name="StarOutline" color="#202020" style={{ width: 24, height: 24 }} />;
|
|
34
89
|
```
|
|
35
90
|
|
|
36
|
-
|
|
37
|
-
`
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
91
|
+
Names match `^[A-Z][A-Za-z0-9]*$`; the default size is 24 × 24 and the default
|
|
92
|
+
color is opaque black. `color` only resolves `currentColor` fills and strokes, it
|
|
93
|
+
is not a whole-image tint. The SDK ships no artwork: native builds provide the
|
|
94
|
+
icon bundle and Web builds must alias `#onekey-icon-assets` to the host's
|
|
95
|
+
generated icon table, otherwise named icons render blank.
|
|
41
96
|
|
|
42
|
-
|
|
43
|
-
skeleton loading is opt-in and replaces the static loading appearance instead
|
|
44
|
-
of appearing as a second stage:
|
|
97
|
+
## API
|
|
45
98
|
|
|
46
|
-
|
|
47
|
-
<OneKeyImage
|
|
48
|
-
source={{ uri }}
|
|
49
|
-
loadingStrategy={OneKeyImageLoadingStrategy.SKELETON}
|
|
50
|
-
fallback={<UnavailableImagePlaceholder />}
|
|
51
|
-
/>
|
|
52
|
-
```
|
|
99
|
+
### `OneKeyImage`
|
|
53
100
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
`
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
allows metadata dimensions up to 16,000,000 pixels and separately caps its
|
|
65
|
-
decoded animation frame buffer at 16 MiB. These limits reflect the native
|
|
66
|
-
decoders' different allocation behavior.
|
|
67
|
-
|
|
68
|
-
`recyclingKey` is available for recycled list cells. Changing it clears stale
|
|
69
|
-
content before the next source is displayed.
|
|
70
|
-
|
|
71
|
-
Cache clearing methods resolve only after their requested native cache work has
|
|
72
|
-
completed, including `OneKeyImageCache.clearMemory()`.
|
|
73
|
-
|
|
74
|
-
Pass the rendered logical dimensions and device pixel ratio when preloading so
|
|
75
|
-
TOS URL selection and decode cache identity match the later render. `preload`
|
|
76
|
-
resolves to `true` only when all requested sources complete successfully:
|
|
77
|
-
|
|
78
|
-
```ts
|
|
79
|
-
const loaded = await OneKeyImageCache.preload([
|
|
80
|
-
{
|
|
81
|
-
uri,
|
|
82
|
-
resizeWidth: 48,
|
|
83
|
-
resizeHeight: 64,
|
|
84
|
-
pixelRatio: 3,
|
|
85
|
-
overscan: 1.1,
|
|
86
|
-
},
|
|
87
|
-
]);
|
|
88
|
-
```
|
|
101
|
+
| Prop | Type | Default | Platforms | Description |
|
|
102
|
+
| --- | --- | --- | :-: | --- |
|
|
103
|
+
| `source` | URI source or numeric asset | — | iOS, Android | `null`, blank or unresolved input shows fallback without `onError`. |
|
|
104
|
+
| `variant`, `contentFit` | `generic` \| `token` \| `network` \| `avatar`; `cover` \| `contain` \| `fill` \| `center` | `generic`, `cover` | iOS, Android | Native placeholder/fallback presentation and display/decode sizing. |
|
|
105
|
+
| `cachePolicy`, `loadingStrategy` | `memory-disk` \| `memory` \| `disk` \| `none`; `static` \| `skeleton` \| `none` | `memory-disk`, `static` | iOS, Android | Cache policy (prop wins over source value) and native loading surface; a React `placeholder` disables the native surface. |
|
|
106
|
+
| `placeholder`, `fallback`, `placeholderColor` | `ReactNode`, color | — | iOS, Android | Overlay content clipped to the same rounded bounds (no pointer events) and theme color for native states. |
|
|
107
|
+
| `autoplay`, `recyclingKey`, `round`, `optimizeTos` | `boolean`, `string`, `boolean`, `boolean` | `false` Android / `true` iOS, —, `false`, `true` | iOS, Android | Animated images, request-generation identity, oval clip and bounded OneKey rendition URLs. |
|
|
108
|
+
| `resizeWidth`, `resizeHeight`, `overscan` | `number` | —, —, `1.1` | iOS, Android | Logical-size hints used by preload, TOS selection and memory probing. |
|
|
109
|
+
| `onLoadStart`, `onLoad`, `onLoadEnd`, `onDisplay`, `onError` | event callbacks | — | iOS, Android | `onLoad` receives `{ source: { url, width, height }, cacheType }`. |
|
|
110
|
+
| `hybridRef` | callback ref | — | iOS, Android | Exposes `reload()` and `cancel()`. |
|
|
89
111
|
|
|
90
|
-
|
|
91
|
-
header in the application Podfile:
|
|
112
|
+
### `OneKeyImageCache`
|
|
92
113
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
114
|
+
| Method | Result | Platforms | Description |
|
|
115
|
+
| --- | --- | --- | :-: |
|
|
116
|
+
| `preload(sources)` | `Promise<boolean>` | iOS, Android | Resolves `true` only when every valid source succeeds. |
|
|
117
|
+
| `clearMemory()`, `clearDisk()`, `clearAll()` | `Promise<void>` | iOS, Android | Resolve after the requested native cache work, including cross-size hints. |
|
|
118
|
+
|
|
119
|
+
Enums exported by the package: `OneKeyImageVariant`, `OneKeyImageContentFit`,
|
|
120
|
+
`OneKeyImageCachePolicy`, `OneKeyImageLoadingStrategy` and
|
|
121
|
+
`OneKeyImageCacheType` (`none`, `memory`, `disk`).
|
|
122
|
+
|
|
123
|
+
### `OneKeyIcon`
|
|
124
|
+
|
|
125
|
+
| Prop | Type | Platforms | Description |
|
|
126
|
+
| --- | --- | :-: | --- |
|
|
127
|
+
| `name`, `color`, `style` | `string`, `string`, view props | iOS, Android, Web | Required host icon name; native accepts `#hex`/`rgb()`/`rgba()`, Web follows CSS. Explicit dimensions beat the 24 × 24 default. |
|
|
128
|
+
|
|
129
|
+
The package also exports `createNamedIcon(document, name)` from
|
|
130
|
+
`@onekeyfe/react-native-image/icon/dom` for non-React Web surfaces.
|
|
131
|
+
|
|
132
|
+
## Platform support
|
|
133
|
+
|
|
134
|
+
| Capability | iOS | Android | Web |
|
|
135
|
+
| --- | :-: | :-: | :-: |
|
|
136
|
+
| `OneKeyImage` rendering | ✅ | ✅ | — |
|
|
137
|
+
| Native loading, skeleton and fallback states | ✅ | ✅ | — |
|
|
138
|
+
| Cache preload and clearing | ✅ | ✅ | — |
|
|
139
|
+
| Animated images | ✅ | ✅ | — |
|
|
140
|
+
| `OneKeyIcon` named SVG | ✅ | ✅ | ✅ host-supplied assets |
|
|
141
|
+
|
|
142
|
+
## Caveats
|
|
143
|
+
|
|
144
|
+
> [!IMPORTANT]
|
|
145
|
+
> `OneKeyImage` is a native view for iOS and Android only. The Web entry of this
|
|
146
|
+
> package provides `OneKeyIcon` and `createNamedIcon`; it never renders
|
|
147
|
+
> `OneKeyImage`.
|
|
148
|
+
|
|
149
|
+
> [!NOTE]
|
|
150
|
+
> Both platforms reject oversized or malformed input: 32 MiB encoded images,
|
|
151
|
+
> 8 MiB decoded data URIs, 16 MiB animated files, 1,000 frames and 60 seconds.
|
|
152
|
+
|
|
153
|
+
> [!WARNING]
|
|
154
|
+
> A reused native view must receive a new `recyclingKey` (or an explicit
|
|
155
|
+
> `reload()`/`cancel()`) when its logical content changes; otherwise stale work
|
|
156
|
+
> from the previous source owns the view.
|
|
157
|
+
|
|
158
|
+
## References
|
|
98
159
|
|
|
99
|
-
|
|
160
|
+
- [Package spec](docs/SPEC.md)
|
|
161
|
+
- [Example image page](../../example/react-native/pages/OneKeyImageTestPage.tsx)
|
|
162
|
+
- [npm package](https://www.npmjs.com/package/@onekeyfe/react-native-image)
|
|
163
|
+
- [Changelog](../../CHANGELOG.md)
|
|
100
164
|
|
|
101
|
-
|
|
102
|
-
`OneKeyIcons.bundle` on iOS and `assets/icons` on Android, including the manifest.
|
|
103
|
-
Web builds alias `#onekey-icon-assets` to a generated module exporting
|
|
104
|
-
`iconResourceHref(name: string): string | undefined`; the default SDK provider
|
|
105
|
-
is empty. `OneKeyIcon` props are unchanged. See [the resource contract](docs/SPEC.md#16-host-owned-icon-resources--implemented-sdk-fixture-runtime-verified).
|
|
165
|
+
## License
|
|
106
166
|
|
|
107
|
-
|
|
108
|
-
`icons:test` are repository maintenance commands that require the example
|
|
109
|
-
fixtures; npm consumers do not receive those samples or the complete catalog.
|
|
167
|
+
MIT. See [LICENSE](LICENSE).
|
package/package.json
CHANGED