@onekeyfe/react-native-device-utils 6.7.0-6 → 6.7.0-61

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 (43) hide show
  1. package/README.md +117 -87
  2. package/android/src/main/java/com/margelo/nitro/reactnativedeviceutils/ReactNativeDeviceUtils.kt +156 -35
  3. package/ios/DualScreenDetector.swift +170 -0
  4. package/ios/MainMenuController.swift +170 -0
  5. package/ios/ReactNativeDeviceUtils.swift +29 -4
  6. package/ios/WindowControlsInsetsObserver.swift +151 -0
  7. package/lib/typescript/src/ReactNativeDeviceUtils.nitro.d.ts +46 -0
  8. package/nitrogen/generated/android/c++/JFunc_void_MainMenuCommand.hpp +77 -0
  9. package/nitrogen/generated/android/c++/JFunc_void_WindowControlsInsets.hpp +77 -0
  10. package/nitrogen/generated/android/c++/JHybridReactNativeDeviceUtilsSpec.cpp +45 -0
  11. package/nitrogen/generated/android/c++/JHybridReactNativeDeviceUtilsSpec.hpp +6 -0
  12. package/nitrogen/generated/android/c++/JMainMenuCommand.hpp +61 -0
  13. package/nitrogen/generated/android/c++/JMainMenuConfig.hpp +90 -0
  14. package/nitrogen/generated/android/c++/JMainMenuLink.hpp +61 -0
  15. package/nitrogen/generated/android/c++/JWindowControlsInsets.hpp +69 -0
  16. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/Func_void_MainMenuCommand.kt +78 -0
  17. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/Func_void_WindowControlsInsets.kt +78 -0
  18. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/HybridReactNativeDeviceUtilsSpec.kt +34 -0
  19. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/MainMenuCommand.kt +24 -0
  20. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/MainMenuConfig.kt +66 -0
  21. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/MainMenuLink.kt +56 -0
  22. package/nitrogen/generated/android/kotlin/com/margelo/nitro/reactnativedeviceutils/WindowControlsInsets.kt +66 -0
  23. package/nitrogen/generated/android/reactnativedeviceutilsOnLoad.cpp +4 -0
  24. package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Bridge.cpp +16 -0
  25. package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Bridge.hpp +73 -0
  26. package/nitrogen/generated/ios/ReactNativeDeviceUtils-Swift-Cxx-Umbrella.hpp +12 -0
  27. package/nitrogen/generated/ios/c++/HybridReactNativeDeviceUtilsSpecSwift.hpp +55 -1
  28. package/nitrogen/generated/ios/swift/Func_void_MainMenuCommand.swift +46 -0
  29. package/nitrogen/generated/ios/swift/Func_void_WindowControlsInsets.swift +46 -0
  30. package/nitrogen/generated/ios/swift/HybridReactNativeDeviceUtilsSpec.swift +6 -0
  31. package/nitrogen/generated/ios/swift/HybridReactNativeDeviceUtilsSpec_cxx.swift +79 -0
  32. package/nitrogen/generated/ios/swift/MainMenuCommand.swift +44 -0
  33. package/nitrogen/generated/ios/swift/MainMenuConfig.swift +50 -0
  34. package/nitrogen/generated/ios/swift/MainMenuLink.swift +34 -0
  35. package/nitrogen/generated/ios/swift/WindowControlsInsets.swift +44 -0
  36. package/nitrogen/generated/shared/c++/HybridReactNativeDeviceUtilsSpec.cpp +6 -0
  37. package/nitrogen/generated/shared/c++/HybridReactNativeDeviceUtilsSpec.hpp +15 -0
  38. package/nitrogen/generated/shared/c++/MainMenuCommand.hpp +80 -0
  39. package/nitrogen/generated/shared/c++/MainMenuConfig.hpp +98 -0
  40. package/nitrogen/generated/shared/c++/MainMenuLink.hpp +87 -0
  41. package/nitrogen/generated/shared/c++/WindowControlsInsets.hpp +95 -0
  42. package/package.json +8 -7
  43. package/src/ReactNativeDeviceUtils.nitro.ts +54 -0
@@ -0,0 +1,170 @@
1
+ import Foundation
2
+ import UIKit
3
+ import ReactNativeNativeLogger
4
+
5
+ /// Owns the app's custom main menu (the iPadOS menu bar).
6
+ ///
7
+ /// JS supplies localized titles and Help links through `setMainMenuConfig`.
8
+ /// The app delegate forwards `buildMenu(with:)` to `buildMenu(withBuilder:)`
9
+ /// (it reaches this class through `NSClassFromString`, because the app target
10
+ /// cannot import Nitro modules). App commands are `UIKeyCommand`s whose action
11
+ /// lives on `UIApplication`, which is always in the responder chain, so the
12
+ /// app delegate needs no command handler.
13
+ public final class MainMenuController: NSObject {
14
+ static let shared = MainMenuController()
15
+
16
+ private struct Link {
17
+ let title: String
18
+ let url: URL
19
+ }
20
+
21
+ private struct Config {
22
+ let aboutTitle: String
23
+ let preferencesTitle: String
24
+ let lockNowTitle: String
25
+ let helpLinks: [Link]
26
+ }
27
+
28
+ private static let aboutMenuIdentifier = UIMenu.Identifier("so.onekey.mainMenu.about")
29
+ private static let settingsMenuIdentifier = UIMenu.Identifier("so.onekey.mainMenu.settings")
30
+
31
+ private let lock = NSLock()
32
+ private var config: Config?
33
+ private var listeners: [Double: (MainMenuCommand) -> Void] = [:]
34
+ private var nextListenerId: Double = 1
35
+
36
+ func setConfig(_ config: MainMenuConfig) {
37
+ let links = config.helpLinks.compactMap { link -> Link? in
38
+ guard let url = URL(string: link.url) else {
39
+ OneKeyLog.warn("DeviceUtils", "Main menu: invalid help link URL")
40
+ return nil
41
+ }
42
+ return Link(title: link.title, url: url)
43
+ }
44
+ let next = Config(
45
+ aboutTitle: config.aboutTitle,
46
+ preferencesTitle: config.preferencesTitle,
47
+ lockNowTitle: config.lockNowTitle,
48
+ helpLinks: links
49
+ )
50
+ lock.lock()
51
+ self.config = next
52
+ lock.unlock()
53
+ DispatchQueue.main.async {
54
+ UIMenuSystem.main.setNeedsRebuild()
55
+ }
56
+ }
57
+
58
+ func addListener(_ callback: @escaping (MainMenuCommand) -> Void) -> Double {
59
+ lock.lock()
60
+ defer { lock.unlock() }
61
+ let id = nextListenerId
62
+ nextListenerId += 1
63
+ listeners[id] = callback
64
+ return id
65
+ }
66
+
67
+ func removeListener(_ id: Double) {
68
+ lock.lock()
69
+ defer { lock.unlock() }
70
+ listeners.removeValue(forKey: id)
71
+ }
72
+
73
+ /// Called by the app delegate's `buildMenu(with:)` on the main thread.
74
+ @objc(buildMenuWithBuilder:)
75
+ public static func buildMenu(withBuilder builder: UIMenuBuilder) {
76
+ shared.build(builder)
77
+ }
78
+
79
+ fileprivate func perform(commandName: String) {
80
+ guard let command = MainMenuCommand(fromString: commandName) else { return }
81
+ lock.lock()
82
+ let callbacks = Array(listeners.values)
83
+ lock.unlock()
84
+ OneKeyLog.info("DeviceUtils", "Main menu command: \(commandName), listeners=\(callbacks.count)")
85
+ callbacks.forEach { $0(command) }
86
+ }
87
+
88
+ private func build(_ builder: UIMenuBuilder) {
89
+ guard builder.system == .main else { return }
90
+
91
+ // A wallet has no documents to open or text to format.
92
+ builder.remove(menu: .file)
93
+ builder.remove(menu: .format)
94
+
95
+ lock.lock()
96
+ let config = self.config
97
+ lock.unlock()
98
+ // Keep the system app and Help menus until JS provides localized titles.
99
+ guard let config else { return }
100
+
101
+ let action = #selector(UIApplication.onekeyPerformMainMenuCommand(_:))
102
+ let about = UICommand(
103
+ title: config.aboutTitle,
104
+ action: action,
105
+ propertyList: MainMenuCommand.about.stringValue
106
+ )
107
+ let preferences = UIKeyCommand(
108
+ title: config.preferencesTitle,
109
+ action: action,
110
+ input: ",",
111
+ modifierFlags: .command,
112
+ propertyList: MainMenuCommand.preferences.stringValue
113
+ )
114
+ let lockNow = UIKeyCommand(
115
+ title: config.lockNowTitle,
116
+ action: action,
117
+ input: "l",
118
+ modifierFlags: [.command, .shift],
119
+ propertyList: MainMenuCommand.locknow.stringValue
120
+ )
121
+ let aboutMenu = UIMenu(
122
+ title: "",
123
+ identifier: MainMenuController.aboutMenuIdentifier,
124
+ options: .displayInline,
125
+ children: [about]
126
+ )
127
+ let settingsMenu = UIMenu(
128
+ title: "",
129
+ identifier: MainMenuController.settingsMenuIdentifier,
130
+ options: .displayInline,
131
+ children: [preferences, lockNow]
132
+ )
133
+
134
+ // The system Preferences item opens the app's page in the Settings app;
135
+ // replace it with the in-app preferences, which own the same shortcut.
136
+ if builder.menu(for: .preferences) != nil {
137
+ builder.replace(menu: .preferences, with: settingsMenu)
138
+ } else {
139
+ builder.insertChild(settingsMenu, atStartOfMenu: .application)
140
+ }
141
+ // An empty About title removes the item (Travel Mode hides About).
142
+ if config.aboutTitle.isEmpty {
143
+ builder.remove(menu: .about)
144
+ } else if builder.menu(for: .about) != nil {
145
+ builder.replace(menu: .about, with: aboutMenu)
146
+ } else {
147
+ builder.insertSibling(aboutMenu, beforeMenu: MainMenuController.settingsMenuIdentifier)
148
+ }
149
+
150
+ if config.helpLinks.isEmpty {
151
+ builder.remove(menu: .help)
152
+ } else if builder.menu(for: .help) != nil {
153
+ let links = config.helpLinks.map { link in
154
+ UIAction(title: link.title) { _ in
155
+ UIApplication.shared.open(link.url)
156
+ }
157
+ }
158
+ builder.replaceChildren(ofMenu: .help) { _ in links }
159
+ }
160
+ }
161
+ }
162
+
163
+ extension UIApplication {
164
+ /// Action of the main menu app commands; the command name is the
165
+ /// command's property list.
166
+ @objc func onekeyPerformMainMenuCommand(_ sender: UICommand) {
167
+ guard let name = sender.propertyList as? String else { return }
168
+ MainMenuController.shared.perform(commandName: name)
169
+ }
170
+ }
@@ -112,14 +112,14 @@ class ReactNativeDeviceUtils: HybridReactNativeDeviceUtilsSpec {
112
112
  }
113
113
 
114
114
  public func isDualScreenDevice() throws -> Bool {
115
- return false
115
+ return DualScreenDetector.shared.isDualScreenDevice
116
116
  }
117
117
 
118
118
  public func initEventListeners() throws -> Void {
119
119
  }
120
-
120
+
121
121
  public func isSpanning() throws -> Bool {
122
- return false
122
+ return DualScreenDetector.shared.isSpanning
123
123
  }
124
124
 
125
125
  public func getWindowRects() throws -> Promise<[DualScreenInfoRect]> {
@@ -132,10 +132,35 @@ class ReactNativeDeviceUtils: HybridReactNativeDeviceUtilsSpec {
132
132
 
133
133
 
134
134
  func addSpanningChangedListener(callback: @escaping (Bool) -> Void) throws -> Double {
135
- return 0
135
+ return DualScreenDetector.shared.addSpanningChangedListener(callback)
136
136
  }
137
137
 
138
138
  func removeSpanningChangedListener(id: Double) throws -> Void {
139
+ DualScreenDetector.shared.removeSpanningChangedListener(id)
140
+ }
141
+
142
+ func getWindowControlsInsets() throws -> WindowControlsInsets {
143
+ return WindowControlsInsetsObserver.shared.currentInsets
144
+ }
145
+
146
+ func addWindowControlsInsetsChangedListener(callback: @escaping (WindowControlsInsets) -> Void) throws -> Double {
147
+ return WindowControlsInsetsObserver.shared.addListener(callback)
148
+ }
149
+
150
+ func removeWindowControlsInsetsChangedListener(id: Double) throws -> Void {
151
+ WindowControlsInsetsObserver.shared.removeListener(id)
152
+ }
153
+
154
+ func setMainMenuConfig(config: MainMenuConfig) throws -> Void {
155
+ MainMenuController.shared.setConfig(config)
156
+ }
157
+
158
+ func addMainMenuCommandListener(callback: @escaping (MainMenuCommand) -> Void) throws -> Double {
159
+ return MainMenuController.shared.addListener(callback)
160
+ }
161
+
162
+ func removeMainMenuCommandListener(id: Double) throws -> Void {
163
+ MainMenuController.shared.removeListener(id)
139
164
  }
140
165
 
141
166
 
@@ -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;