@onekeyfe/react-native-device-utils 1.1.15 → 1.1.17
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/android/build.gradle +4 -0
- package/android/src/main/java/com/margelo/nitro/reactnativedeviceutils/ReactNativeDeviceUtils.kt +41 -1
- package/ios/ReactNativeDeviceUtils.swift +44 -1
- package/lib/typescript/src/ReactNativeDeviceUtils.nitro.d.ts +2 -0
- package/lib/typescript/src/ReactNativeDeviceUtils.nitro.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JHybridReactNativeDeviceUtilsSpec.cpp +8 -0
- package/nitrogen/generated/android/c++/JHybridReactNativeDeviceUtilsSpec.hpp +1 -0
- package/nitrogen/generated/android/c++/JUserInterfaceStyle.hpp +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/HybridReactNativeDeviceUtilsSpec.kt +4 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/UserInterfaceStyle.kt +22 -0
- package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridReactNativeDeviceUtilsSpecSwift.hpp +9 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeDeviceUtilsSpec.swift +1 -0
- package/nitrogen/generated/ios/swift/HybridReactNativeDeviceUtilsSpec_cxx.swift +11 -0
- package/nitrogen/generated/ios/swift/UserInterfaceStyle.swift +44 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeDeviceUtilsSpec.cpp +1 -0
- package/nitrogen/generated/shared/c++/HybridReactNativeDeviceUtilsSpec.hpp +4 -0
- package/nitrogen/generated/shared/c++/UserInterfaceStyle.hpp +80 -0
- package/package.json +1 -1
- package/src/ReactNativeDeviceUtils.nitro.ts +3 -0
package/android/build.gradle
CHANGED
|
@@ -129,4 +129,8 @@ dependencies {
|
|
|
129
129
|
// WindowManager library for foldable device detection
|
|
130
130
|
implementation "androidx.window:window:1.5.1"
|
|
131
131
|
implementation "androidx.window:window-java:1.5.1"
|
|
132
|
+
// AppCompat for night mode support
|
|
133
|
+
implementation "androidx.appcompat:appcompat:1.7.1"
|
|
134
|
+
// AndroidX Preference for PreferenceManager
|
|
135
|
+
implementation "androidx.preference:preference-ktx:1.2.1"
|
|
132
136
|
}
|
package/android/src/main/java/com/margelo/nitro/reactnativedeviceutils/ReactNativeDeviceUtils.kt
CHANGED
|
@@ -6,13 +6,14 @@ import android.content.pm.PackageManager
|
|
|
6
6
|
import android.graphics.Color
|
|
7
7
|
import android.graphics.Rect
|
|
8
8
|
import android.os.Build
|
|
9
|
-
import
|
|
9
|
+
import androidx.preference.PreferenceManager
|
|
10
10
|
import androidx.core.content.ContextCompat
|
|
11
11
|
import androidx.core.util.Consumer
|
|
12
12
|
import androidx.window.layout.FoldingFeature
|
|
13
13
|
import androidx.window.layout.WindowInfoTracker
|
|
14
14
|
import androidx.window.layout.WindowLayoutInfo
|
|
15
15
|
import androidx.window.java.layout.WindowInfoTrackerCallbackAdapter
|
|
16
|
+
import androidx.appcompat.app.AppCompatDelegate
|
|
16
17
|
import com.facebook.proguard.annotations.DoNotStrip
|
|
17
18
|
import com.facebook.react.bridge.LifecycleEventListener
|
|
18
19
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
@@ -35,6 +36,7 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
35
36
|
*/
|
|
36
37
|
companion object {
|
|
37
38
|
private const val PREF_KEY_FOLDABLE = "1k_fold"
|
|
39
|
+
private const val PREF_KEY_UI_STYLE = "1k_user_interface_style"
|
|
38
40
|
|
|
39
41
|
// Xiaomi foldable models
|
|
40
42
|
private val XIAOMI_FOLDABLE_MODELS = setOf(
|
|
@@ -227,6 +229,29 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
227
229
|
NitroModules.applicationContext?.let { ctx ->
|
|
228
230
|
ctx.addLifecycleEventListener(this)
|
|
229
231
|
}
|
|
232
|
+
restoreUserInterfaceStyle()
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
private fun restoreUserInterfaceStyle() {
|
|
236
|
+
try {
|
|
237
|
+
val context = NitroModules.applicationContext ?: return
|
|
238
|
+
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
|
239
|
+
val style = prefs.getString(PREF_KEY_UI_STYLE, null) ?: return
|
|
240
|
+
applyUserInterfaceStyle(style)
|
|
241
|
+
} catch (e: Exception) {
|
|
242
|
+
// Ignore restore errors
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
private fun applyUserInterfaceStyle(style: String) {
|
|
247
|
+
val mode = when (style) {
|
|
248
|
+
"light" -> AppCompatDelegate.MODE_NIGHT_NO
|
|
249
|
+
"dark" -> AppCompatDelegate.MODE_NIGHT_YES
|
|
250
|
+
else -> AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM
|
|
251
|
+
}
|
|
252
|
+
android.os.Handler(android.os.Looper.getMainLooper()).post {
|
|
253
|
+
AppCompatDelegate.setDefaultNightMode(mode)
|
|
254
|
+
}
|
|
230
255
|
}
|
|
231
256
|
|
|
232
257
|
private fun getCurrentActivity(): Activity? {
|
|
@@ -759,6 +784,21 @@ class ReactNativeDeviceUtils : HybridReactNativeDeviceUtilsSpec(), LifecycleEven
|
|
|
759
784
|
}
|
|
760
785
|
}
|
|
761
786
|
|
|
787
|
+
// MARK: - User Interface Style
|
|
788
|
+
|
|
789
|
+
override fun setUserInterfaceStyle(style: String) {
|
|
790
|
+
try {
|
|
791
|
+
val context = NitroModules.applicationContext
|
|
792
|
+
if (context != null) {
|
|
793
|
+
val prefs = PreferenceManager.getDefaultSharedPreferences(context)
|
|
794
|
+
prefs.edit().putString(PREF_KEY_UI_STYLE, style).apply()
|
|
795
|
+
}
|
|
796
|
+
} catch (e: Exception) {
|
|
797
|
+
// Ignore save errors
|
|
798
|
+
}
|
|
799
|
+
applyUserInterfaceStyle(style)
|
|
800
|
+
}
|
|
801
|
+
|
|
762
802
|
// MARK: - Background Color
|
|
763
803
|
|
|
764
804
|
override fun changeBackgroundColor(r: Double, g: Double, b: Double, a: Double) {
|
|
@@ -2,7 +2,45 @@ import NitroModules
|
|
|
2
2
|
import UIKit
|
|
3
3
|
|
|
4
4
|
class ReactNativeDeviceUtils: HybridReactNativeDeviceUtilsSpec {
|
|
5
|
-
|
|
5
|
+
|
|
6
|
+
private static let userInterfaceStyleKey = "1k_user_interface_style"
|
|
7
|
+
|
|
8
|
+
override init() {
|
|
9
|
+
super.init()
|
|
10
|
+
restoreUserInterfaceStyle()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
private func restoreUserInterfaceStyle() {
|
|
14
|
+
guard let style = UserDefaults.standard.string(forKey: ReactNativeDeviceUtils.userInterfaceStyleKey) else {
|
|
15
|
+
return
|
|
16
|
+
}
|
|
17
|
+
applyUserInterfaceStyle(style)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
private func applyUserInterfaceStyle(_ style: String) {
|
|
21
|
+
DispatchQueue.main.async {
|
|
22
|
+
var uiStyle: UIUserInterfaceStyle = .unspecified
|
|
23
|
+
if style == "light" {
|
|
24
|
+
uiStyle = .light
|
|
25
|
+
} else if style == "dark" {
|
|
26
|
+
uiStyle = .dark
|
|
27
|
+
}
|
|
28
|
+
if #available(iOS 15.0, *) {
|
|
29
|
+
for scene in UIApplication.shared.connectedScenes {
|
|
30
|
+
if let windowScene = scene as? UIWindowScene {
|
|
31
|
+
for window in windowScene.windows {
|
|
32
|
+
window.overrideUserInterfaceStyle = uiStyle
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
} else {
|
|
37
|
+
for window in UIApplication.shared.windows {
|
|
38
|
+
window.overrideUserInterfaceStyle = uiStyle
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
6
44
|
public func isDualScreenDevice() throws -> Bool {
|
|
7
45
|
return false
|
|
8
46
|
}
|
|
@@ -31,6 +69,11 @@ class ReactNativeDeviceUtils: HybridReactNativeDeviceUtilsSpec {
|
|
|
31
69
|
}
|
|
32
70
|
|
|
33
71
|
|
|
72
|
+
public func setUserInterfaceStyle(style: String) throws -> Void {
|
|
73
|
+
UserDefaults.standard.set(style, forKey: ReactNativeDeviceUtils.userInterfaceStyleKey)
|
|
74
|
+
applyUserInterfaceStyle(style)
|
|
75
|
+
}
|
|
76
|
+
|
|
34
77
|
public func changeBackgroundColor(r: Double, g: Double, b: Double, a: Double) throws -> Void {
|
|
35
78
|
DispatchQueue.main.async {
|
|
36
79
|
// Clamp color values to valid range [0, 255]
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
|
+
export type UserInterfaceStyle = 'light' | 'dark' | 'unspecified';
|
|
2
3
|
export interface DualScreenInfoRect {
|
|
3
4
|
x: number;
|
|
4
5
|
y: number;
|
|
@@ -17,5 +18,6 @@ export interface ReactNativeDeviceUtils extends HybridObject<{
|
|
|
17
18
|
changeBackgroundColor(r: number, g: number, b: number, a: number): void;
|
|
18
19
|
addSpanningChangedListener(callback: (isSpanning: boolean) => void): number;
|
|
19
20
|
removeSpanningChangedListener(id: number): void;
|
|
21
|
+
setUserInterfaceStyle(style: UserInterfaceStyle): void;
|
|
20
22
|
}
|
|
21
23
|
//# sourceMappingURL=ReactNativeDeviceUtils.nitro.d.ts.map
|
|
@@ -1 +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;
|
|
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,MAAM,kBAAkB,GAAG,OAAO,GAAG,MAAM,GAAG,aAAa,CAAC;AAElE,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;IAChD,qBAAqB,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAAC;CACxD"}
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
|
|
10
10
|
// Forward declaration of `DualScreenInfoRect` to properly resolve imports.
|
|
11
11
|
namespace margelo::nitro::reactnativedeviceutils { struct DualScreenInfoRect; }
|
|
12
|
+
// Forward declaration of `UserInterfaceStyle` to properly resolve imports.
|
|
13
|
+
namespace margelo::nitro::reactnativedeviceutils { enum class UserInterfaceStyle; }
|
|
12
14
|
|
|
13
15
|
#include "DualScreenInfoRect.hpp"
|
|
14
16
|
#include <vector>
|
|
@@ -18,6 +20,8 @@ namespace margelo::nitro::reactnativedeviceutils { struct DualScreenInfoRect; }
|
|
|
18
20
|
#include <functional>
|
|
19
21
|
#include "JFunc_void_bool.hpp"
|
|
20
22
|
#include <NitroModules/JNICallable.hpp>
|
|
23
|
+
#include "UserInterfaceStyle.hpp"
|
|
24
|
+
#include "JUserInterfaceStyle.hpp"
|
|
21
25
|
|
|
22
26
|
namespace margelo::nitro::reactnativedeviceutils {
|
|
23
27
|
|
|
@@ -119,5 +123,9 @@ namespace margelo::nitro::reactnativedeviceutils {
|
|
|
119
123
|
static const auto method = javaClassStatic()->getMethod<void(double /* id */)>("removeSpanningChangedListener");
|
|
120
124
|
method(_javaPart, id);
|
|
121
125
|
}
|
|
126
|
+
void JHybridReactNativeDeviceUtilsSpec::setUserInterfaceStyle(UserInterfaceStyle style) {
|
|
127
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JUserInterfaceStyle> /* style */)>("setUserInterfaceStyle");
|
|
128
|
+
method(_javaPart, JUserInterfaceStyle::fromCpp(style));
|
|
129
|
+
}
|
|
122
130
|
|
|
123
131
|
} // namespace margelo::nitro::reactnativedeviceutils
|
|
@@ -62,6 +62,7 @@ namespace margelo::nitro::reactnativedeviceutils {
|
|
|
62
62
|
void changeBackgroundColor(double r, double g, double b, double a) override;
|
|
63
63
|
double addSpanningChangedListener(const std::function<void(bool /* isSpanning */)>& callback) override;
|
|
64
64
|
void removeSpanningChangedListener(double id) override;
|
|
65
|
+
void setUserInterfaceStyle(UserInterfaceStyle style) override;
|
|
65
66
|
|
|
66
67
|
private:
|
|
67
68
|
friend HybridBase;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JUserInterfaceStyle.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#include <fbjni/fbjni.h>
|
|
11
|
+
#include "UserInterfaceStyle.hpp"
|
|
12
|
+
|
|
13
|
+
namespace margelo::nitro::reactnativedeviceutils {
|
|
14
|
+
|
|
15
|
+
using namespace facebook;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* The C++ JNI bridge between the C++ enum "UserInterfaceStyle" and the the Kotlin enum "UserInterfaceStyle".
|
|
19
|
+
*/
|
|
20
|
+
struct JUserInterfaceStyle final: public jni::JavaClass<JUserInterfaceStyle> {
|
|
21
|
+
public:
|
|
22
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/reactnativedeviceutils/UserInterfaceStyle;";
|
|
23
|
+
|
|
24
|
+
public:
|
|
25
|
+
/**
|
|
26
|
+
* Convert this Java/Kotlin-based enum to the C++ enum UserInterfaceStyle.
|
|
27
|
+
*/
|
|
28
|
+
[[maybe_unused]]
|
|
29
|
+
[[nodiscard]]
|
|
30
|
+
UserInterfaceStyle toCpp() const {
|
|
31
|
+
static const auto clazz = javaClassStatic();
|
|
32
|
+
static const auto fieldOrdinal = clazz->getField<int>("value");
|
|
33
|
+
int ordinal = this->getFieldValue(fieldOrdinal);
|
|
34
|
+
return static_cast<UserInterfaceStyle>(ordinal);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
public:
|
|
38
|
+
/**
|
|
39
|
+
* Create a Java/Kotlin-based enum with the given C++ enum's value.
|
|
40
|
+
*/
|
|
41
|
+
[[maybe_unused]]
|
|
42
|
+
static jni::alias_ref<JUserInterfaceStyle> fromCpp(UserInterfaceStyle value) {
|
|
43
|
+
static const auto clazz = javaClassStatic();
|
|
44
|
+
static const auto fieldLIGHT = clazz->getStaticField<JUserInterfaceStyle>("LIGHT");
|
|
45
|
+
static const auto fieldDARK = clazz->getStaticField<JUserInterfaceStyle>("DARK");
|
|
46
|
+
static const auto fieldUNSPECIFIED = clazz->getStaticField<JUserInterfaceStyle>("UNSPECIFIED");
|
|
47
|
+
|
|
48
|
+
switch (value) {
|
|
49
|
+
case UserInterfaceStyle::LIGHT:
|
|
50
|
+
return clazz->getStaticFieldValue(fieldLIGHT);
|
|
51
|
+
case UserInterfaceStyle::DARK:
|
|
52
|
+
return clazz->getStaticFieldValue(fieldDARK);
|
|
53
|
+
case UserInterfaceStyle::UNSPECIFIED:
|
|
54
|
+
return clazz->getStaticFieldValue(fieldUNSPECIFIED);
|
|
55
|
+
default:
|
|
56
|
+
std::string stringValue = std::to_string(static_cast<int>(value));
|
|
57
|
+
throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
} // namespace margelo::nitro::reactnativedeviceutils
|
|
@@ -82,6 +82,10 @@ abstract class HybridReactNativeDeviceUtilsSpec: HybridObject() {
|
|
|
82
82
|
@DoNotStrip
|
|
83
83
|
@Keep
|
|
84
84
|
abstract fun removeSpanningChangedListener(id: Double): Unit
|
|
85
|
+
|
|
86
|
+
@DoNotStrip
|
|
87
|
+
@Keep
|
|
88
|
+
abstract fun setUserInterfaceStyle(style: UserInterfaceStyle): Unit
|
|
85
89
|
|
|
86
90
|
private external fun initHybrid(): HybridData
|
|
87
91
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// UserInterfaceStyle.kt
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 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
|
+
* Represents the JavaScript enum/union "UserInterfaceStyle".
|
|
15
|
+
*/
|
|
16
|
+
@DoNotStrip
|
|
17
|
+
@Keep
|
|
18
|
+
enum class UserInterfaceStyle(@DoNotStrip @Keep val value: Int) {
|
|
19
|
+
LIGHT(0),
|
|
20
|
+
DARK(1),
|
|
21
|
+
UNSPECIFIED(2);
|
|
22
|
+
}
|
|
@@ -12,10 +12,13 @@
|
|
|
12
12
|
namespace margelo::nitro::reactnativedeviceutils { struct DualScreenInfoRect; }
|
|
13
13
|
// Forward declaration of `HybridReactNativeDeviceUtilsSpec` to properly resolve imports.
|
|
14
14
|
namespace margelo::nitro::reactnativedeviceutils { class HybridReactNativeDeviceUtilsSpec; }
|
|
15
|
+
// Forward declaration of `UserInterfaceStyle` to properly resolve imports.
|
|
16
|
+
namespace margelo::nitro::reactnativedeviceutils { enum class UserInterfaceStyle; }
|
|
15
17
|
|
|
16
18
|
// Include C++ defined types
|
|
17
19
|
#include "DualScreenInfoRect.hpp"
|
|
18
20
|
#include "HybridReactNativeDeviceUtilsSpec.hpp"
|
|
21
|
+
#include "UserInterfaceStyle.hpp"
|
|
19
22
|
#include <NitroModules/Promise.hpp>
|
|
20
23
|
#include <NitroModules/Result.hpp>
|
|
21
24
|
#include <exception>
|
|
@@ -14,11 +14,14 @@ namespace ReactNativeDeviceUtils { class HybridReactNativeDeviceUtilsSpec_cxx; }
|
|
|
14
14
|
|
|
15
15
|
// Forward declaration of `DualScreenInfoRect` to properly resolve imports.
|
|
16
16
|
namespace margelo::nitro::reactnativedeviceutils { struct DualScreenInfoRect; }
|
|
17
|
+
// Forward declaration of `UserInterfaceStyle` to properly resolve imports.
|
|
18
|
+
namespace margelo::nitro::reactnativedeviceutils { enum class UserInterfaceStyle; }
|
|
17
19
|
|
|
18
20
|
#include "DualScreenInfoRect.hpp"
|
|
19
21
|
#include <vector>
|
|
20
22
|
#include <NitroModules/Promise.hpp>
|
|
21
23
|
#include <functional>
|
|
24
|
+
#include "UserInterfaceStyle.hpp"
|
|
22
25
|
|
|
23
26
|
#include "ReactNativeDeviceUtils-Swift-Cxx-Umbrella.hpp"
|
|
24
27
|
|
|
@@ -122,6 +125,12 @@ namespace margelo::nitro::reactnativedeviceutils {
|
|
|
122
125
|
std::rethrow_exception(__result.error());
|
|
123
126
|
}
|
|
124
127
|
}
|
|
128
|
+
inline void setUserInterfaceStyle(UserInterfaceStyle style) override {
|
|
129
|
+
auto __result = _swiftPart.setUserInterfaceStyle(static_cast<int>(style));
|
|
130
|
+
if (__result.hasError()) [[unlikely]] {
|
|
131
|
+
std::rethrow_exception(__result.error());
|
|
132
|
+
}
|
|
133
|
+
}
|
|
125
134
|
|
|
126
135
|
private:
|
|
127
136
|
ReactNativeDeviceUtils::HybridReactNativeDeviceUtilsSpec_cxx _swiftPart;
|
|
@@ -22,6 +22,7 @@ public protocol HybridReactNativeDeviceUtilsSpec_protocol: HybridObject {
|
|
|
22
22
|
func changeBackgroundColor(r: Double, g: Double, b: Double, a: Double) throws -> Void
|
|
23
23
|
func addSpanningChangedListener(callback: @escaping (_ isSpanning: Bool) -> Void) throws -> Double
|
|
24
24
|
func removeSpanningChangedListener(id: Double) throws -> Void
|
|
25
|
+
func setUserInterfaceStyle(style: UserInterfaceStyle) throws -> Void
|
|
25
26
|
}
|
|
26
27
|
|
|
27
28
|
public extension HybridReactNativeDeviceUtilsSpec_protocol {
|
|
@@ -234,4 +234,15 @@ open class HybridReactNativeDeviceUtilsSpec_cxx {
|
|
|
234
234
|
return bridge.create_Result_void_(__exceptionPtr)
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
|
+
|
|
238
|
+
@inline(__always)
|
|
239
|
+
public final func setUserInterfaceStyle(style: Int32) -> bridge.Result_void_ {
|
|
240
|
+
do {
|
|
241
|
+
try self.__implementation.setUserInterfaceStyle(style: margelo.nitro.reactnativedeviceutils.UserInterfaceStyle(rawValue: style)!)
|
|
242
|
+
return bridge.create_Result_void_()
|
|
243
|
+
} catch (let __error) {
|
|
244
|
+
let __exceptionPtr = __error.toCpp()
|
|
245
|
+
return bridge.create_Result_void_(__exceptionPtr)
|
|
246
|
+
}
|
|
247
|
+
}
|
|
237
248
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// UserInterfaceStyle.swift
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Represents the JS union `UserInterfaceStyle`, backed by a C++ enum.
|
|
10
|
+
*/
|
|
11
|
+
public typealias UserInterfaceStyle = margelo.nitro.reactnativedeviceutils.UserInterfaceStyle
|
|
12
|
+
|
|
13
|
+
public extension UserInterfaceStyle {
|
|
14
|
+
/**
|
|
15
|
+
* Get a UserInterfaceStyle for the given String value, or
|
|
16
|
+
* return `nil` if the given value was invalid/unknown.
|
|
17
|
+
*/
|
|
18
|
+
init?(fromString string: String) {
|
|
19
|
+
switch string {
|
|
20
|
+
case "light":
|
|
21
|
+
self = .light
|
|
22
|
+
case "dark":
|
|
23
|
+
self = .dark
|
|
24
|
+
case "unspecified":
|
|
25
|
+
self = .unspecified
|
|
26
|
+
default:
|
|
27
|
+
return nil
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Get the String value this UserInterfaceStyle represents.
|
|
33
|
+
*/
|
|
34
|
+
var stringValue: String {
|
|
35
|
+
switch self {
|
|
36
|
+
case .light:
|
|
37
|
+
return "light"
|
|
38
|
+
case .dark:
|
|
39
|
+
return "dark"
|
|
40
|
+
case .unspecified:
|
|
41
|
+
return "unspecified"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -22,6 +22,7 @@ namespace margelo::nitro::reactnativedeviceutils {
|
|
|
22
22
|
prototype.registerHybridMethod("changeBackgroundColor", &HybridReactNativeDeviceUtilsSpec::changeBackgroundColor);
|
|
23
23
|
prototype.registerHybridMethod("addSpanningChangedListener", &HybridReactNativeDeviceUtilsSpec::addSpanningChangedListener);
|
|
24
24
|
prototype.registerHybridMethod("removeSpanningChangedListener", &HybridReactNativeDeviceUtilsSpec::removeSpanningChangedListener);
|
|
25
|
+
prototype.registerHybridMethod("setUserInterfaceStyle", &HybridReactNativeDeviceUtilsSpec::setUserInterfaceStyle);
|
|
25
26
|
});
|
|
26
27
|
}
|
|
27
28
|
|
|
@@ -15,11 +15,14 @@
|
|
|
15
15
|
|
|
16
16
|
// Forward declaration of `DualScreenInfoRect` to properly resolve imports.
|
|
17
17
|
namespace margelo::nitro::reactnativedeviceutils { struct DualScreenInfoRect; }
|
|
18
|
+
// Forward declaration of `UserInterfaceStyle` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::reactnativedeviceutils { enum class UserInterfaceStyle; }
|
|
18
20
|
|
|
19
21
|
#include "DualScreenInfoRect.hpp"
|
|
20
22
|
#include <vector>
|
|
21
23
|
#include <NitroModules/Promise.hpp>
|
|
22
24
|
#include <functional>
|
|
25
|
+
#include "UserInterfaceStyle.hpp"
|
|
23
26
|
|
|
24
27
|
namespace margelo::nitro::reactnativedeviceutils {
|
|
25
28
|
|
|
@@ -60,6 +63,7 @@ namespace margelo::nitro::reactnativedeviceutils {
|
|
|
60
63
|
virtual void changeBackgroundColor(double r, double g, double b, double a) = 0;
|
|
61
64
|
virtual double addSpanningChangedListener(const std::function<void(bool /* isSpanning */)>& callback) = 0;
|
|
62
65
|
virtual void removeSpanningChangedListener(double id) = 0;
|
|
66
|
+
virtual void setUserInterfaceStyle(UserInterfaceStyle style) = 0;
|
|
63
67
|
|
|
64
68
|
protected:
|
|
65
69
|
// Hybrid Setup
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// UserInterfaceStyle.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © 2026 Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/NitroHash.hpp>)
|
|
11
|
+
#include <NitroModules/NitroHash.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
16
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
21
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::reactnativedeviceutils {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (UserInterfaceStyle).
|
|
30
|
+
*/
|
|
31
|
+
enum class UserInterfaceStyle {
|
|
32
|
+
LIGHT SWIFT_NAME(light) = 0,
|
|
33
|
+
DARK SWIFT_NAME(dark) = 1,
|
|
34
|
+
UNSPECIFIED SWIFT_NAME(unspecified) = 2,
|
|
35
|
+
} CLOSED_ENUM;
|
|
36
|
+
|
|
37
|
+
} // namespace margelo::nitro::reactnativedeviceutils
|
|
38
|
+
|
|
39
|
+
namespace margelo::nitro {
|
|
40
|
+
|
|
41
|
+
// C++ UserInterfaceStyle <> JS UserInterfaceStyle (union)
|
|
42
|
+
template <>
|
|
43
|
+
struct JSIConverter<margelo::nitro::reactnativedeviceutils::UserInterfaceStyle> final {
|
|
44
|
+
static inline margelo::nitro::reactnativedeviceutils::UserInterfaceStyle fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
45
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
|
|
46
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
47
|
+
case hashString("light"): return margelo::nitro::reactnativedeviceutils::UserInterfaceStyle::LIGHT;
|
|
48
|
+
case hashString("dark"): return margelo::nitro::reactnativedeviceutils::UserInterfaceStyle::DARK;
|
|
49
|
+
case hashString("unspecified"): return margelo::nitro::reactnativedeviceutils::UserInterfaceStyle::UNSPECIFIED;
|
|
50
|
+
default: [[unlikely]]
|
|
51
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum UserInterfaceStyle - invalid value!");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::reactnativedeviceutils::UserInterfaceStyle arg) {
|
|
55
|
+
switch (arg) {
|
|
56
|
+
case margelo::nitro::reactnativedeviceutils::UserInterfaceStyle::LIGHT: return JSIConverter<std::string>::toJSI(runtime, "light");
|
|
57
|
+
case margelo::nitro::reactnativedeviceutils::UserInterfaceStyle::DARK: return JSIConverter<std::string>::toJSI(runtime, "dark");
|
|
58
|
+
case margelo::nitro::reactnativedeviceutils::UserInterfaceStyle::UNSPECIFIED: return JSIConverter<std::string>::toJSI(runtime, "unspecified");
|
|
59
|
+
default: [[unlikely]]
|
|
60
|
+
throw std::invalid_argument("Cannot convert UserInterfaceStyle to JS - invalid value: "
|
|
61
|
+
+ std::to_string(static_cast<int>(arg)) + "!");
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
65
|
+
if (!value.isString()) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
|
|
69
|
+
switch (hashString(unionValue.c_str(), unionValue.size())) {
|
|
70
|
+
case hashString("light"):
|
|
71
|
+
case hashString("dark"):
|
|
72
|
+
case hashString("unspecified"):
|
|
73
|
+
return true;
|
|
74
|
+
default:
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
} // namespace margelo::nitro
|
package/package.json
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { HybridObject } from 'react-native-nitro-modules';
|
|
2
2
|
|
|
3
3
|
|
|
4
|
+
export type UserInterfaceStyle = 'light' | 'dark' | 'unspecified';
|
|
5
|
+
|
|
4
6
|
export interface DualScreenInfoRect {
|
|
5
7
|
x: number;
|
|
6
8
|
y: number;
|
|
@@ -18,4 +20,5 @@ export interface ReactNativeDeviceUtils
|
|
|
18
20
|
changeBackgroundColor(r: number, g: number, b: number, a: number): void;
|
|
19
21
|
addSpanningChangedListener(callback: (isSpanning: boolean) => void): number;
|
|
20
22
|
removeSpanningChangedListener(id: number): void;
|
|
23
|
+
setUserInterfaceStyle(style: UserInterfaceStyle): void;
|
|
21
24
|
}
|