@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.
- package/LICENSE +21 -0
- package/README.md +36 -0
- package/ReactNativeDeviceUtils.podspec +29 -0
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +132 -0
- package/android/gradle.properties +4 -0
- package/android/src/main/AndroidManifest.xml +1 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/reactnativedeviceutils/ReactNativeDeviceUtils.kt +343 -0
- package/android/src/main/java/com/margelo/nitro/reactnativedeviceutils/ReactNativeDeviceUtilsPackage.kt +26 -0
- package/ios/ReactNativeDeviceUtils.swift +41 -0
- package/lib/module/ReactNativeDeviceUtils.nitro.js +4 -0
- package/lib/module/ReactNativeDeviceUtils.nitro.js.map +1 -0
- package/lib/module/index.js +6 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/ReactNativeDeviceUtils.nitro.d.ts +21 -0
- package/lib/typescript/src/ReactNativeDeviceUtils.nitro.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +4 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/nitro.json +17 -0
- package/nitrogen/generated/android/c++/JDualScreenInfoRect.hpp +69 -0
- package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeDeviceUtilsSpec.cpp +123 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeDeviceUtilsSpec.hpp +72 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/DualScreenInfoRect.kt +47 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/Func_void_bool.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/HybridReactNativeDeviceUtilsSpec.kt +91 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/reactnativedeviceutilsOnLoad.kt +35 -0
- package/nitrogen/generated/android/reactnativedeviceutils+autolinking.cmake +81 -0
- package/nitrogen/generated/android/reactnativedeviceutils+autolinking.gradle +27 -0
- package/nitrogen/generated/android/reactnativedeviceutilsOnLoad.cpp +46 -0
- package/nitrogen/generated/android/reactnativedeviceutilsOnLoad.hpp +25 -0
- package/nitrogen/generated/ios/ReactNativeDeviceUtils+autolinking.rb +60 -0
- package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Bridge.cpp +65 -0
- package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Bridge.hpp +217 -0
- package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Umbrella.hpp +49 -0
- package/nitrogen/generated/ios/ReactNativeDeviceUtilsAutolinking.mm +33 -0
- package/nitrogen/generated/ios/ReactNativeDeviceUtilsAutolinking.swift +25 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeDeviceUtilsSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeDeviceUtilsSpecSwift.hpp +130 -0
- package/nitrogen/generated/ios/swift/DualScreenInfoRect.swift +69 -0
- package/nitrogen/generated/ios/swift/Func_void_DualScreenInfoRect.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
- package/nitrogen/generated/ios/swift/Func_void_std__vector_DualScreenInfoRect_.swift +47 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeDeviceUtilsSpec.swift +63 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeDeviceUtilsSpec_cxx.swift +237 -0
- package/nitrogen/generated/shared/c++/DualScreenInfoRect.hpp +87 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeDeviceUtilsSpec.cpp +28 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeDeviceUtilsSpec.hpp +73 -0
- package/package.json +170 -0
- package/src/ReactNativeDeviceUtils.nitro.ts +21 -0
- package/src/index.tsx +8 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
export interface DualScreenInfoRect {
|
|
3
|
+
x: number;
|
|
4
|
+
y: number;
|
|
5
|
+
width: number;
|
|
6
|
+
height: number;
|
|
7
|
+
}
|
|
8
|
+
export interface ReactNativeDeviceUtils extends HybridObject<{
|
|
9
|
+
ios: 'swift';
|
|
10
|
+
android: 'kotlin';
|
|
11
|
+
}> {
|
|
12
|
+
initEventListeners(): void;
|
|
13
|
+
isDualScreenDevice(): boolean;
|
|
14
|
+
isSpanning(): boolean;
|
|
15
|
+
getWindowRects(): Promise<DualScreenInfoRect[]>;
|
|
16
|
+
getHingeBounds(): Promise<DualScreenInfoRect>;
|
|
17
|
+
changeBackgroundColor(r: number, g: number, b: number, a: number): void;
|
|
18
|
+
addSpanningChangedListener(callback: (isSpanning: boolean) => void): number;
|
|
19
|
+
removeSpanningChangedListener(id: number): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=ReactNativeDeviceUtils.nitro.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ReactNativeDeviceUtils.nitro.d.ts","sourceRoot":"","sources":["../../../src/ReactNativeDeviceUtils.nitro.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAG/D,MAAM,WAAW,kBAAkB;IACjC,CAAC,EAAE,MAAM,CAAC;IACV,CAAC,EAAE,MAAM,CAAC;IACV,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,sBACf,SAAQ,YAAY,CAAC;IAAE,GAAG,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,QAAQ,CAAA;CAAE,CAAC;IACzD,kBAAkB,IAAI,IAAI,CAAC;IAC3B,kBAAkB,IAAI,OAAO,CAAC;IAC9B,UAAU,IAAI,OAAO,CAAC;IACtB,cAAc,IAAI,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;IAChD,cAAc,IAAI,OAAO,CAAC,kBAAkB,CAAC,CAAC;IAC9C,qBAAqB,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxE,0BAA0B,CAAC,QAAQ,EAAE,CAAC,UAAU,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,CAAC;IAC5E,6BAA6B,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAC;CACjD"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { ReactNativeDeviceUtils as ReactNativeDeviceUtilsType } from './ReactNativeDeviceUtils.nitro';
|
|
2
|
+
export declare const ReactNativeDeviceUtils: ReactNativeDeviceUtilsType;
|
|
3
|
+
export type * from './ReactNativeDeviceUtils.nitro';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,IAAI,0BAA0B,EAAE,MAAM,gCAAgC,CAAC;AAK3G,eAAO,MAAM,sBAAsB,4BAAqC,CAAC;AACzE,mBAAmB,gCAAgC,CAAC"}
|
package/nitro.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"cxxNamespace": ["reactnativedeviceutils"],
|
|
3
|
+
"ios": {
|
|
4
|
+
"iosModuleName": "ReactNativeDeviceUtils"
|
|
5
|
+
},
|
|
6
|
+
"android": {
|
|
7
|
+
"androidNamespace": ["reactnativedeviceutils"],
|
|
8
|
+
"androidCxxLibName": "reactnativedeviceutils"
|
|
9
|
+
},
|
|
10
|
+
"autolinking": {
|
|
11
|
+
"ReactNativeDeviceUtils": {
|
|
12
|
+
"swift": "ReactNativeDeviceUtils",
|
|
13
|
+
"kotlin": "ReactNativeDeviceUtils"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"ignorePaths": ["node_modules"]
|
|
17
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JDualScreenInfoRect.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
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include "DualScreenInfoRect.hpp"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
namespace margelo::nitro::reactnativedeviceutils {
|
|
16
|
+
|
|
17
|
+
using namespace facebook;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The C++ JNI bridge between the C++ struct "DualScreenInfoRect" and the the Kotlin data class "DualScreenInfoRect".
|
|
21
|
+
*/
|
|
22
|
+
struct JDualScreenInfoRect final: public jni::JavaClass<JDualScreenInfoRect> {
|
|
23
|
+
public:
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/reactnativedeviceutils/DualScreenInfoRect;";
|
|
25
|
+
|
|
26
|
+
public:
|
|
27
|
+
/**
|
|
28
|
+
* Convert this Java/Kotlin-based struct to the C++ struct DualScreenInfoRect by copying all values to C++.
|
|
29
|
+
*/
|
|
30
|
+
[[maybe_unused]]
|
|
31
|
+
[[nodiscard]]
|
|
32
|
+
DualScreenInfoRect toCpp() const {
|
|
33
|
+
static const auto clazz = javaClassStatic();
|
|
34
|
+
static const auto fieldX = clazz->getField<double>("x");
|
|
35
|
+
double x = this->getFieldValue(fieldX);
|
|
36
|
+
static const auto fieldY = clazz->getField<double>("y");
|
|
37
|
+
double y = this->getFieldValue(fieldY);
|
|
38
|
+
static const auto fieldWidth = clazz->getField<double>("width");
|
|
39
|
+
double width = this->getFieldValue(fieldWidth);
|
|
40
|
+
static const auto fieldHeight = clazz->getField<double>("height");
|
|
41
|
+
double height = this->getFieldValue(fieldHeight);
|
|
42
|
+
return DualScreenInfoRect(
|
|
43
|
+
x,
|
|
44
|
+
y,
|
|
45
|
+
width,
|
|
46
|
+
height
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
/**
|
|
52
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
53
|
+
*/
|
|
54
|
+
[[maybe_unused]]
|
|
55
|
+
static jni::local_ref<JDualScreenInfoRect::javaobject> fromCpp(const DualScreenInfoRect& value) {
|
|
56
|
+
using JSignature = JDualScreenInfoRect(double, double, double, double);
|
|
57
|
+
static const auto clazz = javaClassStatic();
|
|
58
|
+
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
59
|
+
return create(
|
|
60
|
+
clazz,
|
|
61
|
+
value.x,
|
|
62
|
+
value.y,
|
|
63
|
+
value.width,
|
|
64
|
+
value.height
|
|
65
|
+
);
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
} // namespace margelo::nitro::reactnativedeviceutils
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JFunc_void_bool.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
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include <functional>
|
|
12
|
+
|
|
13
|
+
#include <functional>
|
|
14
|
+
#include <NitroModules/JNICallable.hpp>
|
|
15
|
+
|
|
16
|
+
namespace margelo::nitro::reactnativedeviceutils {
|
|
17
|
+
|
|
18
|
+
using namespace facebook;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Represents the Java/Kotlin callback `(isSpanning: Boolean) -> Unit`.
|
|
22
|
+
* This can be passed around between C++ and Java/Kotlin.
|
|
23
|
+
*/
|
|
24
|
+
struct JFunc_void_bool: public jni::JavaClass<JFunc_void_bool> {
|
|
25
|
+
public:
|
|
26
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/reactnativedeviceutils/Func_void_bool;";
|
|
27
|
+
|
|
28
|
+
public:
|
|
29
|
+
/**
|
|
30
|
+
* Invokes the function this `JFunc_void_bool` instance holds through JNI.
|
|
31
|
+
*/
|
|
32
|
+
void invoke(bool isSpanning) const {
|
|
33
|
+
static const auto method = javaClassStatic()->getMethod<void(jboolean /* isSpanning */)>("invoke");
|
|
34
|
+
method(self(), isSpanning);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* An implementation of Func_void_bool that is backed by a C++ implementation (using `std::function<...>`)
|
|
40
|
+
*/
|
|
41
|
+
class JFunc_void_bool_cxx final: public jni::HybridClass<JFunc_void_bool_cxx, JFunc_void_bool> {
|
|
42
|
+
public:
|
|
43
|
+
static jni::local_ref<JFunc_void_bool::javaobject> fromCpp(const std::function<void(bool /* isSpanning */)>& func) {
|
|
44
|
+
return JFunc_void_bool_cxx::newObjectCxxArgs(func);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
/**
|
|
49
|
+
* Invokes the C++ `std::function<...>` this `JFunc_void_bool_cxx` instance holds.
|
|
50
|
+
*/
|
|
51
|
+
void invoke_cxx(jboolean isSpanning) {
|
|
52
|
+
_func(static_cast<bool>(isSpanning));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
[[nodiscard]]
|
|
57
|
+
inline const std::function<void(bool /* isSpanning */)>& getFunction() const {
|
|
58
|
+
return _func;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public:
|
|
62
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/reactnativedeviceutils/Func_void_bool_cxx;";
|
|
63
|
+
static void registerNatives() {
|
|
64
|
+
registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_bool_cxx::invoke_cxx)});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private:
|
|
68
|
+
explicit JFunc_void_bool_cxx(const std::function<void(bool /* isSpanning */)>& func): _func(func) { }
|
|
69
|
+
|
|
70
|
+
private:
|
|
71
|
+
friend HybridBase;
|
|
72
|
+
std::function<void(bool /* isSpanning */)> _func;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
} // namespace margelo::nitro::reactnativedeviceutils
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JHybridReactNativeDeviceUtilsSpec.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 "JHybridReactNativeDeviceUtilsSpec.hpp"
|
|
9
|
+
|
|
10
|
+
// Forward declaration of `DualScreenInfoRect` to properly resolve imports.
|
|
11
|
+
namespace margelo::nitro::reactnativedeviceutils { struct DualScreenInfoRect; }
|
|
12
|
+
|
|
13
|
+
#include "DualScreenInfoRect.hpp"
|
|
14
|
+
#include <vector>
|
|
15
|
+
#include <NitroModules/Promise.hpp>
|
|
16
|
+
#include <NitroModules/JPromise.hpp>
|
|
17
|
+
#include "JDualScreenInfoRect.hpp"
|
|
18
|
+
#include <functional>
|
|
19
|
+
#include "JFunc_void_bool.hpp"
|
|
20
|
+
#include <NitroModules/JNICallable.hpp>
|
|
21
|
+
|
|
22
|
+
namespace margelo::nitro::reactnativedeviceutils {
|
|
23
|
+
|
|
24
|
+
jni::local_ref<JHybridReactNativeDeviceUtilsSpec::jhybriddata> JHybridReactNativeDeviceUtilsSpec::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
25
|
+
return makeCxxInstance(jThis);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
void JHybridReactNativeDeviceUtilsSpec::registerNatives() {
|
|
29
|
+
registerHybrid({
|
|
30
|
+
makeNativeMethod("initHybrid", JHybridReactNativeDeviceUtilsSpec::initHybrid),
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
size_t JHybridReactNativeDeviceUtilsSpec::getExternalMemorySize() noexcept {
|
|
35
|
+
static const auto method = javaClassStatic()->getMethod<jlong()>("getMemorySize");
|
|
36
|
+
return method(_javaPart);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
void JHybridReactNativeDeviceUtilsSpec::dispose() noexcept {
|
|
40
|
+
static const auto method = javaClassStatic()->getMethod<void()>("dispose");
|
|
41
|
+
method(_javaPart);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
std::string JHybridReactNativeDeviceUtilsSpec::toString() {
|
|
45
|
+
static const auto method = javaClassStatic()->getMethod<jni::JString()>("toString");
|
|
46
|
+
auto javaString = method(_javaPart);
|
|
47
|
+
return javaString->toStdString();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Properties
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
// Methods
|
|
54
|
+
void JHybridReactNativeDeviceUtilsSpec::initEventListeners() {
|
|
55
|
+
static const auto method = javaClassStatic()->getMethod<void()>("initEventListeners");
|
|
56
|
+
method(_javaPart);
|
|
57
|
+
}
|
|
58
|
+
bool JHybridReactNativeDeviceUtilsSpec::isDualScreenDevice() {
|
|
59
|
+
static const auto method = javaClassStatic()->getMethod<jboolean()>("isDualScreenDevice");
|
|
60
|
+
auto __result = method(_javaPart);
|
|
61
|
+
return static_cast<bool>(__result);
|
|
62
|
+
}
|
|
63
|
+
bool JHybridReactNativeDeviceUtilsSpec::isSpanning() {
|
|
64
|
+
static const auto method = javaClassStatic()->getMethod<jboolean()>("isSpanning");
|
|
65
|
+
auto __result = method(_javaPart);
|
|
66
|
+
return static_cast<bool>(__result);
|
|
67
|
+
}
|
|
68
|
+
std::shared_ptr<Promise<std::vector<DualScreenInfoRect>>> JHybridReactNativeDeviceUtilsSpec::getWindowRects() {
|
|
69
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("getWindowRects");
|
|
70
|
+
auto __result = method(_javaPart);
|
|
71
|
+
return [&]() {
|
|
72
|
+
auto __promise = Promise<std::vector<DualScreenInfoRect>>::create();
|
|
73
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
74
|
+
auto __result = jni::static_ref_cast<jni::JArrayClass<JDualScreenInfoRect>>(__boxedResult);
|
|
75
|
+
__promise->resolve([&]() {
|
|
76
|
+
size_t __size = __result->size();
|
|
77
|
+
std::vector<DualScreenInfoRect> __vector;
|
|
78
|
+
__vector.reserve(__size);
|
|
79
|
+
for (size_t __i = 0; __i < __size; __i++) {
|
|
80
|
+
auto __element = __result->getElement(__i);
|
|
81
|
+
__vector.push_back(__element->toCpp());
|
|
82
|
+
}
|
|
83
|
+
return __vector;
|
|
84
|
+
}());
|
|
85
|
+
});
|
|
86
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
87
|
+
jni::JniException __jniError(__throwable);
|
|
88
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
89
|
+
});
|
|
90
|
+
return __promise;
|
|
91
|
+
}();
|
|
92
|
+
}
|
|
93
|
+
std::shared_ptr<Promise<DualScreenInfoRect>> JHybridReactNativeDeviceUtilsSpec::getHingeBounds() {
|
|
94
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("getHingeBounds");
|
|
95
|
+
auto __result = method(_javaPart);
|
|
96
|
+
return [&]() {
|
|
97
|
+
auto __promise = Promise<DualScreenInfoRect>::create();
|
|
98
|
+
__result->cthis()->addOnResolvedListener([=](const jni::alias_ref<jni::JObject>& __boxedResult) {
|
|
99
|
+
auto __result = jni::static_ref_cast<JDualScreenInfoRect>(__boxedResult);
|
|
100
|
+
__promise->resolve(__result->toCpp());
|
|
101
|
+
});
|
|
102
|
+
__result->cthis()->addOnRejectedListener([=](const jni::alias_ref<jni::JThrowable>& __throwable) {
|
|
103
|
+
jni::JniException __jniError(__throwable);
|
|
104
|
+
__promise->reject(std::make_exception_ptr(__jniError));
|
|
105
|
+
});
|
|
106
|
+
return __promise;
|
|
107
|
+
}();
|
|
108
|
+
}
|
|
109
|
+
void JHybridReactNativeDeviceUtilsSpec::changeBackgroundColor(double r, double g, double b, double a) {
|
|
110
|
+
static const auto method = javaClassStatic()->getMethod<void(double /* r */, double /* g */, double /* b */, double /* a */)>("changeBackgroundColor");
|
|
111
|
+
method(_javaPart, r, g, b, a);
|
|
112
|
+
}
|
|
113
|
+
double JHybridReactNativeDeviceUtilsSpec::addSpanningChangedListener(const std::function<void(bool /* isSpanning */)>& callback) {
|
|
114
|
+
static const auto method = javaClassStatic()->getMethod<double(jni::alias_ref<JFunc_void_bool::javaobject> /* callback */)>("addSpanningChangedListener_cxx");
|
|
115
|
+
auto __result = method(_javaPart, JFunc_void_bool_cxx::fromCpp(callback));
|
|
116
|
+
return __result;
|
|
117
|
+
}
|
|
118
|
+
void JHybridReactNativeDeviceUtilsSpec::removeSpanningChangedListener(double id) {
|
|
119
|
+
static const auto method = javaClassStatic()->getMethod<void(double /* id */)>("removeSpanningChangedListener");
|
|
120
|
+
method(_javaPart, id);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
} // namespace margelo::nitro::reactnativedeviceutils
|
|
@@ -0,0 +1,72 @@
|
|
|
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
|
+
#include <NitroModules/JHybridObject.hpp>
|
|
11
|
+
#include <fbjni/fbjni.h>
|
|
12
|
+
#include "HybridReactNativeDeviceUtilsSpec.hpp"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
namespace margelo::nitro::reactnativedeviceutils {
|
|
18
|
+
|
|
19
|
+
using namespace facebook;
|
|
20
|
+
|
|
21
|
+
class JHybridReactNativeDeviceUtilsSpec: public jni::HybridClass<JHybridReactNativeDeviceUtilsSpec, JHybridObject>,
|
|
22
|
+
public virtual HybridReactNativeDeviceUtilsSpec {
|
|
23
|
+
public:
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/reactnativedeviceutils/HybridReactNativeDeviceUtilsSpec;";
|
|
25
|
+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
26
|
+
static void registerNatives();
|
|
27
|
+
|
|
28
|
+
protected:
|
|
29
|
+
// C++ constructor (called from Java via `initHybrid()`)
|
|
30
|
+
explicit JHybridReactNativeDeviceUtilsSpec(jni::alias_ref<jhybridobject> jThis) :
|
|
31
|
+
HybridObject(HybridReactNativeDeviceUtilsSpec::TAG),
|
|
32
|
+
HybridBase(jThis),
|
|
33
|
+
_javaPart(jni::make_global(jThis)) {}
|
|
34
|
+
|
|
35
|
+
public:
|
|
36
|
+
~JHybridReactNativeDeviceUtilsSpec() override {
|
|
37
|
+
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
38
|
+
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public:
|
|
42
|
+
size_t getExternalMemorySize() noexcept override;
|
|
43
|
+
void dispose() noexcept override;
|
|
44
|
+
std::string toString() override;
|
|
45
|
+
|
|
46
|
+
public:
|
|
47
|
+
inline const jni::global_ref<JHybridReactNativeDeviceUtilsSpec::javaobject>& getJavaPart() const noexcept {
|
|
48
|
+
return _javaPart;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
// Properties
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
// Methods
|
|
57
|
+
void initEventListeners() override;
|
|
58
|
+
bool isDualScreenDevice() override;
|
|
59
|
+
bool isSpanning() override;
|
|
60
|
+
std::shared_ptr<Promise<std::vector<DualScreenInfoRect>>> getWindowRects() override;
|
|
61
|
+
std::shared_ptr<Promise<DualScreenInfoRect>> getHingeBounds() override;
|
|
62
|
+
void changeBackgroundColor(double r, double g, double b, double a) override;
|
|
63
|
+
double addSpanningChangedListener(const std::function<void(bool /* isSpanning */)>& callback) override;
|
|
64
|
+
void removeSpanningChangedListener(double id) override;
|
|
65
|
+
|
|
66
|
+
private:
|
|
67
|
+
friend HybridBase;
|
|
68
|
+
using HybridBase::HybridBase;
|
|
69
|
+
jni::global_ref<JHybridReactNativeDeviceUtilsSpec::javaobject> _javaPart;
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
} // namespace margelo::nitro::reactnativedeviceutils
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// DualScreenInfoRect.kt
|
|
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
|
+
package com.margelo.nitro.reactnativedeviceutils
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Represents the JavaScript object/struct "DualScreenInfoRect".
|
|
16
|
+
*/
|
|
17
|
+
@DoNotStrip
|
|
18
|
+
@Keep
|
|
19
|
+
data class DualScreenInfoRect(
|
|
20
|
+
@DoNotStrip
|
|
21
|
+
@Keep
|
|
22
|
+
val x: Double,
|
|
23
|
+
@DoNotStrip
|
|
24
|
+
@Keep
|
|
25
|
+
val y: Double,
|
|
26
|
+
@DoNotStrip
|
|
27
|
+
@Keep
|
|
28
|
+
val width: Double,
|
|
29
|
+
@DoNotStrip
|
|
30
|
+
@Keep
|
|
31
|
+
val height: Double
|
|
32
|
+
) {
|
|
33
|
+
/* primary constructor */
|
|
34
|
+
|
|
35
|
+
private companion object {
|
|
36
|
+
/**
|
|
37
|
+
* Constructor called from C++
|
|
38
|
+
*/
|
|
39
|
+
@DoNotStrip
|
|
40
|
+
@Keep
|
|
41
|
+
@Suppress("unused")
|
|
42
|
+
@JvmStatic
|
|
43
|
+
private fun fromCpp(x: Double, y: Double, width: Double, height: Double): DualScreenInfoRect {
|
|
44
|
+
return DualScreenInfoRect(x, y, width, height)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/Func_void_bool.kt
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_bool.kt
|
|
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
|
+
package com.margelo.nitro.reactnativedeviceutils
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.jni.HybridData
|
|
12
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import dalvik.annotation.optimization.FastNative
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Represents the JavaScript callback `(isSpanning: boolean) => void`.
|
|
18
|
+
* This can be either implemented in C++ (in which case it might be a callback coming from JS),
|
|
19
|
+
* or in Kotlin/Java (in which case it is a native callback).
|
|
20
|
+
*/
|
|
21
|
+
@DoNotStrip
|
|
22
|
+
@Keep
|
|
23
|
+
@Suppress("ClassName", "RedundantUnitReturnType")
|
|
24
|
+
fun interface Func_void_bool: (Boolean) -> Unit {
|
|
25
|
+
/**
|
|
26
|
+
* Call the given JS callback.
|
|
27
|
+
* @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
|
|
28
|
+
*/
|
|
29
|
+
@DoNotStrip
|
|
30
|
+
@Keep
|
|
31
|
+
override fun invoke(isSpanning: Boolean): Unit
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Represents the JavaScript callback `(isSpanning: boolean) => void`.
|
|
36
|
+
* This is implemented in C++, via a `std::function<...>`.
|
|
37
|
+
* The callback might be coming from JS.
|
|
38
|
+
*/
|
|
39
|
+
@DoNotStrip
|
|
40
|
+
@Keep
|
|
41
|
+
@Suppress(
|
|
42
|
+
"KotlinJniMissingFunction", "unused",
|
|
43
|
+
"RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
|
|
44
|
+
"ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
|
|
45
|
+
)
|
|
46
|
+
class Func_void_bool_cxx: Func_void_bool {
|
|
47
|
+
@DoNotStrip
|
|
48
|
+
@Keep
|
|
49
|
+
private val mHybridData: HybridData
|
|
50
|
+
|
|
51
|
+
@DoNotStrip
|
|
52
|
+
@Keep
|
|
53
|
+
private constructor(hybridData: HybridData) {
|
|
54
|
+
mHybridData = hybridData
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@DoNotStrip
|
|
58
|
+
@Keep
|
|
59
|
+
override fun invoke(isSpanning: Boolean): Unit
|
|
60
|
+
= invoke_cxx(isSpanning)
|
|
61
|
+
|
|
62
|
+
@FastNative
|
|
63
|
+
private external fun invoke_cxx(isSpanning: Boolean): Unit
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Represents the JavaScript callback `(isSpanning: boolean) => void`.
|
|
68
|
+
* This is implemented in Java/Kotlin, via a `(Boolean) -> Unit`.
|
|
69
|
+
* The callback is always coming from native.
|
|
70
|
+
*/
|
|
71
|
+
@DoNotStrip
|
|
72
|
+
@Keep
|
|
73
|
+
@Suppress("ClassName", "RedundantUnitReturnType", "unused")
|
|
74
|
+
class Func_void_bool_java(private val function: (Boolean) -> Unit): Func_void_bool {
|
|
75
|
+
@DoNotStrip
|
|
76
|
+
@Keep
|
|
77
|
+
override fun invoke(isSpanning: Boolean): Unit {
|
|
78
|
+
return this.function(isSpanning)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridReactNativeDeviceUtilsSpec.kt
|
|
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
|
+
package com.margelo.nitro.reactnativedeviceutils
|
|
9
|
+
|
|
10
|
+
import androidx.annotation.Keep
|
|
11
|
+
import com.facebook.jni.HybridData
|
|
12
|
+
import com.facebook.proguard.annotations.DoNotStrip
|
|
13
|
+
import com.margelo.nitro.core.Promise
|
|
14
|
+
import com.margelo.nitro.core.HybridObject
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A Kotlin class representing the ReactNativeDeviceUtils HybridObject.
|
|
18
|
+
* Implement this abstract class to create Kotlin-based instances of ReactNativeDeviceUtils.
|
|
19
|
+
*/
|
|
20
|
+
@DoNotStrip
|
|
21
|
+
@Keep
|
|
22
|
+
@Suppress(
|
|
23
|
+
"KotlinJniMissingFunction", "unused",
|
|
24
|
+
"RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet",
|
|
25
|
+
"LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
|
|
26
|
+
)
|
|
27
|
+
abstract class HybridReactNativeDeviceUtilsSpec: HybridObject() {
|
|
28
|
+
@DoNotStrip
|
|
29
|
+
private var mHybridData: HybridData = initHybrid()
|
|
30
|
+
|
|
31
|
+
init {
|
|
32
|
+
super.updateNative(mHybridData)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
override fun updateNative(hybridData: HybridData) {
|
|
36
|
+
mHybridData = hybridData
|
|
37
|
+
super.updateNative(hybridData)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Default implementation of `HybridObject.toString()`
|
|
41
|
+
override fun toString(): String {
|
|
42
|
+
return "[HybridObject ReactNativeDeviceUtils]"
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Properties
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
// Methods
|
|
49
|
+
@DoNotStrip
|
|
50
|
+
@Keep
|
|
51
|
+
abstract fun initEventListeners(): Unit
|
|
52
|
+
|
|
53
|
+
@DoNotStrip
|
|
54
|
+
@Keep
|
|
55
|
+
abstract fun isDualScreenDevice(): Boolean
|
|
56
|
+
|
|
57
|
+
@DoNotStrip
|
|
58
|
+
@Keep
|
|
59
|
+
abstract fun isSpanning(): Boolean
|
|
60
|
+
|
|
61
|
+
@DoNotStrip
|
|
62
|
+
@Keep
|
|
63
|
+
abstract fun getWindowRects(): Promise<Array<DualScreenInfoRect>>
|
|
64
|
+
|
|
65
|
+
@DoNotStrip
|
|
66
|
+
@Keep
|
|
67
|
+
abstract fun getHingeBounds(): Promise<DualScreenInfoRect>
|
|
68
|
+
|
|
69
|
+
@DoNotStrip
|
|
70
|
+
@Keep
|
|
71
|
+
abstract fun changeBackgroundColor(r: Double, g: Double, b: Double, a: Double): Unit
|
|
72
|
+
|
|
73
|
+
abstract fun addSpanningChangedListener(callback: (isSpanning: Boolean) -> Unit): Double
|
|
74
|
+
|
|
75
|
+
@DoNotStrip
|
|
76
|
+
@Keep
|
|
77
|
+
private fun addSpanningChangedListener_cxx(callback: Func_void_bool): Double {
|
|
78
|
+
val __result = addSpanningChangedListener(callback)
|
|
79
|
+
return __result
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
@DoNotStrip
|
|
83
|
+
@Keep
|
|
84
|
+
abstract fun removeSpanningChangedListener(id: Double): Unit
|
|
85
|
+
|
|
86
|
+
private external fun initHybrid(): HybridData
|
|
87
|
+
|
|
88
|
+
companion object {
|
|
89
|
+
protected const val TAG = "HybridReactNativeDeviceUtilsSpec"
|
|
90
|
+
}
|
|
91
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// reactnativedeviceutilsOnLoad.kt
|
|
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
|
+
package com.margelo.nitro.reactnativedeviceutils
|
|
9
|
+
|
|
10
|
+
import android.util.Log
|
|
11
|
+
|
|
12
|
+
internal class reactnativedeviceutilsOnLoad {
|
|
13
|
+
companion object {
|
|
14
|
+
private const val TAG = "reactnativedeviceutilsOnLoad"
|
|
15
|
+
private var didLoad = false
|
|
16
|
+
/**
|
|
17
|
+
* Initializes the native part of "reactnativedeviceutils".
|
|
18
|
+
* This method is idempotent and can be called more than once.
|
|
19
|
+
*/
|
|
20
|
+
@JvmStatic
|
|
21
|
+
fun initializeNative() {
|
|
22
|
+
if (didLoad) return
|
|
23
|
+
try {
|
|
24
|
+
Log.i(TAG, "Loading reactnativedeviceutils C++ library...")
|
|
25
|
+
System.loadLibrary("reactnativedeviceutils")
|
|
26
|
+
Log.i(TAG, "Successfully loaded reactnativedeviceutils C++ library!")
|
|
27
|
+
didLoad = true
|
|
28
|
+
} catch (e: Error) {
|
|
29
|
+
Log.e(TAG, "Failed to load reactnativedeviceutils C++ library! Is it properly installed and linked? " +
|
|
30
|
+
"Is the name correct? (see `CMakeLists.txt`, at `add_library(...)`)", e)
|
|
31
|
+
throw e
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|