@onekeyfe/react-native-device-utils 6.7.0-alpha.475 → 6.8.0-11
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/ReactNativeDeviceUtils.podspec +6 -0
- package/android/src/main/java/com/margelo/nitro/reactnativedeviceutils/ReactNativeDeviceUtils.kt +99 -29
- package/ios/DualScreenDetector.swift +20 -3
- package/ios/ReactNativeDeviceUtils.swift +22 -0
- package/ios/tests/AppleAdsAttributionTests.swift +48 -0
- package/lib/typescript/src/ReactNativeDeviceUtils.nitro.d.ts +2 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeDeviceUtilsSpec.cpp +16 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeDeviceUtilsSpec.hpp +1 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/HybridReactNativeDeviceUtilsSpec.kt +4 -0
- package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Bridge.cpp +8 -0
- package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Bridge.hpp +43 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeDeviceUtilsSpecSwift.hpp +8 -0
- package/nitrogen/generated/ios/swift/Func_void_std__optional_std__string_.swift +53 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeDeviceUtilsSpec.swift +1 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeDeviceUtilsSpec_cxx.swift +25 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeDeviceUtilsSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeDeviceUtilsSpec.hpp +1 -0
- package/package.json +2 -1
- package/src/ReactNativeDeviceUtils.nitro.ts +3 -0
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).
|
|
@@ -18,6 +18,8 @@ Pod::Spec.new do |s|
|
|
|
18
18
|
"ios/**/*.{m,mm}",
|
|
19
19
|
"cpp/**/*.{hpp,cpp}",
|
|
20
20
|
]
|
|
21
|
+
s.exclude_files = "ios/tests/**/*"
|
|
22
|
+
s.frameworks = "AdServices"
|
|
21
23
|
|
|
22
24
|
s.dependency 'React-jsi'
|
|
23
25
|
s.dependency 'React-callinvoker'
|
|
@@ -27,4 +29,8 @@ Pod::Spec.new do |s|
|
|
|
27
29
|
add_nitrogen_files(s)
|
|
28
30
|
|
|
29
31
|
install_modules_dependencies(s)
|
|
32
|
+
|
|
33
|
+
s.test_spec "Tests" do |test_spec|
|
|
34
|
+
test_spec.source_files = "ios/tests/**/*.swift"
|
|
35
|
+
end
|
|
30
36
|
end
|
package/android/src/main/java/com/margelo/nitro/reactnativedeviceutils/ReactNativeDeviceUtils.kt
CHANGED
|
@@ -25,6 +25,7 @@ import androidx.window.layout.WindowLayoutInfo
|
|
|
25
25
|
import androidx.window.java.layout.WindowInfoTrackerCallbackAdapter
|
|
26
26
|
import androidx.appcompat.app.AppCompatDelegate
|
|
27
27
|
import com.facebook.proguard.annotations.DoNotStrip
|
|
28
|
+
import com.facebook.react.ReactRootView
|
|
28
29
|
import com.facebook.react.bridge.LifecycleEventListener
|
|
29
30
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
30
31
|
import com.margelo.nitro.NitroModules
|
|
@@ -965,9 +966,9 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
965
966
|
// the platform bar transparent and draw the requested color only
|
|
966
967
|
// behind three-button navigation.
|
|
967
968
|
window.navigationBarColor = Color.TRANSPARENT
|
|
968
|
-
installNavigationBarProtection(
|
|
969
|
+
installNavigationBarProtection(activity, appearance.color)
|
|
969
970
|
} else {
|
|
970
|
-
removeNavigationBarProtection(
|
|
971
|
+
removeNavigationBarProtection(activity)
|
|
971
972
|
window.navigationBarColor = appearance.color
|
|
972
973
|
}
|
|
973
974
|
} catch (e: Exception) {
|
|
@@ -979,27 +980,40 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
979
980
|
}
|
|
980
981
|
}
|
|
981
982
|
|
|
982
|
-
private fun installNavigationBarProtection(
|
|
983
|
-
val
|
|
984
|
-
val
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
983
|
+
private fun installNavigationBarProtection(activity: Activity, color: Int) {
|
|
984
|
+
val decorView = activity.window?.decorView as? ViewGroup ?: return
|
|
985
|
+
val contentView = activity.findViewById<ViewGroup>(android.R.id.content)
|
|
986
|
+
val reactRootIndex = contentView?.let(::findReactRootIndex)
|
|
987
|
+
// Overlay hosts are content-view children added after the React root, and a
|
|
988
|
+
// dimmed overlay must cover this bar together with the rest of the screen,
|
|
989
|
+
// so the protection belongs directly above the React root and below them.
|
|
990
|
+
// While the React root does not exist yet, fall back to the decor view; the
|
|
991
|
+
// next call moves it into place.
|
|
992
|
+
val container =
|
|
993
|
+
if (contentView != null && reactRootIndex != null) contentView else decorView
|
|
994
|
+
val targetIndex =
|
|
995
|
+
if (container === contentView && reactRootIndex != null) {
|
|
996
|
+
reactRootIndex + 1
|
|
997
|
+
} else {
|
|
998
|
+
container.childCount
|
|
999
|
+
}
|
|
1000
|
+
// A detached React root falls back to the decor view while an earlier
|
|
1001
|
+
// protection may still live in the content view. Reuse it (moving it to the
|
|
1002
|
+
// fallback container) and drop any duplicate, so one activity never ends up
|
|
1003
|
+
// with a second protection stacked above later overlays.
|
|
1004
|
+
val protectionView =
|
|
1005
|
+
findNavigationBarProtection(contentView ?: decorView)
|
|
1006
|
+
?: findNavigationBarProtection(decorView)
|
|
1007
|
+
?: View(container.context).also { view ->
|
|
1008
|
+
view.tag = NAVIGATION_BAR_PROTECTION_VIEW_TAG
|
|
1009
|
+
view.isClickable = false
|
|
1010
|
+
view.isFocusable = false
|
|
1011
|
+
view.importantForAccessibility = View.IMPORTANT_FOR_ACCESSIBILITY_NO
|
|
1012
|
+
}
|
|
1013
|
+
removeDuplicateNavigationBarProtections(contentView, decorView, protectionView)
|
|
1014
|
+
placeNavigationBarProtection(container, protectionView, targetIndex)
|
|
1000
1015
|
|
|
1001
1016
|
protectionView.visibility = View.VISIBLE
|
|
1002
|
-
protectionView.bringToFront()
|
|
1003
1017
|
ViewCompat.setOnApplyWindowInsetsListener(protectionView) { view, windowInsets ->
|
|
1004
1018
|
val navigationBarInsets = windowInsets.getInsets(
|
|
1005
1019
|
WindowInsetsCompat.Type.navigationBars()
|
|
@@ -1060,9 +1074,57 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
1060
1074
|
ViewCompat.requestApplyInsets(protectionView)
|
|
1061
1075
|
}
|
|
1062
1076
|
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1077
|
+
/** Removes extra protection views left by an earlier fallback. */
|
|
1078
|
+
private fun removeDuplicateNavigationBarProtections(
|
|
1079
|
+
contentView: ViewGroup?,
|
|
1080
|
+
decorView: ViewGroup,
|
|
1081
|
+
keep: View,
|
|
1082
|
+
) {
|
|
1083
|
+
for (container in listOfNotNull(contentView, decorView)) {
|
|
1084
|
+
for (index in container.childCount - 1 downTo 0) {
|
|
1085
|
+
val child = container.getChildAt(index)
|
|
1086
|
+
if (child !== keep && child.tag == NAVIGATION_BAR_PROTECTION_VIEW_TAG) {
|
|
1087
|
+
ViewCompat.setOnApplyWindowInsetsListener(child, null)
|
|
1088
|
+
container.removeView(child)
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
}
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
/** Index of the React root child, or null before the root view exists. */
|
|
1095
|
+
private fun findReactRootIndex(container: ViewGroup): Int? {
|
|
1096
|
+
for (index in 0 until container.childCount) {
|
|
1097
|
+
if (container.getChildAt(index) is ReactRootView) {
|
|
1098
|
+
return index
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
return null
|
|
1102
|
+
}
|
|
1103
|
+
|
|
1104
|
+
private fun placeNavigationBarProtection(
|
|
1105
|
+
container: ViewGroup,
|
|
1106
|
+
protectionView: View,
|
|
1107
|
+
index: Int,
|
|
1108
|
+
) {
|
|
1109
|
+
val parent = protectionView.parent as? ViewGroup
|
|
1110
|
+
if (parent === container && container.indexOfChild(protectionView) == index) {
|
|
1111
|
+
return
|
|
1112
|
+
}
|
|
1113
|
+
parent?.removeView(protectionView)
|
|
1114
|
+
container.addView(
|
|
1115
|
+
protectionView,
|
|
1116
|
+
index.coerceIn(0, container.childCount),
|
|
1117
|
+
FrameLayout.LayoutParams(
|
|
1118
|
+
ViewGroup.LayoutParams.MATCH_PARENT,
|
|
1119
|
+
0,
|
|
1120
|
+
Gravity.BOTTOM,
|
|
1121
|
+
),
|
|
1122
|
+
)
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
private fun findNavigationBarProtection(container: ViewGroup): View? {
|
|
1126
|
+
for (index in 0 until container.childCount) {
|
|
1127
|
+
val child = container.getChildAt(index)
|
|
1066
1128
|
if (child.tag == NAVIGATION_BAR_PROTECTION_VIEW_TAG) {
|
|
1067
1129
|
return child
|
|
1068
1130
|
}
|
|
@@ -1070,11 +1132,15 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
1070
1132
|
return null
|
|
1071
1133
|
}
|
|
1072
1134
|
|
|
1073
|
-
private fun removeNavigationBarProtection(
|
|
1074
|
-
|
|
1075
|
-
val
|
|
1076
|
-
|
|
1077
|
-
|
|
1135
|
+
private fun removeNavigationBarProtection(activity: Activity?) {
|
|
1136
|
+
if (activity == null) return
|
|
1137
|
+
val decorView = activity.window?.decorView as? ViewGroup
|
|
1138
|
+
val contentView = activity.findViewById<ViewGroup>(android.R.id.content)
|
|
1139
|
+
for (container in listOfNotNull(contentView, decorView)) {
|
|
1140
|
+
val protectionView = findNavigationBarProtection(container) ?: continue
|
|
1141
|
+
ViewCompat.setOnApplyWindowInsetsListener(protectionView, null)
|
|
1142
|
+
container.removeView(protectionView)
|
|
1143
|
+
}
|
|
1078
1144
|
}
|
|
1079
1145
|
|
|
1080
1146
|
override fun onHostResume() {
|
|
@@ -1267,6 +1333,10 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
1267
1333
|
return Promise.resolved(action)
|
|
1268
1334
|
}
|
|
1269
1335
|
|
|
1336
|
+
override fun getAppleAdsAttributionToken(): Promise<String?> {
|
|
1337
|
+
return Promise.resolved(null)
|
|
1338
|
+
}
|
|
1339
|
+
|
|
1270
1340
|
// MARK: - Android Channel & Installer
|
|
1271
1341
|
|
|
1272
1342
|
override fun getAndroidChannel(): AndroidChannel {
|
|
@@ -13,7 +13,9 @@ import ReactNativeNativeLogger
|
|
|
13
13
|
final class DualScreenDetector {
|
|
14
14
|
static let shared = DualScreenDetector()
|
|
15
15
|
|
|
16
|
-
|
|
16
|
+
// A new key: entries under the previous key may mark regular iPhones as
|
|
17
|
+
// foldable, because iOS 27.3 beta reports an `.unknown` hinge on them.
|
|
18
|
+
private static let cacheKey = "1k_dual_screen_device_model_v2"
|
|
17
19
|
private static let foldableModelIdentifiers: Set<String> = [
|
|
18
20
|
"iPhone19,4", // iPhone Duo
|
|
19
21
|
]
|
|
@@ -136,11 +138,12 @@ final class DualScreenDetector {
|
|
|
136
138
|
|
|
137
139
|
@available(iOS 27.1, *)
|
|
138
140
|
private func handleHingeUpdate(_ hinge: UIHinge?) {
|
|
141
|
+
let hasHinge = hinge.map { DualScreenDetector.isPhysicalHinge($0.status) } ?? false
|
|
139
142
|
let nextSpanning = hinge?.status == .fullyOpen || hinge?.status == .partiallyOpen
|
|
140
143
|
|
|
141
144
|
lock.lock()
|
|
142
|
-
let isNewlyDetected =
|
|
143
|
-
if
|
|
145
|
+
let isNewlyDetected = hasHinge && !isDualScreen
|
|
146
|
+
if hasHinge { isDualScreen = true }
|
|
144
147
|
let didChangeSpanning = spanning != nextSpanning
|
|
145
148
|
spanning = nextSpanning
|
|
146
149
|
let callbacks = Array(listeners.values)
|
|
@@ -159,6 +162,20 @@ final class DualScreenDetector {
|
|
|
159
162
|
callbacks.forEach { $0(nextSpanning) }
|
|
160
163
|
}
|
|
161
164
|
}
|
|
165
|
+
|
|
166
|
+
/// Only a reported fold position proves a hinge. iOS 27.3 beta delivers a
|
|
167
|
+
/// non-nil hinge with `.unknown` status on iPhones without one.
|
|
168
|
+
@available(iOS 27.1, *)
|
|
169
|
+
private static func isPhysicalHinge(_ status: UIHinge.Status) -> Bool {
|
|
170
|
+
switch status {
|
|
171
|
+
case .closed, .partiallyOpen, .fullyOpen:
|
|
172
|
+
return true
|
|
173
|
+
case .unknown:
|
|
174
|
+
return false
|
|
175
|
+
@unknown default:
|
|
176
|
+
return false
|
|
177
|
+
}
|
|
178
|
+
}
|
|
162
179
|
#endif
|
|
163
180
|
|
|
164
181
|
private static func keyWindow() -> UIWindow? {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import AdServices
|
|
1
2
|
import NitroModules
|
|
2
3
|
import UIKit
|
|
3
4
|
import ReactNativeNativeLogger
|
|
@@ -364,4 +365,25 @@ class ReactNativeDeviceUtils: HybridReactNativeDeviceUtilsSpec {
|
|
|
364
365
|
return hasEmbeddedProvision ? .other : .unknown
|
|
365
366
|
#endif
|
|
366
367
|
}
|
|
368
|
+
|
|
369
|
+
func getAppleAdsAttributionToken() throws -> Promise<String?> {
|
|
370
|
+
guard #available(iOS 14.3, *) else {
|
|
371
|
+
return .resolved(withResult: nil)
|
|
372
|
+
}
|
|
373
|
+
return Self.requestAppleAdsAttributionToken {
|
|
374
|
+
try AAAttribution.attributionToken()
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
static func requestAppleAdsAttributionToken(
|
|
379
|
+
using provider: @escaping @Sendable () throws -> String
|
|
380
|
+
) -> Promise<String?> {
|
|
381
|
+
return Promise.parallel(.global(qos: .utility)) {
|
|
382
|
+
let token = try provider()
|
|
383
|
+
guard !token.isEmpty else {
|
|
384
|
+
throw RuntimeError.error(withMessage: "AdServices returned an empty attribution token")
|
|
385
|
+
}
|
|
386
|
+
return token
|
|
387
|
+
}
|
|
388
|
+
}
|
|
367
389
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import NitroModules
|
|
2
|
+
import XCTest
|
|
3
|
+
@testable import ReactNativeDeviceUtils
|
|
4
|
+
|
|
5
|
+
final class AppleAdsAttributionTests: XCTestCase {
|
|
6
|
+
private enum ProviderError: Error {
|
|
7
|
+
case unavailable
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
@MainActor
|
|
11
|
+
func testResolvesNonEmptyTokenOffMainThread() async throws {
|
|
12
|
+
XCTAssertTrue(Thread.isMainThread)
|
|
13
|
+
let promise = ReactNativeDeviceUtils.requestAppleAdsAttributionToken {
|
|
14
|
+
XCTAssertFalse(Thread.isMainThread)
|
|
15
|
+
return "test-token"
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let token = try await promise.await()
|
|
19
|
+
XCTAssertEqual(token, "test-token")
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
func testRejectsEmptyToken() async {
|
|
23
|
+
let promise = ReactNativeDeviceUtils.requestAppleAdsAttributionToken { "" }
|
|
24
|
+
|
|
25
|
+
do {
|
|
26
|
+
_ = try await promise.await()
|
|
27
|
+
XCTFail("Expected the empty token to reject")
|
|
28
|
+
} catch {
|
|
29
|
+
XCTAssertEqual(
|
|
30
|
+
String(describing: error),
|
|
31
|
+
"AdServices returned an empty attribution token"
|
|
32
|
+
)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
func testPreservesProviderError() async {
|
|
37
|
+
let promise = ReactNativeDeviceUtils.requestAppleAdsAttributionToken {
|
|
38
|
+
throw ProviderError.unavailable
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
do {
|
|
42
|
+
_ = try await promise.await()
|
|
43
|
+
XCTFail("Expected the provider error to reject")
|
|
44
|
+
} catch {
|
|
45
|
+
XCTAssertEqual(error as? ProviderError, .unavailable)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -110,5 +110,7 @@ export interface ReactNativeDeviceUtils extends HybridObject<{
|
|
|
110
110
|
getAndClearRecoveryAction(): Promise<string>;
|
|
111
111
|
getAndroidChannel(): AndroidChannel;
|
|
112
112
|
getInstallerPackageName(): InstallerPackageName;
|
|
113
|
+
/** Returns an AdServices token on iOS 14.3+, or undefined on unsupported platforms. */
|
|
114
|
+
getAppleAdsAttributionToken(): Promise<string | undefined>;
|
|
113
115
|
}
|
|
114
116
|
//# sourceMappingURL=ReactNativeDeviceUtils.nitro.d.ts.map
|
|
@@ -422,5 +422,21 @@ namespace margelo::nitro::reactnativedeviceutils {
|
|
|
422
422
|
auto __result = method(_javaPart);
|
|
423
423
|
return __result->toCpp();
|
|
424
424
|
}
|
|
425
|
+
std::shared_ptr<Promise<std::optional<std::string>>> JHybridReactNativeDeviceUtilsSpec::getAppleAdsAttributionToken() {
|
|
426
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("getAppleAdsAttributionToken");
|
|
427
|
+
auto __result = method(_javaPart);
|
|
428
|
+
return [&]() {
|
|
429
|
+
auto __promise = Promise<std::optional<std::string>>::create();
|
|
430
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
431
|
+
auto __result = jni::static_ref_cast<jni::JString>(__boxedResult);
|
|
432
|
+
__promise->resolve(__result != nullptr ? std::make_optional(__result->toStdString()) : std::nullopt);
|
|
433
|
+
});
|
|
434
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
435
|
+
jni::JniException __jniError(__throwable);
|
|
436
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
437
|
+
});
|
|
438
|
+
return __promise;
|
|
439
|
+
}();
|
|
440
|
+
}
|
|
425
441
|
|
|
426
442
|
} // namespace margelo::nitro::reactnativedeviceutils
|
|
@@ -91,6 +91,7 @@ namespace margelo::nitro::reactnativedeviceutils {
|
|
|
91
91
|
std::shared_ptr<Promise<std::string>> getAndClearRecoveryAction() override;
|
|
92
92
|
AndroidChannel getAndroidChannel() override;
|
|
93
93
|
InstallerPackageName getInstallerPackageName() override;
|
|
94
|
+
std::shared_ptr<Promise<std::optional<std::string>>> getAppleAdsAttributionToken() override;
|
|
94
95
|
|
|
95
96
|
private:
|
|
96
97
|
jni::global_ref<JHybridReactNativeDeviceUtilsSpec::JavaPart> _javaPart;
|
|
@@ -192,6 +192,10 @@ abstract class HybridReactNativeDeviceUtilsSpec: HybridObject() {
|
|
|
192
192
|
@DoNotStrip
|
|
193
193
|
@Keep
|
|
194
194
|
abstract fun getInstallerPackageName(): InstallerPackageName
|
|
195
|
+
|
|
196
|
+
@DoNotStrip
|
|
197
|
+
@Keep
|
|
198
|
+
abstract fun getAppleAdsAttributionToken(): Promise<String?>
|
|
195
199
|
|
|
196
200
|
// Default implementation of `HybridObject.toString()`
|
|
197
201
|
override fun toString(): String {
|
|
@@ -110,6 +110,14 @@ namespace margelo::nitro::reactnativedeviceutils::bridge::swift {
|
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
112
|
|
|
113
|
+
// pragma MARK: std::function<void(const std::optional<std::string>& /* result */)>
|
|
114
|
+
Func_void_std__optional_std__string_ create_Func_void_std__optional_std__string_(void* NON_NULL swiftClosureWrapper) noexcept {
|
|
115
|
+
auto swiftClosure = ReactNativeDeviceUtils::Func_void_std__optional_std__string_::fromUnsafe(swiftClosureWrapper);
|
|
116
|
+
return [swiftClosure = std::move(swiftClosure)](const std::optional<std::string>& result) mutable -> void {
|
|
117
|
+
swiftClosure.call(result);
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
113
121
|
// pragma MARK: std::shared_ptr<HybridReactNativeDeviceUtilsSpec>
|
|
114
122
|
std::shared_ptr<HybridReactNativeDeviceUtilsSpec> create_std__shared_ptr_HybridReactNativeDeviceUtilsSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
|
|
115
123
|
ReactNativeDeviceUtils::HybridReactNativeDeviceUtilsSpec_cxx swiftPart = ReactNativeDeviceUtils::HybridReactNativeDeviceUtilsSpec_cxx::fromUnsafe(swiftUnsafePointer);
|
|
@@ -520,6 +520,40 @@ namespace margelo::nitro::reactnativedeviceutils::bridge::swift {
|
|
|
520
520
|
return Func_void_GooglePlayServicesStatus_Wrapper(std::move(value));
|
|
521
521
|
}
|
|
522
522
|
|
|
523
|
+
// pragma MARK: std::shared_ptr<Promise<std::optional<std::string>>>
|
|
524
|
+
/**
|
|
525
|
+
* Specialized version of `std::shared_ptr<Promise<std::optional<std::string>>>`.
|
|
526
|
+
*/
|
|
527
|
+
using std__shared_ptr_Promise_std__optional_std__string___ = std::shared_ptr<Promise<std::optional<std::string>>>;
|
|
528
|
+
inline std::shared_ptr<Promise<std::optional<std::string>>> create_std__shared_ptr_Promise_std__optional_std__string___() noexcept {
|
|
529
|
+
return Promise<std::optional<std::string>>::create();
|
|
530
|
+
}
|
|
531
|
+
inline PromiseHolder<std::optional<std::string>> wrap_std__shared_ptr_Promise_std__optional_std__string___(std::shared_ptr<Promise<std::optional<std::string>>> promise) noexcept {
|
|
532
|
+
return PromiseHolder<std::optional<std::string>>(std::move(promise));
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// pragma MARK: std::function<void(const std::optional<std::string>& /* result */)>
|
|
536
|
+
/**
|
|
537
|
+
* Specialized version of `std::function<void(const std::optional<std::string>&)>`.
|
|
538
|
+
*/
|
|
539
|
+
using Func_void_std__optional_std__string_ = std::function<void(const std::optional<std::string>& /* result */)>;
|
|
540
|
+
/**
|
|
541
|
+
* Wrapper class for a `std::function<void(const std::optional<std::string>& / * result * /)>`, this can be used from Swift.
|
|
542
|
+
*/
|
|
543
|
+
class Func_void_std__optional_std__string__Wrapper final {
|
|
544
|
+
public:
|
|
545
|
+
explicit Func_void_std__optional_std__string__Wrapper(std::function<void(const std::optional<std::string>& /* result */)>&& func): _function(std::make_unique<std::function<void(const std::optional<std::string>& /* result */)>>(std::move(func))) {}
|
|
546
|
+
inline void call(std::optional<std::string> result) const noexcept {
|
|
547
|
+
_function->operator()(result);
|
|
548
|
+
}
|
|
549
|
+
private:
|
|
550
|
+
std::unique_ptr<std::function<void(const std::optional<std::string>& /* result */)>> _function;
|
|
551
|
+
} SWIFT_NONCOPYABLE;
|
|
552
|
+
Func_void_std__optional_std__string_ create_Func_void_std__optional_std__string_(void* NON_NULL swiftClosureWrapper) noexcept;
|
|
553
|
+
inline Func_void_std__optional_std__string__Wrapper wrap_Func_void_std__optional_std__string_(Func_void_std__optional_std__string_ value) noexcept {
|
|
554
|
+
return Func_void_std__optional_std__string__Wrapper(std::move(value));
|
|
555
|
+
}
|
|
556
|
+
|
|
523
557
|
// pragma MARK: std::shared_ptr<HybridReactNativeDeviceUtilsSpec>
|
|
524
558
|
/**
|
|
525
559
|
* Specialized version of `std::shared_ptr<HybridReactNativeDeviceUtilsSpec>`.
|
|
@@ -675,5 +709,14 @@ namespace margelo::nitro::reactnativedeviceutils::bridge::swift {
|
|
|
675
709
|
inline Result_InstallerPackageName_ create_Result_InstallerPackageName_(const std::exception_ptr& error) noexcept {
|
|
676
710
|
return Result<InstallerPackageName>::withError(error);
|
|
677
711
|
}
|
|
712
|
+
|
|
713
|
+
// pragma MARK: Result<std::shared_ptr<Promise<std::optional<std::string>>>>
|
|
714
|
+
using Result_std__shared_ptr_Promise_std__optional_std__string____ = Result<std::shared_ptr<Promise<std::optional<std::string>>>>;
|
|
715
|
+
inline Result_std__shared_ptr_Promise_std__optional_std__string____ create_Result_std__shared_ptr_Promise_std__optional_std__string____(const std::shared_ptr<Promise<std::optional<std::string>>>& value) noexcept {
|
|
716
|
+
return Result<std::shared_ptr<Promise<std::optional<std::string>>>>::withValue(value);
|
|
717
|
+
}
|
|
718
|
+
inline Result_std__shared_ptr_Promise_std__optional_std__string____ create_Result_std__shared_ptr_Promise_std__optional_std__string____(const std::exception_ptr& error) noexcept {
|
|
719
|
+
return Result<std::shared_ptr<Promise<std::optional<std::string>>>>::withError(error);
|
|
720
|
+
}
|
|
678
721
|
|
|
679
722
|
} // namespace margelo::nitro::reactnativedeviceutils::bridge::swift
|
|
@@ -373,6 +373,14 @@ namespace margelo::nitro::reactnativedeviceutils {
|
|
|
373
373
|
auto __value = std::move(__result.value());
|
|
374
374
|
return __value;
|
|
375
375
|
}
|
|
376
|
+
inline std::shared_ptr<Promise<std::optional<std::string>>> getAppleAdsAttributionToken() override {
|
|
377
|
+
auto __result = _swiftPart.getAppleAdsAttributionToken();
|
|
378
|
+
if (__result.hasError()) [[unlikely]] {
|
|
379
|
+
std::rethrow_exception(__result.error());
|
|
380
|
+
}
|
|
381
|
+
auto __value = std::move(__result.value());
|
|
382
|
+
return __value;
|
|
383
|
+
}
|
|
376
384
|
|
|
377
385
|
private:
|
|
378
386
|
ReactNativeDeviceUtils::HybridReactNativeDeviceUtilsSpec_cxx _swiftPart;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_std__optional_std__string_.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
import NitroModules
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Wraps a Swift `(_ value: String?) -> Void` as a class.
|
|
12
|
+
* This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
|
|
13
|
+
*/
|
|
14
|
+
public final class Func_void_std__optional_std__string_ {
|
|
15
|
+
public typealias bridge = margelo.nitro.reactnativedeviceutils.bridge.swift
|
|
16
|
+
|
|
17
|
+
private let closure: (_ value: String?) -> Void
|
|
18
|
+
|
|
19
|
+
public init(_ closure: @escaping (_ value: String?) -> Void) {
|
|
20
|
+
self.closure = closure
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
@inline(__always)
|
|
24
|
+
public func call(value: bridge.std__optional_std__string_) -> Void {
|
|
25
|
+
self.closure({ () -> String? in
|
|
26
|
+
if bridge.has_value_std__optional_std__string_(value) {
|
|
27
|
+
let __unwrapped = bridge.get_std__optional_std__string_(value)
|
|
28
|
+
return String(__unwrapped)
|
|
29
|
+
} else {
|
|
30
|
+
return nil
|
|
31
|
+
}
|
|
32
|
+
}())
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Casts this instance to a retained unsafe raw pointer.
|
|
37
|
+
* This acquires one additional strong reference on the object!
|
|
38
|
+
*/
|
|
39
|
+
@inline(__always)
|
|
40
|
+
public func toUnsafe() -> UnsafeMutableRawPointer {
|
|
41
|
+
return Unmanaged.passRetained(self).toOpaque()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Casts an unsafe pointer to a `Func_void_std__optional_std__string_`.
|
|
46
|
+
* The pointer has to be a retained opaque `Unmanaged<Func_void_std__optional_std__string_>`.
|
|
47
|
+
* This removes one strong reference from the object!
|
|
48
|
+
*/
|
|
49
|
+
@inline(__always)
|
|
50
|
+
public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__optional_std__string_ {
|
|
51
|
+
return Unmanaged<Func_void_std__optional_std__string_>.fromOpaque(pointer).takeRetainedValue()
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -50,6 +50,7 @@ public protocol HybridReactNativeDeviceUtilsSpec_protocol: HybridObject {
|
|
|
50
50
|
func getAndClearRecoveryAction() throws -> Promise<String>
|
|
51
51
|
func getAndroidChannel() throws -> AndroidChannel
|
|
52
52
|
func getInstallerPackageName() throws -> InstallerPackageName
|
|
53
|
+
func getAppleAdsAttributionToken() throws -> Promise<String?>
|
|
53
54
|
}
|
|
54
55
|
|
|
55
56
|
public extension HybridReactNativeDeviceUtilsSpec_protocol {
|
|
@@ -711,4 +711,29 @@ open class HybridReactNativeDeviceUtilsSpec_cxx {
|
|
|
711
711
|
return bridge.create_Result_InstallerPackageName_(__exceptionPtr)
|
|
712
712
|
}
|
|
713
713
|
}
|
|
714
|
+
|
|
715
|
+
@inline(__always)
|
|
716
|
+
public final func getAppleAdsAttributionToken() -> bridge.Result_std__shared_ptr_Promise_std__optional_std__string____ {
|
|
717
|
+
do {
|
|
718
|
+
let __result = try self.__implementation.getAppleAdsAttributionToken()
|
|
719
|
+
let __resultCpp = { () -> bridge.std__shared_ptr_Promise_std__optional_std__string___ in
|
|
720
|
+
let __promise = bridge.create_std__shared_ptr_Promise_std__optional_std__string___()
|
|
721
|
+
let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__optional_std__string___(__promise)
|
|
722
|
+
__result
|
|
723
|
+
.then({ __result in __promiseHolder.resolve({ () -> bridge.std__optional_std__string_ in
|
|
724
|
+
if let __unwrappedValue = __result {
|
|
725
|
+
return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
|
|
726
|
+
} else {
|
|
727
|
+
return .init()
|
|
728
|
+
}
|
|
729
|
+
}()) })
|
|
730
|
+
.catch({ __error in __promiseHolder.reject(__error.toCpp()) })
|
|
731
|
+
return __promise
|
|
732
|
+
}()
|
|
733
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__optional_std__string____(__resultCpp)
|
|
734
|
+
} catch (let __error) {
|
|
735
|
+
let __exceptionPtr = __error.toCpp()
|
|
736
|
+
return bridge.create_Result_std__shared_ptr_Promise_std__optional_std__string____(__exceptionPtr)
|
|
737
|
+
}
|
|
738
|
+
}
|
|
714
739
|
}
|
|
@@ -51,6 +51,7 @@ namespace margelo::nitro::reactnativedeviceutils {
|
|
|
51
51
|
prototype.registerHybridMethod("getAndClearRecoveryAction", &HybridReactNativeDeviceUtilsSpec::getAndClearRecoveryAction);
|
|
52
52
|
prototype.registerHybridMethod("getAndroidChannel", &HybridReactNativeDeviceUtilsSpec::getAndroidChannel);
|
|
53
53
|
prototype.registerHybridMethod("getInstallerPackageName", &HybridReactNativeDeviceUtilsSpec::getInstallerPackageName);
|
|
54
|
+
prototype.registerHybridMethod("getAppleAdsAttributionToken", &HybridReactNativeDeviceUtilsSpec::getAppleAdsAttributionToken);
|
|
54
55
|
});
|
|
55
56
|
}
|
|
56
57
|
|
|
@@ -119,6 +119,7 @@ namespace margelo::nitro::reactnativedeviceutils {
|
|
|
119
119
|
virtual std::shared_ptr<Promise<std::string>> getAndClearRecoveryAction() = 0;
|
|
120
120
|
virtual AndroidChannel getAndroidChannel() = 0;
|
|
121
121
|
virtual InstallerPackageName getInstallerPackageName() = 0;
|
|
122
|
+
virtual std::shared_ptr<Promise<std::optional<std::string>>> getAppleAdsAttributionToken() = 0;
|
|
122
123
|
|
|
123
124
|
protected:
|
|
124
125
|
// Hybrid Setup
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-device-utils",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.8.0-11",
|
|
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"
|
|
@@ -156,4 +156,7 @@ export interface ReactNativeDeviceUtils
|
|
|
156
156
|
// Android Channel & Installer
|
|
157
157
|
getAndroidChannel(): AndroidChannel;
|
|
158
158
|
getInstallerPackageName(): InstallerPackageName;
|
|
159
|
+
|
|
160
|
+
/** Returns an AdServices token on iOS 14.3+, or undefined on unsupported platforms. */
|
|
161
|
+
getAppleAdsAttributionToken(): Promise<string | undefined>;
|
|
159
162
|
}
|