@onekeyfe/react-native-device-utils 1.1.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.
Files changed (55) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +36 -0
  3. package/ReactNativeDeviceUtils.podspec +29 -0
  4. package/android/CMakeLists.txt +24 -0
  5. package/android/build.gradle +132 -0
  6. package/android/gradle.properties +4 -0
  7. package/android/src/main/AndroidManifest.xml +1 -0
  8. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  9. package/android/src/main/java/com/margelo/nitro/reactnativedeviceutils/ReactNativeDeviceUtils.kt +343 -0
  10. package/android/src/main/java/com/margelo/nitro/reactnativedeviceutils/ReactNativeDeviceUtilsPackage.kt +26 -0
  11. package/ios/ReactNativeDeviceUtils.swift +41 -0
  12. package/lib/module/ReactNativeDeviceUtils.nitro.js +4 -0
  13. package/lib/module/ReactNativeDeviceUtils.nitro.js.map +1 -0
  14. package/lib/module/index.js +6 -0
  15. package/lib/module/index.js.map +1 -0
  16. package/lib/module/package.json +1 -0
  17. package/lib/typescript/package.json +1 -0
  18. package/lib/typescript/src/ReactNativeDeviceUtils.nitro.d.ts +21 -0
  19. package/lib/typescript/src/ReactNativeDeviceUtils.nitro.d.ts.map +1 -0
  20. package/lib/typescript/src/index.d.ts +4 -0
  21. package/lib/typescript/src/index.d.ts.map +1 -0
  22. package/nitro.json +17 -0
  23. package/nitrogen/generated/android/c++/JDualScreenInfoRect.hpp +69 -0
  24. package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
  25. package/nitrogen/generated/android/c++/JHybridReactNativeDeviceUtilsSpec.cpp +123 -0
  26. package/nitrogen/generated/android/c++/JHybridReactNativeDeviceUtilsSpec.hpp +72 -0
  27. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/DualScreenInfoRect.kt +47 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/Func_void_bool.kt +80 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/HybridReactNativeDeviceUtilsSpec.kt +91 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/reactnativedeviceutilsOnLoad.kt +35 -0
  31. package/nitrogen/generated/android/reactnativedeviceutils+autolinking.cmake +81 -0
  32. package/nitrogen/generated/android/reactnativedeviceutils+autolinking.gradle +27 -0
  33. package/nitrogen/generated/android/reactnativedeviceutilsOnLoad.cpp +46 -0
  34. package/nitrogen/generated/android/reactnativedeviceutilsOnLoad.hpp +25 -0
  35. package/nitrogen/generated/ios/ReactNativeDeviceUtils+autolinking.rb +60 -0
  36. package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Bridge.cpp +65 -0
  37. package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Bridge.hpp +217 -0
  38. package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Umbrella.hpp +49 -0
  39. package/nitrogen/generated/ios/ReactNativeDeviceUtilsAutolinking.mm +33 -0
  40. package/nitrogen/generated/ios/ReactNativeDeviceUtilsAutolinking.swift +25 -0
  41. package/nitrogen/generated/ios/c++/HybridReactNativeDeviceUtilsSpecSwift.cpp +11 -0
  42. package/nitrogen/generated/ios/c++/HybridReactNativeDeviceUtilsSpecSwift.hpp +130 -0
  43. package/nitrogen/generated/ios/swift/DualScreenInfoRect.swift +69 -0
  44. package/nitrogen/generated/ios/swift/Func_void_DualScreenInfoRect.swift +47 -0
  45. package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
  46. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
  47. package/nitrogen/generated/ios/swift/Func_void_std__vector_DualScreenInfoRect_.swift +47 -0
  48. package/nitrogen/generated/ios/swift/HybridReactNativeDeviceUtilsSpec.swift +63 -0
  49. package/nitrogen/generated/ios/swift/HybridReactNativeDeviceUtilsSpec_cxx.swift +237 -0
  50. package/nitrogen/generated/shared/c++/DualScreenInfoRect.hpp +87 -0
  51. package/nitrogen/generated/shared/c++/HybridReactNativeDeviceUtilsSpec.cpp +28 -0
  52. package/nitrogen/generated/shared/c++/HybridReactNativeDeviceUtilsSpec.hpp +73 -0
  53. package/package.json +170 -0
  54. package/src/ReactNativeDeviceUtils.nitro.ts +21 -0
  55. package/src/index.tsx +8 -0
@@ -0,0 +1,87 @@
1
+ ///
2
+ /// DualScreenInfoRect.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+
27
+
28
+
29
+
30
+ namespace margelo::nitro::reactnativedeviceutils {
31
+
32
+ /**
33
+ * A struct which can be represented as a JavaScript object (DualScreenInfoRect).
34
+ */
35
+ struct DualScreenInfoRect {
36
+ public:
37
+ double x SWIFT_PRIVATE;
38
+ double y SWIFT_PRIVATE;
39
+ double width SWIFT_PRIVATE;
40
+ double height SWIFT_PRIVATE;
41
+
42
+ public:
43
+ DualScreenInfoRect() = default;
44
+ explicit DualScreenInfoRect(double x, double y, double width, double height): x(x), y(y), width(width), height(height) {}
45
+ };
46
+
47
+ } // namespace margelo::nitro::reactnativedeviceutils
48
+
49
+ namespace margelo::nitro {
50
+
51
+ // C++ DualScreenInfoRect <> JS DualScreenInfoRect (object)
52
+ template <>
53
+ struct JSIConverter<margelo::nitro::reactnativedeviceutils::DualScreenInfoRect> final {
54
+ static inline margelo::nitro::reactnativedeviceutils::DualScreenInfoRect fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
55
+ jsi::Object obj = arg.asObject(runtime);
56
+ return margelo::nitro::reactnativedeviceutils::DualScreenInfoRect(
57
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "x")),
58
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "y")),
59
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "width")),
60
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "height"))
61
+ );
62
+ }
63
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::reactnativedeviceutils::DualScreenInfoRect& arg) {
64
+ jsi::Object obj(runtime);
65
+ obj.setProperty(runtime, "x", JSIConverter<double>::toJSI(runtime, arg.x));
66
+ obj.setProperty(runtime, "y", JSIConverter<double>::toJSI(runtime, arg.y));
67
+ obj.setProperty(runtime, "width", JSIConverter<double>::toJSI(runtime, arg.width));
68
+ obj.setProperty(runtime, "height", JSIConverter<double>::toJSI(runtime, arg.height));
69
+ return obj;
70
+ }
71
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
72
+ if (!value.isObject()) {
73
+ return false;
74
+ }
75
+ jsi::Object obj = value.getObject(runtime);
76
+ if (!nitro::isPlainObject(runtime, obj)) {
77
+ return false;
78
+ }
79
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "x"))) return false;
80
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "y"))) return false;
81
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "width"))) return false;
82
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "height"))) return false;
83
+ return true;
84
+ }
85
+ };
86
+
87
+ } // namespace margelo::nitro
@@ -0,0 +1,28 @@
1
+ ///
2
+ /// HybridReactNativeDeviceUtilsSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "HybridReactNativeDeviceUtilsSpec.hpp"
9
+
10
+ namespace margelo::nitro::reactnativedeviceutils {
11
+
12
+ void HybridReactNativeDeviceUtilsSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("initEventListeners", &HybridReactNativeDeviceUtilsSpec::initEventListeners);
18
+ prototype.registerHybridMethod("isDualScreenDevice", &HybridReactNativeDeviceUtilsSpec::isDualScreenDevice);
19
+ prototype.registerHybridMethod("isSpanning", &HybridReactNativeDeviceUtilsSpec::isSpanning);
20
+ prototype.registerHybridMethod("getWindowRects", &HybridReactNativeDeviceUtilsSpec::getWindowRects);
21
+ prototype.registerHybridMethod("getHingeBounds", &HybridReactNativeDeviceUtilsSpec::getHingeBounds);
22
+ prototype.registerHybridMethod("changeBackgroundColor", &HybridReactNativeDeviceUtilsSpec::changeBackgroundColor);
23
+ prototype.registerHybridMethod("addSpanningChangedListener", &HybridReactNativeDeviceUtilsSpec::addSpanningChangedListener);
24
+ prototype.registerHybridMethod("removeSpanningChangedListener", &HybridReactNativeDeviceUtilsSpec::removeSpanningChangedListener);
25
+ });
26
+ }
27
+
28
+ } // namespace margelo::nitro::reactnativedeviceutils
@@ -0,0 +1,73 @@
1
+ ///
2
+ /// HybridReactNativeDeviceUtilsSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `DualScreenInfoRect` to properly resolve imports.
17
+ namespace margelo::nitro::reactnativedeviceutils { struct DualScreenInfoRect; }
18
+
19
+ #include "DualScreenInfoRect.hpp"
20
+ #include <vector>
21
+ #include <NitroModules/Promise.hpp>
22
+ #include <functional>
23
+
24
+ namespace margelo::nitro::reactnativedeviceutils {
25
+
26
+ using namespace margelo::nitro;
27
+
28
+ /**
29
+ * An abstract base class for `ReactNativeDeviceUtils`
30
+ * Inherit this class to create instances of `HybridReactNativeDeviceUtilsSpec` in C++.
31
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
32
+ * @example
33
+ * ```cpp
34
+ * class HybridReactNativeDeviceUtils: public HybridReactNativeDeviceUtilsSpec {
35
+ * public:
36
+ * HybridReactNativeDeviceUtils(...): HybridObject(TAG) { ... }
37
+ * // ...
38
+ * };
39
+ * ```
40
+ */
41
+ class HybridReactNativeDeviceUtilsSpec: public virtual HybridObject {
42
+ public:
43
+ // Constructor
44
+ explicit HybridReactNativeDeviceUtilsSpec(): HybridObject(TAG) { }
45
+
46
+ // Destructor
47
+ ~HybridReactNativeDeviceUtilsSpec() override = default;
48
+
49
+ public:
50
+ // Properties
51
+
52
+
53
+ public:
54
+ // Methods
55
+ virtual void initEventListeners() = 0;
56
+ virtual bool isDualScreenDevice() = 0;
57
+ virtual bool isSpanning() = 0;
58
+ virtual std::shared_ptr<Promise<std::vector<DualScreenInfoRect>>> getWindowRects() = 0;
59
+ virtual std::shared_ptr<Promise<DualScreenInfoRect>> getHingeBounds() = 0;
60
+ virtual void changeBackgroundColor(double r, double g, double b, double a) = 0;
61
+ virtual double addSpanningChangedListener(const std::function<void(bool /* isSpanning */)>& callback) = 0;
62
+ virtual void removeSpanningChangedListener(double id) = 0;
63
+
64
+ protected:
65
+ // Hybrid Setup
66
+ void loadHybridMethods() override;
67
+
68
+ protected:
69
+ // Tag for logging
70
+ static constexpr auto TAG = "ReactNativeDeviceUtils";
71
+ };
72
+
73
+ } // namespace margelo::nitro::reactnativedeviceutils
package/package.json ADDED
@@ -0,0 +1,170 @@
1
+ {
2
+ "name": "@onekeyfe/react-native-device-utils",
3
+ "version": "1.1.11",
4
+ "description": "react-native-device-utils",
5
+ "main": "./lib/module/index.js",
6
+ "types": "./lib/typescript/src/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "source": "./src/index.tsx",
10
+ "types": "./lib/typescript/src/index.d.ts",
11
+ "default": "./lib/module/index.js"
12
+ },
13
+ "./package.json": "./package.json"
14
+ },
15
+ "files": [
16
+ "src",
17
+ "lib",
18
+ "android",
19
+ "ios",
20
+ "cpp",
21
+ "nitrogen",
22
+ "nitro.json",
23
+ "*.podspec",
24
+ "react-native.config.js",
25
+ "!ios/build",
26
+ "!android/build",
27
+ "!android/gradle",
28
+ "!android/gradlew",
29
+ "!android/gradlew.bat",
30
+ "!android/local.properties",
31
+ "!**/__tests__",
32
+ "!**/__fixtures__",
33
+ "!**/__mocks__",
34
+ "!**/.*"
35
+ ],
36
+ "scripts": {
37
+ "example": "yarn workspace react-native-device-utils-example",
38
+ "clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
39
+ "prepare": "bob build",
40
+ "nitrogen": "nitrogen",
41
+ "typecheck": "tsc",
42
+ "lint": "eslint \"**/*.{js,ts,tsx}\"",
43
+ "test": "jest",
44
+ "release": "yarn prepare && npm whoami && npm publish --access public"
45
+ },
46
+ "keywords": [
47
+ "react-native",
48
+ "ios",
49
+ "android"
50
+ ],
51
+ "repository": {
52
+ "type": "git",
53
+ "url": "git+https://github.com/OneKeyHQ/app-modules/react-native-device-utils.git"
54
+ },
55
+ "author": "onekeyfe <huanming@onekey.so> (https://github.com/OneKeyHQ/app-modules)",
56
+ "license": "MIT",
57
+ "bugs": {
58
+ "url": "https://github.com/OneKeyHQ/app-modules/react-native-device-utils/issues"
59
+ },
60
+ "homepage": "https://github.com/OneKeyHQ/app-modules/react-native-device-utils#readme",
61
+ "publishConfig": {
62
+ "registry": "https://registry.npmjs.org/"
63
+ },
64
+ "devDependencies": {
65
+ "@commitlint/config-conventional": "^19.8.1",
66
+ "@eslint/compat": "^1.3.2",
67
+ "@eslint/eslintrc": "^3.3.1",
68
+ "@eslint/js": "^9.35.0",
69
+ "@react-native/babel-preset": "0.83.0",
70
+ "@react-native/eslint-config": "0.83.0",
71
+ "@release-it/conventional-changelog": "^10.0.1",
72
+ "@types/jest": "^29.5.14",
73
+ "@types/react": "^19.2.0",
74
+ "commitlint": "^19.8.1",
75
+ "del-cli": "^6.0.0",
76
+ "eslint": "^9.35.0",
77
+ "eslint-config-prettier": "^10.1.8",
78
+ "eslint-plugin-prettier": "^5.5.4",
79
+ "jest": "^29.7.0",
80
+ "lefthook": "^2.0.3",
81
+ "nitrogen": "^0.31.10",
82
+ "prettier": "^2.8.8",
83
+ "react": "19.2.0",
84
+ "react-native": "0.83.0",
85
+ "react-native-builder-bob": "^0.40.13",
86
+ "react-native-nitro-modules": "^0.31.10",
87
+ "release-it": "^19.0.4",
88
+ "turbo": "^2.5.6",
89
+ "typescript": "^5.9.2"
90
+ },
91
+ "peerDependencies": {
92
+ "react": "*",
93
+ "react-native": "*",
94
+ "react-native-nitro-modules": "^0.31.10"
95
+ },
96
+ "react-native-builder-bob": {
97
+ "source": "src",
98
+ "output": "lib",
99
+ "targets": [
100
+ [
101
+ "custom",
102
+ {
103
+ "script": "nitrogen",
104
+ "clean": "nitrogen/"
105
+ }
106
+ ],
107
+ [
108
+ "module",
109
+ {
110
+ "esm": true
111
+ }
112
+ ],
113
+ [
114
+ "typescript",
115
+ {
116
+ "project": "tsconfig.build.json"
117
+ }
118
+ ]
119
+ ]
120
+ },
121
+ "prettier": {
122
+ "quoteProps": "consistent",
123
+ "singleQuote": true,
124
+ "tabWidth": 2,
125
+ "trailingComma": "es5",
126
+ "useTabs": false
127
+ },
128
+ "jest": {
129
+ "preset": "react-native",
130
+ "modulePathIgnorePatterns": [
131
+ "<rootDir>/example/node_modules",
132
+ "<rootDir>/lib/"
133
+ ]
134
+ },
135
+ "commitlint": {
136
+ "extends": [
137
+ "@commitlint/config-conventional"
138
+ ]
139
+ },
140
+ "release-it": {
141
+ "git": {
142
+ "commitMessage": "chore: release ${version}",
143
+ "tagName": "v${version}"
144
+ },
145
+ "npm": {
146
+ "publish": true
147
+ },
148
+ "github": {
149
+ "release": true
150
+ },
151
+ "plugins": {
152
+ "@release-it/conventional-changelog": {
153
+ "preset": {
154
+ "name": "angular"
155
+ }
156
+ }
157
+ }
158
+ },
159
+ "create-react-native-library": {
160
+ "type": "nitro-module",
161
+ "languages": "kotlin-swift",
162
+ "tools": [
163
+ "eslint",
164
+ "jest",
165
+ "lefthook",
166
+ "release-it"
167
+ ],
168
+ "version": "0.56.0"
169
+ }
170
+ }
@@ -0,0 +1,21 @@
1
+ import type { HybridObject } from 'react-native-nitro-modules';
2
+
3
+
4
+ export interface DualScreenInfoRect {
5
+ x: number;
6
+ y: number;
7
+ width: number;
8
+ height: number;
9
+ }
10
+
11
+ export interface ReactNativeDeviceUtils
12
+ extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
13
+ initEventListeners(): void;
14
+ isDualScreenDevice(): boolean;
15
+ isSpanning(): boolean;
16
+ getWindowRects(): Promise<DualScreenInfoRect[]>;
17
+ getHingeBounds(): Promise<DualScreenInfoRect>;
18
+ changeBackgroundColor(r: number, g: number, b: number, a: number): void;
19
+ addSpanningChangedListener(callback: (isSpanning: boolean) => void): number;
20
+ removeSpanningChangedListener(id: number): void;
21
+ }
package/src/index.tsx ADDED
@@ -0,0 +1,8 @@
1
+ import { NitroModules } from 'react-native-nitro-modules';
2
+ import type { ReactNativeDeviceUtils as ReactNativeDeviceUtilsType } from './ReactNativeDeviceUtils.nitro';
3
+
4
+ const ReactNativeDeviceUtilsHybridObject =
5
+ NitroModules.createHybridObject<ReactNativeDeviceUtilsType>('ReactNativeDeviceUtils');
6
+
7
+ export const ReactNativeDeviceUtils = ReactNativeDeviceUtilsHybridObject;
8
+ export type * from './ReactNativeDeviceUtils.nitro';