@onekeyfe/react-native-device-utils 6.8.0-alpha.514 → 6.8.0-alpha.538
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.
|
@@ -18,6 +18,7 @@ Pod::Spec.new do |s|
|
|
|
18
18
|
"ios/**/*.{m,mm}",
|
|
19
19
|
"cpp/**/*.{hpp,cpp}",
|
|
20
20
|
]
|
|
21
|
+
s.exclude_files = "ios/tests/**/*"
|
|
21
22
|
s.frameworks = "AdServices"
|
|
22
23
|
|
|
23
24
|
s.dependency 'React-jsi'
|
|
@@ -28,4 +29,8 @@ Pod::Spec.new do |s|
|
|
|
28
29
|
add_nitrogen_files(s)
|
|
29
30
|
|
|
30
31
|
install_modules_dependencies(s)
|
|
32
|
+
|
|
33
|
+
s.test_spec "Tests" do |test_spec|
|
|
34
|
+
test_spec.source_files = "ios/tests/**/*.swift"
|
|
35
|
+
end
|
|
31
36
|
end
|
|
@@ -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? {
|
|
@@ -367,10 +367,19 @@ class ReactNativeDeviceUtils: HybridReactNativeDeviceUtilsSpec {
|
|
|
367
367
|
}
|
|
368
368
|
|
|
369
369
|
func getAppleAdsAttributionToken() throws -> Promise<String?> {
|
|
370
|
-
|
|
371
|
-
|
|
370
|
+
guard #available(iOS 14.3, *) else {
|
|
371
|
+
return .resolved(withResult: nil)
|
|
372
|
+
}
|
|
373
|
+
return Self.requestAppleAdsAttributionToken {
|
|
374
|
+
try AAAttribution.attributionToken()
|
|
375
|
+
}
|
|
376
|
+
}
|
|
372
377
|
|
|
373
|
-
|
|
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()
|
|
374
383
|
guard !token.isEmpty else {
|
|
375
384
|
throw RuntimeError.error(withMessage: "AdServices returned an empty attribution token")
|
|
376
385
|
}
|
|
@@ -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
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@onekeyfe/react-native-device-utils",
|
|
3
|
-
"version": "6.8.0-alpha.
|
|
3
|
+
"version": "6.8.0-alpha.538",
|
|
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",
|