@onekeyfe/react-native-device-utils 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.
- package/README.md +117 -87
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -1,9 +1,39 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# @onekeyfe/react-native-device-utils
|
|
2
4
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
**Host integration for OneKey apps: launch data, device tokens, foldables, iPadOS windows and a process-wide primitive store.**
|
|
6
|
+
|
|
7
|
+
[](https://www.npmjs.com/package/@onekeyfe/react-native-device-utils)
|
|
8
|
+
[](LICENSE)
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
One Nitro HybridObject that groups the small native capabilities a host app
|
|
16
|
+
needs but React Native does not expose: launch options and startup time, push
|
|
17
|
+
device tokens, foldable/dual-screen state on both platforms, iPadOS window
|
|
18
|
+
controls and the app menu, Android navigation-bar styling and Play Services
|
|
19
|
+
inspection, boot-failure recovery, and a bounded in-memory primitive store. It
|
|
20
|
+
is a set of host integration helpers, not a portable device API: several calls
|
|
21
|
+
are deliberately no-ops on the platform that cannot honor them, and the store is
|
|
22
|
+
process-scoped and never persisted.
|
|
23
|
+
|
|
24
|
+
## Features
|
|
25
|
+
|
|
26
|
+
- **One object, many host capabilities** — launch options, tokens, appearance,
|
|
27
|
+
foldables, services and recovery behind a single imported HybridObject.
|
|
28
|
+
- **Shared in-memory store** — 128 entries of string/boolean/number values shared
|
|
29
|
+
by the main and background runtimes, with atomic set-if-absent claims and type
|
|
30
|
+
preservation.
|
|
31
|
+
- **Explicit listener lifecycle** — every subscription returns a numeric ID that
|
|
32
|
+
its owner removes; no hidden global listeners.
|
|
33
|
+
- **Platform-honest** — iOS-only and Android-only calls are documented as such
|
|
34
|
+
and are safe no-ops on the other platform instead of throwing.
|
|
35
|
+
- **Typed boundary** — enums and result objects land in TypeScript through
|
|
36
|
+
Nitro-generated bindings, so adapters get compile-time checks.
|
|
7
37
|
|
|
8
38
|
## Installation
|
|
9
39
|
|
|
@@ -11,99 +41,99 @@ These are host integration helpers rather than a portable browser device API.
|
|
|
11
41
|
yarn add @onekeyfe/react-native-device-utils react-native-nitro-modules
|
|
12
42
|
```
|
|
13
43
|
|
|
14
|
-
Install the
|
|
15
|
-
such as push tokens and launch options also require the application's native
|
|
16
|
-
host configuration; installing this package does not register those services.
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
```ts
|
|
21
|
-
import { ReactNativeDeviceUtils } from '@onekeyfe/react-native-device-utils';
|
|
44
|
+
Install the native peer packages this package links as well:
|
|
22
45
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
const installer = ReactNativeDeviceUtils.getInstallerPackageName();
|
|
46
|
+
```sh
|
|
47
|
+
yarn add @onekeyfe/react-native-native-logger
|
|
26
48
|
```
|
|
27
49
|
|
|
28
|
-
|
|
50
|
+
This package ships native code. Install the app's iOS pods and rebuild the
|
|
51
|
+
native binary; a JavaScript-only update does not register the module. Push
|
|
52
|
+
tokens and launch options additionally depend on the host application's native
|
|
53
|
+
configuration — installing this package does not register those services.
|
|
29
54
|
|
|
30
|
-
|
|
31
|
-
interface style.
|
|
32
|
-
- Android navigation bar: `setNavigationBarAppearance(r, g, b, a, useDarkIcons)`.
|
|
33
|
-
Color channels use 0–255; this method is a no-op on iOS.
|
|
34
|
-
- Launch and notifications: read/clear launch options, register/store device
|
|
35
|
-
tokens and consume cold-start local notification data.
|
|
36
|
-
- Android services: WebView package information, Google Play Services status,
|
|
37
|
-
distribution channel and installer identification.
|
|
38
|
-
- Boot recovery: mark boot success, inspect/update failure counts and consume
|
|
39
|
-
a pending recovery action.
|
|
40
|
-
|
|
41
|
-
Spanning listeners return IDs that must be removed when their owner finishes.
|
|
42
|
-
Cold-start local notification consumption is meaningful on iOS; Android returns
|
|
43
|
-
an empty string. Platform-specific results should not be interpreted as a
|
|
44
|
-
cross-platform guarantee that a service or hardware feature is available.
|
|
45
|
-
|
|
46
|
-
See [src/ReactNativeDeviceUtils.nitro.ts](src/ReactNativeDeviceUtils.nitro.ts)
|
|
47
|
-
for the complete signatures, enum values and platform notes.
|
|
48
|
-
See [docs/SPEC.md](docs/SPEC.md) for the InMemoryStore contract and acceptance status.
|
|
55
|
+
## Usage
|
|
49
56
|
|
|
50
|
-
|
|
57
|
+
```ts
|
|
58
|
+
import { ReactNativeDeviceUtils } from '@onekeyfe/react-native-device-utils';
|
|
51
59
|
|
|
52
|
-
|
|
60
|
+
// Call once during startup so native event listeners exist.
|
|
61
|
+
ReactNativeDeviceUtils.initEventListeners();
|
|
53
62
|
|
|
54
|
-
|
|
55
|
-
|
|
63
|
+
const { launchType, deepLink } =
|
|
64
|
+
await ReactNativeDeviceUtils.getLaunchOptions();
|
|
65
|
+
const startupTime = await ReactNativeDeviceUtils.getStartupTime();
|
|
56
66
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
67
|
+
// Claim a startup stage exactly once across runtimes.
|
|
68
|
+
const claimed = ReactNativeDeviceUtils.setInMemoryValueIfAbsent(
|
|
69
|
+
'analytics:startup:jsReadyTime',
|
|
70
|
+
Date.now(),
|
|
71
|
+
);
|
|
61
72
|
```
|
|
62
73
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
74
|
+
Consumers own key namespaces and decide what to do with each result. Store
|
|
75
|
+
values are native copies, not retained JS objects.
|
|
76
|
+
|
|
77
|
+
## API
|
|
78
|
+
|
|
79
|
+
| Method | Result | Platforms | Description |
|
|
80
|
+
| --- | --- | :-: | --- |
|
|
81
|
+
| `initEventListeners()` | `void` | iOS, Android | Registers native listeners; call once at startup. |
|
|
82
|
+
| `getLaunchOptions()` / `clearLaunchOptions()` | `Promise<LaunchOptions>` / `Promise<boolean>` | iOS, Android | Read or consume the app's launch type and optional deep link. |
|
|
83
|
+
| `getStartupTime()` | `Promise<number>` | iOS, Android | Native startup timestamp. |
|
|
84
|
+
| `getDeviceToken()` / `saveDeviceToken(token)` / `registerDeviceToken()` | `Promise<string>` / `Promise<void>` / `Promise<boolean>` | iOS, Android | Push-token plumbing; host setup still owns registration. |
|
|
85
|
+
| `getInMemoryValue(key)` / `setInMemoryValue(key, value)` / `removeInMemoryValue(key)` / `setInMemoryValueIfAbsent(key, value)` | `InMemoryValue \| undefined` / `void` / `boolean` / `boolean` | iOS, Android | Synchronous bounded primitive store. |
|
|
86
|
+
| `getAndClearColdStartLocalNotification()` | `Promise<string>` | iOS, Android | Returns local-notification JSON once; Android returns `""`. |
|
|
87
|
+
| `isDualScreenDevice()` / `isSpanning()` | `boolean` | iOS, Android | Foldable detection and spanning state. |
|
|
88
|
+
| `getWindowRects()` / `getHingeBounds()` | `Promise<DualScreenInfoRect[]>` / `Promise<DualScreenInfoRect>` | iOS, Android | Window and hinge geometry; iOS keeps empty/zero results. |
|
|
89
|
+
| `getWindowControlsInsets()` + change listeners | `WindowControlsInsets` / listener ID | iOS 26+ | Room taken by system window controls; zero elsewhere. |
|
|
90
|
+
| `setMainMenuConfig(config)` + command listeners | `void` / listener ID | iOS (iPadOS) | Rebuilds the iPadOS app menu; Android ignores it. |
|
|
91
|
+
| `setNavigationBarAppearance(r, g, b, a, useDarkIcons)` | `void` | Android | Applies the navigation-bar color and icon style; no-op on iOS. |
|
|
92
|
+
| `getCurrentWebViewPackageInfo()` / `isGooglePlayServicesAvailable()` | `Promise<WebViewPackageInfo>` / `Promise<GooglePlayServicesStatus>` | Android | WebView package and Play Services status. |
|
|
93
|
+
| `getAndroidChannel()` / `getInstallerPackageName()` | `AndroidChannel` / `InstallerPackageName` | Android | Distribution channel and installer source. |
|
|
94
|
+
| `markBootSuccess()` / `getConsecutiveBootFailCount()` / `incrementConsecutiveBootFailCount()` / `setConsecutiveBootFailCount(count)` / `getAndClearRecoveryAction()` | varies | iOS, Android | Boot-failure counter and one-shot recovery action. |
|
|
95
|
+
| `exitApp()` | `void` | iOS, Android | Terminates the app process. |
|
|
96
|
+
|
|
97
|
+
See [`src/ReactNativeDeviceUtils.nitro.ts`](src/ReactNativeDeviceUtils.nitro.ts)
|
|
98
|
+
for full signatures, result types and enum values.
|
|
99
|
+
|
|
100
|
+
## Platform support
|
|
101
|
+
|
|
102
|
+
| Capability | iOS | Android | Web |
|
|
103
|
+
| --- | :-: | :-: | :-: |
|
|
104
|
+
| Launch options, startup time, device tokens | ✅ | ✅ | — |
|
|
105
|
+
| In-memory primitive store | ✅ | ✅ | — |
|
|
106
|
+
| Dual-screen detection and spanning listeners | ✅ foldable iPhone | ✅ | — |
|
|
107
|
+
| Window controls insets | ✅ iOS 26+ | — | — |
|
|
108
|
+
| iPadOS main menu | ✅ iPadOS | — | — |
|
|
109
|
+
| Navigation-bar appearance | — | ✅ | — |
|
|
110
|
+
| WebView / Play Services / installer inspection | — | ✅ | — |
|
|
111
|
+
| Boot recovery | ✅ | ✅ | — |
|
|
112
|
+
|
|
113
|
+
## Caveats
|
|
114
|
+
|
|
115
|
+
> [!IMPORTANT]
|
|
116
|
+
> The in-memory store API needs a rebuilt native host containing these bindings;
|
|
117
|
+
> it is not an OTA-only change. The store survives JS reloads and runtime
|
|
118
|
+
> recreation but not process exit, and it is never written to disk.
|
|
119
|
+
|
|
120
|
+
> [!NOTE]
|
|
121
|
+
> The store holds at most 128 entries. Keys are limited to 256 UTF-8 bytes and
|
|
122
|
+
> string values to 4096 UTF-8 bytes; overlong arguments or a write to a new key
|
|
123
|
+
> at capacity throw synchronously and leave the map unchanged.
|
|
124
|
+
|
|
125
|
+
> [!WARNING]
|
|
126
|
+
> Do not treat a successful call as proof that the underlying platform feature
|
|
127
|
+
> exists. Android returns `""` for cold-start local notifications, iOS ignores the
|
|
128
|
+
> navigation-bar call, and window-controls insets are zero outside iOS 26+.
|
|
129
|
+
|
|
130
|
+
## References
|
|
131
|
+
|
|
132
|
+
- [Package spec](docs/SPEC.md)
|
|
133
|
+
- [Native interface](src/ReactNativeDeviceUtils.nitro.ts)
|
|
134
|
+
- [Example page](../../example/react-native/pages/DeviceUtilsTestPage.tsx)
|
|
135
|
+
- [Changelog](../../CHANGELOG.md)
|
|
106
136
|
|
|
107
137
|
## License
|
|
108
138
|
|
|
109
|
-
MIT.
|
|
139
|
+
MIT. See [LICENSE](LICENSE).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-device-utils",
|
|
3
|
-
"version": "6.7.0-
|
|
3
|
+
"version": "6.7.0-47",
|
|
4
4
|
"description": "Native device, launch, system appearance and boot recovery utilities for OneKey",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -90,6 +90,7 @@
|
|
|
90
90
|
"typescript": "^5.9.2"
|
|
91
91
|
},
|
|
92
92
|
"peerDependencies": {
|
|
93
|
+
"@onekeyfe/react-native-native-logger": "*",
|
|
93
94
|
"react": "*",
|
|
94
95
|
"react-native": "*",
|
|
95
96
|
"react-native-nitro-modules": "0.37.0"
|