@onekeyfe/react-native-device-utils 6.7.0-4 → 6.7.0-40

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 (42) hide show
  1. package/android/src/main/java/com/margelo/nitro/reactnativedeviceutils/ReactNativeDeviceUtils.kt +156 -35
  2. package/ios/DualScreenDetector.swift +170 -0
  3. package/ios/MainMenuController.swift +170 -0
  4. package/ios/ReactNativeDeviceUtils.swift +29 -4
  5. package/ios/WindowControlsInsetsObserver.swift +151 -0
  6. package/lib/typescript/src/ReactNativeDeviceUtils.nitro.d.ts +46 -0
  7. package/nitrogen/generated/android/c++/JFunc_void_MainMenuCommand.hpp +77 -0
  8. package/nitrogen/generated/android/c++/JFunc_void_WindowControlsInsets.hpp +77 -0
  9. package/nitrogen/generated/android/c++/JHybridReactNativeDeviceUtilsSpec.cpp +45 -0
  10. package/nitrogen/generated/android/c++/JHybridReactNativeDeviceUtilsSpec.hpp +6 -0
  11. package/nitrogen/generated/android/c++/JMainMenuCommand.hpp +61 -0
  12. package/nitrogen/generated/android/c++/JMainMenuConfig.hpp +90 -0
  13. package/nitrogen/generated/android/c++/JMainMenuLink.hpp +61 -0
  14. package/nitrogen/generated/android/c++/JWindowControlsInsets.hpp +69 -0
  15. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/Func_void_MainMenuCommand.kt +78 -0
  16. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/Func_void_WindowControlsInsets.kt +78 -0
  17. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/HybridReactNativeDeviceUtilsSpec.kt +34 -0
  18. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/MainMenuCommand.kt +24 -0
  19. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/MainMenuConfig.kt +66 -0
  20. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/MainMenuLink.kt +56 -0
  21. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/WindowControlsInsets.kt +66 -0
  22. package/nitrogen/generated/android/reactnativedeviceutilsOnLoad.cpp +4 -0
  23. package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Bridge.cpp +16 -0
  24. package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Bridge.hpp +73 -0
  25. package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Umbrella.hpp +12 -0
  26. package/nitrogen/generated/ios/c++/HybridReactNativeDeviceUtilsSpecSwift.hpp +55 -1
  27. package/nitrogen/generated/ios/swift/Func_void_MainMenuCommand.swift +46 -0
  28. package/nitrogen/generated/ios/swift/Func_void_WindowControlsInsets.swift +46 -0
  29. package/nitrogen/generated/ios/swift/HybridReactNativeDeviceUtilsSpec.swift +6 -0
  30. package/nitrogen/generated/ios/swift/HybridReactNativeDeviceUtilsSpec_cxx.swift +79 -0
  31. package/nitrogen/generated/ios/swift/MainMenuCommand.swift +44 -0
  32. package/nitrogen/generated/ios/swift/MainMenuConfig.swift +50 -0
  33. package/nitrogen/generated/ios/swift/MainMenuLink.swift +34 -0
  34. package/nitrogen/generated/ios/swift/WindowControlsInsets.swift +44 -0
  35. package/nitrogen/generated/shared/c++/HybridReactNativeDeviceUtilsSpec.cpp +6 -0
  36. package/nitrogen/generated/shared/c++/HybridReactNativeDeviceUtilsSpec.hpp +15 -0
  37. package/nitrogen/generated/shared/c++/MainMenuCommand.hpp +80 -0
  38. package/nitrogen/generated/shared/c++/MainMenuConfig.hpp +98 -0
  39. package/nitrogen/generated/shared/c++/MainMenuLink.hpp +87 -0
  40. package/nitrogen/generated/shared/c++/WindowControlsInsets.hpp +95 -0
  41. package/package.json +7 -7
  42. package/src/ReactNativeDeviceUtils.nitro.ts +54 -0
@@ -0,0 +1,151 @@
1
+ import Foundation
2
+ import UIKit
3
+ import ReactNativeNativeLogger
4
+
5
+ /// Tracks how much room the key window's system window controls (the iPadOS
6
+ /// window controls in the top-leading corner, for example) take beyond the
7
+ /// safe area.
8
+ ///
9
+ /// UIKit reports the controls through the safe area with horizontal corner
10
+ /// adaptation (iOS 26+). An invisible view spanning the window recomputes the
11
+ /// difference on every layout and safe area change, so window resizes and
12
+ /// entering or leaving full screen update the value.
13
+ final class WindowControlsInsetsObserver {
14
+ static let shared = WindowControlsInsetsObserver()
15
+
16
+ private let lock = NSLock()
17
+ private var insets = WindowControlsInsets(top: 0, left: 0, bottom: 0, right: 0)
18
+ private var listeners: [Double: (WindowControlsInsets) -> Void] = [:]
19
+ private var nextListenerId: Double = 1
20
+ private var keyWindowObserver: NSObjectProtocol?
21
+ private weak var trackingView: UIView?
22
+
23
+ private init() {
24
+ DispatchQueue.main.async { [weak self] in
25
+ self?.install()
26
+ }
27
+ }
28
+
29
+ var currentInsets: WindowControlsInsets {
30
+ lock.lock()
31
+ defer { lock.unlock() }
32
+ return insets
33
+ }
34
+
35
+ func addListener(_ callback: @escaping (WindowControlsInsets) -> Void) -> Double {
36
+ lock.lock()
37
+ defer { lock.unlock() }
38
+ let id = nextListenerId
39
+ nextListenerId += 1
40
+ listeners[id] = callback
41
+ return id
42
+ }
43
+
44
+ func removeListener(_ id: Double) {
45
+ lock.lock()
46
+ defer { lock.unlock() }
47
+ listeners.removeValue(forKey: id)
48
+ }
49
+
50
+ private func install(in keyWindow: UIWindow? = nil) {
51
+ // UIView.LayoutRegion ships in the iOS 26 SDK (Swift 6.2). Older
52
+ // toolchains and systems keep the all-zero value.
53
+ #if compiler(>=6.2)
54
+ guard #available(iOS 26.0, *) else { return }
55
+ if keyWindowObserver == nil {
56
+ keyWindowObserver = NotificationCenter.default.addObserver(
57
+ forName: UIWindow.didBecomeKeyNotification,
58
+ object: nil,
59
+ queue: .main
60
+ ) { [weak self] notification in
61
+ guard let window = notification.object as? UIWindow else { return }
62
+ self?.install(in: window)
63
+ }
64
+ }
65
+ guard let window = keyWindow ?? WindowControlsInsetsObserver.keyWindow() else { return }
66
+ if let view = trackingView, view.window === window {
67
+ update(from: view)
68
+ return
69
+ }
70
+ let view = WindowControlsTrackingView(frame: window.bounds) { [weak self] view in
71
+ self?.update(from: view)
72
+ }
73
+ view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
74
+ view.isUserInteractionEnabled = false
75
+ view.isAccessibilityElement = false
76
+ // Behind the root view controller's view, so it never draws or
77
+ // receives touches above app content.
78
+ let previousView = trackingView
79
+ trackingView = view
80
+ previousView?.removeFromSuperview()
81
+ window.insertSubview(view, at: 0)
82
+ update(from: view)
83
+ #endif
84
+ }
85
+
86
+ #if compiler(>=6.2)
87
+ @available(iOS 26.0, *)
88
+ private func update(from view: UIView) {
89
+ guard view === trackingView else { return }
90
+ let safeArea = view.safeAreaInsets
91
+ let adapted = view.edgeInsets(for: .safeArea(cornerAdaptation: .horizontal))
92
+ let next = WindowControlsInsets(
93
+ top: Double(max(0, adapted.top - safeArea.top)),
94
+ left: Double(max(0, adapted.left - safeArea.left)),
95
+ bottom: Double(max(0, adapted.bottom - safeArea.bottom)),
96
+ right: Double(max(0, adapted.right - safeArea.right))
97
+ )
98
+
99
+ lock.lock()
100
+ let previous = insets
101
+ let didChange = previous.top != next.top
102
+ || previous.left != next.left
103
+ || previous.bottom != next.bottom
104
+ || previous.right != next.right
105
+ if didChange {
106
+ insets = next
107
+ }
108
+ let callbacks = didChange ? Array(listeners.values) : []
109
+ lock.unlock()
110
+
111
+ guard didChange else { return }
112
+ OneKeyLog.debug(
113
+ "DeviceUtils",
114
+ "Window controls insets: top=\(next.top), left=\(next.left), bottom=\(next.bottom), right=\(next.right)"
115
+ )
116
+ callbacks.forEach { $0(next) }
117
+ }
118
+ #endif
119
+
120
+ private static func keyWindow() -> UIWindow? {
121
+ UIApplication.shared.connectedScenes
122
+ .compactMap { $0 as? UIWindowScene }
123
+ .flatMap { $0.windows }
124
+ .first { $0.isKeyWindow }
125
+ }
126
+ }
127
+
128
+ /// Invisible full-window view that reports layout and safe area changes.
129
+ private final class WindowControlsTrackingView: UIView {
130
+ private let onChange: (UIView) -> Void
131
+
132
+ init(frame: CGRect, onChange: @escaping (UIView) -> Void) {
133
+ self.onChange = onChange
134
+ super.init(frame: frame)
135
+ }
136
+
137
+ @available(*, unavailable)
138
+ required init?(coder: NSCoder) {
139
+ fatalError("init(coder:) has not been implemented")
140
+ }
141
+
142
+ override func layoutSubviews() {
143
+ super.layoutSubviews()
144
+ onChange(self)
145
+ }
146
+
147
+ override func safeAreaInsetsDidChange() {
148
+ super.safeAreaInsetsDidChange()
149
+ onChange(self)
150
+ }
151
+ }
@@ -9,6 +9,35 @@ export interface DualScreenInfoRect {
9
9
  width: number;
10
10
  height: number;
11
11
  }
12
+ /**
13
+ * Extra room, in points beyond the safe area, that content near the window
14
+ * corners must leave for system window controls (the iPadOS window controls in
15
+ * the top-leading corner, for example). All zero when no controls are shown.
16
+ */
17
+ export interface WindowControlsInsets {
18
+ top: number;
19
+ left: number;
20
+ bottom: number;
21
+ right: number;
22
+ }
23
+ /** App commands in the iPadOS menu bar that JS performs. */
24
+ export type MainMenuCommand = 'about' | 'preferences' | 'lockNow';
25
+ export interface MainMenuLink {
26
+ title: string;
27
+ url: string;
28
+ }
29
+ /**
30
+ * Localized content of the custom main menu (the iPadOS menu bar). Help links
31
+ * open in the system browser natively; the other items notify JS. An empty
32
+ * `aboutTitle` removes the About item and empty `helpLinks` remove the Help
33
+ * menu.
34
+ */
35
+ export interface MainMenuConfig {
36
+ aboutTitle: string;
37
+ preferencesTitle: string;
38
+ lockNowTitle: string;
39
+ helpLinks: MainMenuLink[];
40
+ }
12
41
  export interface LaunchOptions {
13
42
  launchType: string;
14
43
  deepLink?: string;
@@ -43,6 +72,23 @@ export interface ReactNativeDeviceUtils extends HybridObject<{
43
72
  addSpanningChangedListener(callback: (isSpanning: boolean) => void): number;
44
73
  removeSpanningChangedListener(id: number): void;
45
74
  setUserInterfaceStyle(style: UserInterfaceStyle): void;
75
+ /**
76
+ * Window-controls insets of the app's main window, for content that adapts
77
+ * horizontally (a header row beside the controls). iOS 26+ reads UIKit's
78
+ * safe area with horizontal corner adaptation; Android and older iOS return
79
+ * all zeros. Listeners fire on the main thread when the value changes.
80
+ */
81
+ getWindowControlsInsets(): WindowControlsInsets;
82
+ addWindowControlsInsetsChangedListener(callback: (insets: WindowControlsInsets) => void): number;
83
+ removeWindowControlsInsetsChangedListener(id: number): void;
84
+ /**
85
+ * Replaces the custom main menu content and rebuilds the menu bar. The menu
86
+ * only shows on iPadOS (and in windows with a menu bar); Android ignores it.
87
+ */
88
+ setMainMenuConfig(config: MainMenuConfig): void;
89
+ /** Listeners fire on the main thread when the user picks an app command. */
90
+ addMainMenuCommandListener(callback: (command: MainMenuCommand) => void): number;
91
+ removeMainMenuCommandListener(id: number): void;
46
92
  getLaunchOptions(): Promise<LaunchOptions>;
47
93
  clearLaunchOptions(): Promise<boolean>;
48
94
  getDeviceToken(): Promise<string>;
@@ -0,0 +1,77 @@
1
+ ///
2
+ /// JFunc_void_MainMenuCommand.hpp
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
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include <functional>
12
+
13
+ #include "MainMenuCommand.hpp"
14
+ #include <functional>
15
+ #include <NitroModules/JNICallable.hpp>
16
+ #include "JMainMenuCommand.hpp"
17
+
18
+ namespace margelo::nitro::reactnativedeviceutils {
19
+
20
+ using namespace facebook;
21
+
22
+ /**
23
+ * Represents the Java/Kotlin callback `(command: MainMenuCommand) -> Unit`.
24
+ * This can be passed around between C++ and Java/Kotlin.
25
+ */
26
+ struct JFunc_void_MainMenuCommand: public jni::JavaClass<JFunc_void_MainMenuCommand> {
27
+ public:
28
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/reactnativedeviceutils/Func_void_MainMenuCommand;";
29
+
30
+ public:
31
+ /**
32
+ * Invokes the function this `JFunc_void_MainMenuCommand` instance holds through JNI.
33
+ */
34
+ void invoke(MainMenuCommand command) const {
35
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JMainMenuCommand> /* command */)>("invoke");
36
+ method(self(), JMainMenuCommand::fromCpp(command));
37
+ }
38
+ };
39
+
40
+ /**
41
+ * An implementation of Func_void_MainMenuCommand that is backed by a C++ implementation (using `std::function<...>`)
42
+ */
43
+ class JFunc_void_MainMenuCommand_cxx final: public jni::HybridClass<JFunc_void_MainMenuCommand_cxx, JFunc_void_MainMenuCommand> {
44
+ public:
45
+ static jni::local_ref<JFunc_void_MainMenuCommand::javaobject> fromCpp(const std::function<void(MainMenuCommand /* command */)>& func) {
46
+ return JFunc_void_MainMenuCommand_cxx::newObjectCxxArgs(func);
47
+ }
48
+
49
+ public:
50
+ /**
51
+ * Invokes the C++ `std::function<...>` this `JFunc_void_MainMenuCommand_cxx` instance holds.
52
+ */
53
+ void invoke_cxx(jni::alias_ref<JMainMenuCommand> command) {
54
+ _func(command->toCpp());
55
+ }
56
+
57
+ public:
58
+ [[nodiscard]]
59
+ inline const std::function<void(MainMenuCommand /* command */)>& getFunction() const {
60
+ return _func;
61
+ }
62
+
63
+ public:
64
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/reactnativedeviceutils/Func_void_MainMenuCommand_cxx;";
65
+ static void registerNatives() {
66
+ registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_MainMenuCommand_cxx::invoke_cxx)});
67
+ }
68
+
69
+ private:
70
+ explicit JFunc_void_MainMenuCommand_cxx(const std::function<void(MainMenuCommand /* command */)>& func): _func(func) { }
71
+
72
+ private:
73
+ friend HybridBase;
74
+ std::function<void(MainMenuCommand /* command */)> _func;
75
+ };
76
+
77
+ } // namespace margelo::nitro::reactnativedeviceutils
@@ -0,0 +1,77 @@
1
+ ///
2
+ /// JFunc_void_WindowControlsInsets.hpp
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
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include <functional>
12
+
13
+ #include "WindowControlsInsets.hpp"
14
+ #include <functional>
15
+ #include <NitroModules/JNICallable.hpp>
16
+ #include "JWindowControlsInsets.hpp"
17
+
18
+ namespace margelo::nitro::reactnativedeviceutils {
19
+
20
+ using namespace facebook;
21
+
22
+ /**
23
+ * Represents the Java/Kotlin callback `(insets: WindowControlsInsets) -> Unit`.
24
+ * This can be passed around between C++ and Java/Kotlin.
25
+ */
26
+ struct JFunc_void_WindowControlsInsets: public jni::JavaClass<JFunc_void_WindowControlsInsets> {
27
+ public:
28
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/reactnativedeviceutils/Func_void_WindowControlsInsets;";
29
+
30
+ public:
31
+ /**
32
+ * Invokes the function this `JFunc_void_WindowControlsInsets` instance holds through JNI.
33
+ */
34
+ void invoke(const WindowControlsInsets& insets) const {
35
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JWindowControlsInsets> /* insets */)>("invoke");
36
+ method(self(), JWindowControlsInsets::fromCpp(insets));
37
+ }
38
+ };
39
+
40
+ /**
41
+ * An implementation of Func_void_WindowControlsInsets that is backed by a C++ implementation (using `std::function<...>`)
42
+ */
43
+ class JFunc_void_WindowControlsInsets_cxx final: public jni::HybridClass<JFunc_void_WindowControlsInsets_cxx, JFunc_void_WindowControlsInsets> {
44
+ public:
45
+ static jni::local_ref<JFunc_void_WindowControlsInsets::javaobject> fromCpp(const std::function<void(const WindowControlsInsets& /* insets */)>& func) {
46
+ return JFunc_void_WindowControlsInsets_cxx::newObjectCxxArgs(func);
47
+ }
48
+
49
+ public:
50
+ /**
51
+ * Invokes the C++ `std::function<...>` this `JFunc_void_WindowControlsInsets_cxx` instance holds.
52
+ */
53
+ void invoke_cxx(jni::alias_ref<JWindowControlsInsets> insets) {
54
+ _func(insets->toCpp());
55
+ }
56
+
57
+ public:
58
+ [[nodiscard]]
59
+ inline const std::function<void(const WindowControlsInsets& /* insets */)>& getFunction() const {
60
+ return _func;
61
+ }
62
+
63
+ public:
64
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/reactnativedeviceutils/Func_void_WindowControlsInsets_cxx;";
65
+ static void registerNatives() {
66
+ registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_WindowControlsInsets_cxx::invoke_cxx)});
67
+ }
68
+
69
+ private:
70
+ explicit JFunc_void_WindowControlsInsets_cxx(const std::function<void(const WindowControlsInsets& /* insets */)>& func): _func(func) { }
71
+
72
+ private:
73
+ friend HybridBase;
74
+ std::function<void(const WindowControlsInsets& /* insets */)> _func;
75
+ };
76
+
77
+ } // namespace margelo::nitro::reactnativedeviceutils
@@ -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 `WindowControlsInsets` to properly resolve imports.
13
+ namespace margelo::nitro::reactnativedeviceutils { struct WindowControlsInsets; }
12
14
  // Forward declaration of `LaunchOptions` to properly resolve imports.
13
15
  namespace margelo::nitro::reactnativedeviceutils { struct LaunchOptions; }
14
16
  // Forward declaration of `WebViewPackageInfo` to properly resolve imports.
@@ -21,12 +23,20 @@ namespace margelo::nitro::reactnativedeviceutils { enum class AndroidChannel; }
21
23
  namespace margelo::nitro::reactnativedeviceutils { enum class InstallerPackageName; }
22
24
  // Forward declaration of `UserInterfaceStyle` to properly resolve imports.
23
25
  namespace margelo::nitro::reactnativedeviceutils { enum class UserInterfaceStyle; }
26
+ // Forward declaration of `MainMenuConfig` to properly resolve imports.
27
+ namespace margelo::nitro::reactnativedeviceutils { struct MainMenuConfig; }
28
+ // Forward declaration of `MainMenuLink` to properly resolve imports.
29
+ namespace margelo::nitro::reactnativedeviceutils { struct MainMenuLink; }
30
+ // Forward declaration of `MainMenuCommand` to properly resolve imports.
31
+ namespace margelo::nitro::reactnativedeviceutils { enum class MainMenuCommand; }
24
32
 
25
33
  #include "DualScreenInfoRect.hpp"
26
34
  #include <vector>
27
35
  #include <NitroModules/Promise.hpp>
28
36
  #include <NitroModules/JPromise.hpp>
29
37
  #include "JDualScreenInfoRect.hpp"
38
+ #include "WindowControlsInsets.hpp"
39
+ #include "JWindowControlsInsets.hpp"
30
40
  #include "LaunchOptions.hpp"
31
41
  #include "JLaunchOptions.hpp"
32
42
  #include <string>
@@ -47,6 +57,14 @@ namespace margelo::nitro::reactnativedeviceutils { enum class UserInterfaceStyle
47
57
  #include <NitroModules/JNICallable.hpp>
48
58
  #include "UserInterfaceStyle.hpp"
49
59
  #include "JUserInterfaceStyle.hpp"
60
+ #include "JFunc_void_WindowControlsInsets.hpp"
61
+ #include "MainMenuConfig.hpp"
62
+ #include "JMainMenuConfig.hpp"
63
+ #include "MainMenuLink.hpp"
64
+ #include "JMainMenuLink.hpp"
65
+ #include "MainMenuCommand.hpp"
66
+ #include "JFunc_void_MainMenuCommand.hpp"
67
+ #include "JMainMenuCommand.hpp"
50
68
 
51
69
  namespace margelo::nitro::reactnativedeviceutils {
52
70
 
@@ -157,6 +175,33 @@ namespace margelo::nitro::reactnativedeviceutils {
157
175
  static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JUserInterfaceStyle> /* style */)>("setUserInterfaceStyle");
158
176
  method(_javaPart, JUserInterfaceStyle::fromCpp(style));
159
177
  }
178
+ WindowControlsInsets JHybridReactNativeDeviceUtilsSpec::getWindowControlsInsets() {
179
+ static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JWindowControlsInsets>()>("getWindowControlsInsets");
180
+ auto __result = method(_javaPart);
181
+ return __result->toCpp();
182
+ }
183
+ double JHybridReactNativeDeviceUtilsSpec::addWindowControlsInsetsChangedListener(const std::function<void(const WindowControlsInsets& /* insets */)>& callback) {
184
+ static const auto method = _javaPart->javaClassStatic()->getMethod<double(jni::alias_ref<JFunc_void_WindowControlsInsets::javaobject> /* callback */)>("addWindowControlsInsetsChangedListener_cxx");
185
+ auto __result = method(_javaPart, JFunc_void_WindowControlsInsets_cxx::fromCpp(callback));
186
+ return __result;
187
+ }
188
+ void JHybridReactNativeDeviceUtilsSpec::removeWindowControlsInsetsChangedListener(double id) {
189
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(double /* id */)>("removeWindowControlsInsetsChangedListener");
190
+ method(_javaPart, id);
191
+ }
192
+ void JHybridReactNativeDeviceUtilsSpec::setMainMenuConfig(const MainMenuConfig& config) {
193
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(jni::alias_ref<JMainMenuConfig> /* config */)>("setMainMenuConfig");
194
+ method(_javaPart, JMainMenuConfig::fromCpp(config));
195
+ }
196
+ double JHybridReactNativeDeviceUtilsSpec::addMainMenuCommandListener(const std::function<void(MainMenuCommand /* command */)>& callback) {
197
+ static const auto method = _javaPart->javaClassStatic()->getMethod<double(jni::alias_ref<JFunc_void_MainMenuCommand::javaobject> /* callback */)>("addMainMenuCommandListener_cxx");
198
+ auto __result = method(_javaPart, JFunc_void_MainMenuCommand_cxx::fromCpp(callback));
199
+ return __result;
200
+ }
201
+ void JHybridReactNativeDeviceUtilsSpec::removeMainMenuCommandListener(double id) {
202
+ static const auto method = _javaPart->javaClassStatic()->getMethod<void(double /* id */)>("removeMainMenuCommandListener");
203
+ method(_javaPart, id);
204
+ }
160
205
  std::shared_ptr<Promise<LaunchOptions>> JHybridReactNativeDeviceUtilsSpec::getLaunchOptions() {
161
206
  static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("getLaunchOptions");
162
207
  auto __result = method(_javaPart);
@@ -64,6 +64,12 @@ namespace margelo::nitro::reactnativedeviceutils {
64
64
  double addSpanningChangedListener(const std::function<void(bool /* isSpanning */)>& callback) override;
65
65
  void removeSpanningChangedListener(double id) override;
66
66
  void setUserInterfaceStyle(UserInterfaceStyle style) override;
67
+ WindowControlsInsets getWindowControlsInsets() override;
68
+ double addWindowControlsInsetsChangedListener(const std::function<void(const WindowControlsInsets& /* insets */)>& callback) override;
69
+ void removeWindowControlsInsetsChangedListener(double id) override;
70
+ void setMainMenuConfig(const MainMenuConfig& config) override;
71
+ double addMainMenuCommandListener(const std::function<void(MainMenuCommand /* command */)>& callback) override;
72
+ void removeMainMenuCommandListener(double id) override;
67
73
  std::shared_ptr<Promise<LaunchOptions>> getLaunchOptions() override;
68
74
  std::shared_ptr<Promise<bool>> clearLaunchOptions() override;
69
75
  std::shared_ptr<Promise<std::string>> getDeviceToken() override;
@@ -0,0 +1,61 @@
1
+ ///
2
+ /// JMainMenuCommand.hpp
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
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "MainMenuCommand.hpp"
12
+
13
+ namespace margelo::nitro::reactnativedeviceutils {
14
+
15
+ using namespace facebook;
16
+
17
+ /**
18
+ * The C++ JNI bridge between the C++ enum "MainMenuCommand" and the Kotlin enum "MainMenuCommand".
19
+ */
20
+ struct JMainMenuCommand final: public jni::JavaClass<JMainMenuCommand> {
21
+ public:
22
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/reactnativedeviceutils/MainMenuCommand;";
23
+
24
+ public:
25
+ /**
26
+ * Convert this Java/Kotlin-based enum to the C++ enum MainMenuCommand.
27
+ */
28
+ [[maybe_unused]]
29
+ [[nodiscard]]
30
+ MainMenuCommand 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<MainMenuCommand>(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<JMainMenuCommand> fromCpp(MainMenuCommand value) {
43
+ static const auto clazz = javaClassStatic();
44
+ switch (value) {
45
+ case MainMenuCommand::ABOUT:
46
+ static const auto fieldABOUT = clazz->getStaticField<JMainMenuCommand>("ABOUT");
47
+ return clazz->getStaticFieldValue(fieldABOUT);
48
+ case MainMenuCommand::PREFERENCES:
49
+ static const auto fieldPREFERENCES = clazz->getStaticField<JMainMenuCommand>("PREFERENCES");
50
+ return clazz->getStaticFieldValue(fieldPREFERENCES);
51
+ case MainMenuCommand::LOCKNOW:
52
+ static const auto fieldLOCKNOW = clazz->getStaticField<JMainMenuCommand>("LOCKNOW");
53
+ return clazz->getStaticFieldValue(fieldLOCKNOW);
54
+ default:
55
+ std::string stringValue = std::to_string(static_cast<int>(value));
56
+ throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
57
+ }
58
+ }
59
+ };
60
+
61
+ } // namespace margelo::nitro::reactnativedeviceutils
@@ -0,0 +1,90 @@
1
+ ///
2
+ /// JMainMenuConfig.hpp
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
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "MainMenuConfig.hpp"
12
+
13
+ #include "JMainMenuLink.hpp"
14
+ #include "MainMenuLink.hpp"
15
+ #include <string>
16
+ #include <vector>
17
+
18
+ namespace margelo::nitro::reactnativedeviceutils {
19
+
20
+ using namespace facebook;
21
+
22
+ /**
23
+ * The C++ JNI bridge between the C++ struct "MainMenuConfig" and the Kotlin data class "MainMenuConfig".
24
+ */
25
+ struct JMainMenuConfig final: public jni::JavaClass<JMainMenuConfig> {
26
+ public:
27
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/reactnativedeviceutils/MainMenuConfig;";
28
+
29
+ public:
30
+ /**
31
+ * Convert this Java/Kotlin-based struct to the C++ struct MainMenuConfig by copying all values to C++.
32
+ */
33
+ [[maybe_unused]]
34
+ [[nodiscard]]
35
+ MainMenuConfig toCpp() const {
36
+ static const auto clazz = javaClassStatic();
37
+ static const auto fieldAboutTitle = clazz->getField<jni::JString>("aboutTitle");
38
+ jni::local_ref<jni::JString> aboutTitle = this->getFieldValue(fieldAboutTitle);
39
+ static const auto fieldPreferencesTitle = clazz->getField<jni::JString>("preferencesTitle");
40
+ jni::local_ref<jni::JString> preferencesTitle = this->getFieldValue(fieldPreferencesTitle);
41
+ static const auto fieldLockNowTitle = clazz->getField<jni::JString>("lockNowTitle");
42
+ jni::local_ref<jni::JString> lockNowTitle = this->getFieldValue(fieldLockNowTitle);
43
+ static const auto fieldHelpLinks = clazz->getField<jni::JArrayClass<JMainMenuLink>>("helpLinks");
44
+ jni::local_ref<jni::JArrayClass<JMainMenuLink>> helpLinks = this->getFieldValue(fieldHelpLinks);
45
+ return MainMenuConfig(
46
+ aboutTitle->toStdString(),
47
+ preferencesTitle->toStdString(),
48
+ lockNowTitle->toStdString(),
49
+ [&](auto&& __input) {
50
+ size_t __size = __input->size();
51
+ std::vector<MainMenuLink> __vector;
52
+ __vector.reserve(__size);
53
+ for (size_t __i = 0; __i < __size; __i++) {
54
+ auto __element = __input->getElement(__i);
55
+ __vector.push_back(__element->toCpp());
56
+ }
57
+ return __vector;
58
+ }(helpLinks)
59
+ );
60
+ }
61
+
62
+ public:
63
+ /**
64
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
65
+ */
66
+ [[maybe_unused]]
67
+ static jni::local_ref<JMainMenuConfig::javaobject> fromCpp(const MainMenuConfig& value) {
68
+ using JSignature = JMainMenuConfig(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>, jni::alias_ref<jni::JArrayClass<JMainMenuLink>>);
69
+ static const auto clazz = javaClassStatic();
70
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
71
+ return create(
72
+ clazz,
73
+ jni::make_jstring(value.aboutTitle),
74
+ jni::make_jstring(value.preferencesTitle),
75
+ jni::make_jstring(value.lockNowTitle),
76
+ [&](auto&& __input) {
77
+ size_t __size = __input.size();
78
+ jni::local_ref<jni::JArrayClass<JMainMenuLink>> __array = jni::JArrayClass<JMainMenuLink>::newArray(__size);
79
+ for (size_t __i = 0; __i < __size; __i++) {
80
+ const auto& __element = __input[__i];
81
+ auto __elementJni = JMainMenuLink::fromCpp(__element);
82
+ __array->setElement(__i, *__elementJni);
83
+ }
84
+ return __array;
85
+ }(value.helpLinks)
86
+ );
87
+ }
88
+ };
89
+
90
+ } // namespace margelo::nitro::reactnativedeviceutils
@@ -0,0 +1,61 @@
1
+ ///
2
+ /// JMainMenuLink.hpp
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
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "MainMenuLink.hpp"
12
+
13
+ #include <string>
14
+
15
+ namespace margelo::nitro::reactnativedeviceutils {
16
+
17
+ using namespace facebook;
18
+
19
+ /**
20
+ * The C++ JNI bridge between the C++ struct "MainMenuLink" and the Kotlin data class "MainMenuLink".
21
+ */
22
+ struct JMainMenuLink final: public jni::JavaClass<JMainMenuLink> {
23
+ public:
24
+ static constexpr auto kJavaDescriptor = "Lcom/margelo/nitro/reactnativedeviceutils/MainMenuLink;";
25
+
26
+ public:
27
+ /**
28
+ * Convert this Java/Kotlin-based struct to the C++ struct MainMenuLink by copying all values to C++.
29
+ */
30
+ [[maybe_unused]]
31
+ [[nodiscard]]
32
+ MainMenuLink toCpp() const {
33
+ static const auto clazz = javaClassStatic();
34
+ static const auto fieldTitle = clazz->getField<jni::JString>("title");
35
+ jni::local_ref<jni::JString> title = this->getFieldValue(fieldTitle);
36
+ static const auto fieldUrl = clazz->getField<jni::JString>("url");
37
+ jni::local_ref<jni::JString> url = this->getFieldValue(fieldUrl);
38
+ return MainMenuLink(
39
+ title->toStdString(),
40
+ url->toStdString()
41
+ );
42
+ }
43
+
44
+ public:
45
+ /**
46
+ * Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
47
+ */
48
+ [[maybe_unused]]
49
+ static jni::local_ref<JMainMenuLink::javaobject> fromCpp(const MainMenuLink& value) {
50
+ using JSignature = JMainMenuLink(jni::alias_ref<jni::JString>, jni::alias_ref<jni::JString>);
51
+ static const auto clazz = javaClassStatic();
52
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
53
+ return create(
54
+ clazz,
55
+ jni::make_jstring(value.title),
56
+ jni::make_jstring(value.url)
57
+ );
58
+ }
59
+ };
60
+
61
+ } // namespace margelo::nitro::reactnativedeviceutils