@matiks/rn-app-state 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/FLOW.md +239 -0
  2. package/NitroAppState.podspec +31 -0
  3. package/README.md +72 -0
  4. package/android/CMakeLists.txt +29 -0
  5. package/android/build.gradle +140 -0
  6. package/android/fix-prefab.gradle +51 -0
  7. package/android/gradle.properties +5 -0
  8. package/android/src/main/AndroidManifest.xml +2 -0
  9. package/android/src/main/cpp/cpp-adapter.cpp +6 -0
  10. package/android/src/main/java/com/margelo/nitro/appstate/HybridAppState.kt +188 -0
  11. package/android/src/main/java/com/margelo/nitro/appstate/NitroAppStatePackage.kt +18 -0
  12. package/ios/HybridAppState.swift +224 -0
  13. package/nitro.json +24 -0
  14. package/nitrogen/generated/.gitattributes +1 -0
  15. package/nitrogen/generated/android/NitroAppState+autolinking.cmake +81 -0
  16. package/nitrogen/generated/android/NitroAppState+autolinking.gradle +27 -0
  17. package/nitrogen/generated/android/NitroAppStateOnLoad.cpp +48 -0
  18. package/nitrogen/generated/android/NitroAppStateOnLoad.hpp +25 -0
  19. package/nitrogen/generated/android/c++/JAppStateChangeEvent.hpp +57 -0
  20. package/nitrogen/generated/android/c++/JAppStateListener.hpp +67 -0
  21. package/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
  22. package/nitrogen/generated/android/c++/JFunc_void_AppStateChangeEvent.hpp +78 -0
  23. package/nitrogen/generated/android/c++/JHybridAppStateModuleSpec.cpp +84 -0
  24. package/nitrogen/generated/android/c++/JHybridAppStateModuleSpec.hpp +68 -0
  25. package/nitrogen/generated/android/kotlin/com/margelo/nitro/appstate/AppStateChangeEvent.kt +38 -0
  26. package/nitrogen/generated/android/kotlin/com/margelo/nitro/appstate/AppStateListener.kt +42 -0
  27. package/nitrogen/generated/android/kotlin/com/margelo/nitro/appstate/Func_void.kt +80 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/appstate/Func_void_AppStateChangeEvent.kt +80 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/appstate/HybridAppStateModuleSpec.kt +72 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/appstate/NitroAppStateOnLoad.kt +35 -0
  31. package/nitrogen/generated/ios/NitroAppState+autolinking.rb +60 -0
  32. package/nitrogen/generated/ios/NitroAppState-Swift-Cxx-Bridge.cpp +49 -0
  33. package/nitrogen/generated/ios/NitroAppState-Swift-Cxx-Bridge.hpp +112 -0
  34. package/nitrogen/generated/ios/NitroAppState-Swift-Cxx-Umbrella.hpp +51 -0
  35. package/nitrogen/generated/ios/NitroAppStateAutolinking.mm +33 -0
  36. package/nitrogen/generated/ios/NitroAppStateAutolinking.swift +26 -0
  37. package/nitrogen/generated/ios/c++/HybridAppStateModuleSpecSwift.cpp +11 -0
  38. package/nitrogen/generated/ios/c++/HybridAppStateModuleSpecSwift.hpp +106 -0
  39. package/nitrogen/generated/ios/swift/AppStateChangeEvent.swift +29 -0
  40. package/nitrogen/generated/ios/swift/AppStateListener.swift +37 -0
  41. package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
  42. package/nitrogen/generated/ios/swift/Func_void_AppStateChangeEvent.swift +46 -0
  43. package/nitrogen/generated/ios/swift/HybridAppStateModuleSpec.swift +57 -0
  44. package/nitrogen/generated/ios/swift/HybridAppStateModuleSpec_cxx.swift +172 -0
  45. package/nitrogen/generated/shared/c++/AppStateChangeEvent.hpp +83 -0
  46. package/nitrogen/generated/shared/c++/AppStateListener.hpp +83 -0
  47. package/nitrogen/generated/shared/c++/HybridAppStateModuleSpec.cpp +24 -0
  48. package/nitrogen/generated/shared/c++/HybridAppStateModuleSpec.hpp +70 -0
  49. package/package.json +54 -0
  50. package/src/index.ts +2 -0
  51. package/src/specs/AppState.nitro.ts +57 -0
  52. package/src/useNitroAppState/index.ts +2 -0
  53. package/src/useNitroAppState/types.ts +21 -0
  54. package/src/useNitroAppState/useNitroAppState.native.ts +142 -0
  55. package/src/useNitroAppState/useNitroAppState.web.ts +56 -0
@@ -0,0 +1,72 @@
1
+ ///
2
+ /// HybridAppStateModuleSpec.kt
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
+ package com.margelo.nitro.appstate
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.HybridObject
14
+
15
+ /**
16
+ * A Kotlin class representing the AppStateModule HybridObject.
17
+ * Implement this abstract class to create Kotlin-based instances of AppStateModule.
18
+ */
19
+ @DoNotStrip
20
+ @Keep
21
+ @Suppress(
22
+ "KotlinJniMissingFunction", "unused",
23
+ "RedundantSuppression", "RedundantUnitReturnType", "SimpleRedundantLet",
24
+ "LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
25
+ )
26
+ abstract class HybridAppStateModuleSpec: HybridObject() {
27
+ @DoNotStrip
28
+ private var mHybridData: HybridData = initHybrid()
29
+
30
+ init {
31
+ super.updateNative(mHybridData)
32
+ }
33
+
34
+ override fun updateNative(hybridData: HybridData) {
35
+ mHybridData = hybridData
36
+ super.updateNative(hybridData)
37
+ }
38
+
39
+ // Default implementation of `HybridObject.toString()`
40
+ override fun toString(): String {
41
+ return "[HybridObject AppStateModule]"
42
+ }
43
+
44
+ // Properties
45
+ @get:DoNotStrip
46
+ @get:Keep
47
+ abstract val wasKilledLastSession: Boolean
48
+
49
+ // Methods
50
+ @DoNotStrip
51
+ @Keep
52
+ abstract fun getCurrentState(): String
53
+
54
+ abstract fun addListener(onStateChange: (event: AppStateChangeEvent) -> Unit): AppStateListener
55
+
56
+ @DoNotStrip
57
+ @Keep
58
+ private fun addListener_cxx(onStateChange: Func_void_AppStateChangeEvent): AppStateListener {
59
+ val __result = addListener(onStateChange)
60
+ return __result
61
+ }
62
+
63
+ @DoNotStrip
64
+ @Keep
65
+ abstract fun getStateOnNotification(): String
66
+
67
+ private external fun initHybrid(): HybridData
68
+
69
+ companion object {
70
+ protected const val TAG = "HybridAppStateModuleSpec"
71
+ }
72
+ }
@@ -0,0 +1,35 @@
1
+ ///
2
+ /// NitroAppStateOnLoad.kt
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
+ package com.margelo.nitro.appstate
9
+
10
+ import android.util.Log
11
+
12
+ internal class NitroAppStateOnLoad {
13
+ companion object {
14
+ private const val TAG = "NitroAppStateOnLoad"
15
+ private var didLoad = false
16
+ /**
17
+ * Initializes the native part of "NitroAppState".
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 NitroAppState C++ library...")
25
+ System.loadLibrary("NitroAppState")
26
+ Log.i(TAG, "Successfully loaded NitroAppState C++ library!")
27
+ didLoad = true
28
+ } catch (e: Error) {
29
+ Log.e(TAG, "Failed to load NitroAppState 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
+ }
@@ -0,0 +1,60 @@
1
+ #
2
+ # NitroAppState+autolinking.rb
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
+ # This is a Ruby script that adds all files generated by Nitrogen
9
+ # to the given podspec.
10
+ #
11
+ # To use it, add this to your .podspec:
12
+ # ```ruby
13
+ # Pod::Spec.new do |spec|
14
+ # # ...
15
+ #
16
+ # # Add all files generated by Nitrogen
17
+ # load 'nitrogen/generated/ios/NitroAppState+autolinking.rb'
18
+ # add_nitrogen_files(spec)
19
+ # end
20
+ # ```
21
+
22
+ def add_nitrogen_files(spec)
23
+ Pod::UI.puts "[NitroModules] 🔥 NitroAppState is boosted by nitro!"
24
+
25
+ spec.dependency "NitroModules"
26
+
27
+ current_source_files = Array(spec.attributes_hash['source_files'])
28
+ spec.source_files = current_source_files + [
29
+ # Generated cross-platform specs
30
+ "nitrogen/generated/shared/**/*.{h,hpp,c,cpp,swift}",
31
+ # Generated bridges for the cross-platform specs
32
+ "nitrogen/generated/ios/**/*.{h,hpp,c,cpp,mm,swift}",
33
+ ]
34
+
35
+ current_public_header_files = Array(spec.attributes_hash['public_header_files'])
36
+ spec.public_header_files = current_public_header_files + [
37
+ # Generated specs
38
+ "nitrogen/generated/shared/**/*.{h,hpp}",
39
+ # Swift to C++ bridging helpers
40
+ "nitrogen/generated/ios/NitroAppState-Swift-Cxx-Bridge.hpp"
41
+ ]
42
+
43
+ current_private_header_files = Array(spec.attributes_hash['private_header_files'])
44
+ spec.private_header_files = current_private_header_files + [
45
+ # iOS specific specs
46
+ "nitrogen/generated/ios/c++/**/*.{h,hpp}",
47
+ # Views are framework-specific and should be private
48
+ "nitrogen/generated/shared/**/views/**/*"
49
+ ]
50
+
51
+ current_pod_target_xcconfig = spec.attributes_hash['pod_target_xcconfig'] || {}
52
+ spec.pod_target_xcconfig = current_pod_target_xcconfig.merge({
53
+ # Use C++ 20
54
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++20",
55
+ # Enables C++ <-> Swift interop (by default it's only ObjC)
56
+ "SWIFT_OBJC_INTEROP_MODE" => "objcxx",
57
+ # Enables stricter modular headers
58
+ "DEFINES_MODULE" => "YES",
59
+ })
60
+ end
@@ -0,0 +1,49 @@
1
+ ///
2
+ /// NitroAppState-Swift-Cxx-Bridge.cpp
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
+ #include "NitroAppState-Swift-Cxx-Bridge.hpp"
9
+
10
+ // Include C++ implementation defined types
11
+ #include "HybridAppStateModuleSpecSwift.hpp"
12
+ #include "NitroAppState-Swift-Cxx-Umbrella.hpp"
13
+ #include <NitroModules/NitroDefines.hpp>
14
+
15
+ namespace margelo::nitro::appstate::bridge::swift {
16
+
17
+ // pragma MARK: std::function<void()>
18
+ Func_void create_Func_void(void* NON_NULL swiftClosureWrapper) noexcept {
19
+ auto swiftClosure = NitroAppState::Func_void::fromUnsafe(swiftClosureWrapper);
20
+ return [swiftClosure = std::move(swiftClosure)]() mutable -> void {
21
+ swiftClosure.call();
22
+ };
23
+ }
24
+
25
+ // pragma MARK: std::function<void(const AppStateChangeEvent& /* event */)>
26
+ Func_void_AppStateChangeEvent create_Func_void_AppStateChangeEvent(void* NON_NULL swiftClosureWrapper) noexcept {
27
+ auto swiftClosure = NitroAppState::Func_void_AppStateChangeEvent::fromUnsafe(swiftClosureWrapper);
28
+ return [swiftClosure = std::move(swiftClosure)](const AppStateChangeEvent& event) mutable -> void {
29
+ swiftClosure.call(event);
30
+ };
31
+ }
32
+
33
+ // pragma MARK: std::shared_ptr<HybridAppStateModuleSpec>
34
+ std::shared_ptr<HybridAppStateModuleSpec> create_std__shared_ptr_HybridAppStateModuleSpec_(void* NON_NULL swiftUnsafePointer) noexcept {
35
+ NitroAppState::HybridAppStateModuleSpec_cxx swiftPart = NitroAppState::HybridAppStateModuleSpec_cxx::fromUnsafe(swiftUnsafePointer);
36
+ return std::make_shared<margelo::nitro::appstate::HybridAppStateModuleSpecSwift>(swiftPart);
37
+ }
38
+ void* NON_NULL get_std__shared_ptr_HybridAppStateModuleSpec_(std__shared_ptr_HybridAppStateModuleSpec_ cppType) {
39
+ std::shared_ptr<margelo::nitro::appstate::HybridAppStateModuleSpecSwift> swiftWrapper = std::dynamic_pointer_cast<margelo::nitro::appstate::HybridAppStateModuleSpecSwift>(cppType);
40
+ #ifdef NITRO_DEBUG
41
+ if (swiftWrapper == nullptr) [[unlikely]] {
42
+ throw std::runtime_error("Class \"HybridAppStateModuleSpec\" is not implemented in Swift!");
43
+ }
44
+ #endif
45
+ NitroAppState::HybridAppStateModuleSpec_cxx& swiftPart = swiftWrapper->getSwiftPart();
46
+ return swiftPart.toUnsafe();
47
+ }
48
+
49
+ } // namespace margelo::nitro::appstate::bridge::swift
@@ -0,0 +1,112 @@
1
+ ///
2
+ /// NitroAppState-Swift-Cxx-Bridge.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
+ // Forward declarations of C++ defined types
11
+ // Forward declaration of `AppStateChangeEvent` to properly resolve imports.
12
+ namespace margelo::nitro::appstate { struct AppStateChangeEvent; }
13
+ // Forward declaration of `AppStateListener` to properly resolve imports.
14
+ namespace margelo::nitro::appstate { struct AppStateListener; }
15
+ // Forward declaration of `HybridAppStateModuleSpec` to properly resolve imports.
16
+ namespace margelo::nitro::appstate { class HybridAppStateModuleSpec; }
17
+
18
+ // Forward declarations of Swift defined types
19
+ // Forward declaration of `HybridAppStateModuleSpec_cxx` to properly resolve imports.
20
+ namespace NitroAppState { class HybridAppStateModuleSpec_cxx; }
21
+
22
+ // Include C++ defined types
23
+ #include "AppStateChangeEvent.hpp"
24
+ #include "AppStateListener.hpp"
25
+ #include "HybridAppStateModuleSpec.hpp"
26
+ #include <NitroModules/Result.hpp>
27
+ #include <exception>
28
+ #include <functional>
29
+ #include <memory>
30
+ #include <string>
31
+
32
+ /**
33
+ * Contains specialized versions of C++ templated types so they can be accessed from Swift,
34
+ * as well as helper functions to interact with those C++ types from Swift.
35
+ */
36
+ namespace margelo::nitro::appstate::bridge::swift {
37
+
38
+ // pragma MARK: std::function<void()>
39
+ /**
40
+ * Specialized version of `std::function<void()>`.
41
+ */
42
+ using Func_void = std::function<void()>;
43
+ /**
44
+ * Wrapper class for a `std::function<void()>`, this can be used from Swift.
45
+ */
46
+ class Func_void_Wrapper final {
47
+ public:
48
+ explicit Func_void_Wrapper(std::function<void()>&& func): _function(std::make_unique<std::function<void()>>(std::move(func))) {}
49
+ inline void call() const noexcept {
50
+ _function->operator()();
51
+ }
52
+ private:
53
+ std::unique_ptr<std::function<void()>> _function;
54
+ } SWIFT_NONCOPYABLE;
55
+ Func_void create_Func_void(void* NON_NULL swiftClosureWrapper) noexcept;
56
+ inline Func_void_Wrapper wrap_Func_void(Func_void value) noexcept {
57
+ return Func_void_Wrapper(std::move(value));
58
+ }
59
+
60
+ // pragma MARK: std::function<void(const AppStateChangeEvent& /* event */)>
61
+ /**
62
+ * Specialized version of `std::function<void(const AppStateChangeEvent&)>`.
63
+ */
64
+ using Func_void_AppStateChangeEvent = std::function<void(const AppStateChangeEvent& /* event */)>;
65
+ /**
66
+ * Wrapper class for a `std::function<void(const AppStateChangeEvent& / * event * /)>`, this can be used from Swift.
67
+ */
68
+ class Func_void_AppStateChangeEvent_Wrapper final {
69
+ public:
70
+ explicit Func_void_AppStateChangeEvent_Wrapper(std::function<void(const AppStateChangeEvent& /* event */)>&& func): _function(std::make_unique<std::function<void(const AppStateChangeEvent& /* event */)>>(std::move(func))) {}
71
+ inline void call(AppStateChangeEvent event) const noexcept {
72
+ _function->operator()(event);
73
+ }
74
+ private:
75
+ std::unique_ptr<std::function<void(const AppStateChangeEvent& /* event */)>> _function;
76
+ } SWIFT_NONCOPYABLE;
77
+ Func_void_AppStateChangeEvent create_Func_void_AppStateChangeEvent(void* NON_NULL swiftClosureWrapper) noexcept;
78
+ inline Func_void_AppStateChangeEvent_Wrapper wrap_Func_void_AppStateChangeEvent(Func_void_AppStateChangeEvent value) noexcept {
79
+ return Func_void_AppStateChangeEvent_Wrapper(std::move(value));
80
+ }
81
+
82
+ // pragma MARK: std::shared_ptr<HybridAppStateModuleSpec>
83
+ /**
84
+ * Specialized version of `std::shared_ptr<HybridAppStateModuleSpec>`.
85
+ */
86
+ using std__shared_ptr_HybridAppStateModuleSpec_ = std::shared_ptr<HybridAppStateModuleSpec>;
87
+ std::shared_ptr<HybridAppStateModuleSpec> create_std__shared_ptr_HybridAppStateModuleSpec_(void* NON_NULL swiftUnsafePointer) noexcept;
88
+ void* NON_NULL get_std__shared_ptr_HybridAppStateModuleSpec_(std__shared_ptr_HybridAppStateModuleSpec_ cppType);
89
+
90
+ // pragma MARK: std::weak_ptr<HybridAppStateModuleSpec>
91
+ using std__weak_ptr_HybridAppStateModuleSpec_ = std::weak_ptr<HybridAppStateModuleSpec>;
92
+ inline std__weak_ptr_HybridAppStateModuleSpec_ weakify_std__shared_ptr_HybridAppStateModuleSpec_(const std::shared_ptr<HybridAppStateModuleSpec>& strong) noexcept { return strong; }
93
+
94
+ // pragma MARK: Result<std::string>
95
+ using Result_std__string_ = Result<std::string>;
96
+ inline Result_std__string_ create_Result_std__string_(const std::string& value) noexcept {
97
+ return Result<std::string>::withValue(value);
98
+ }
99
+ inline Result_std__string_ create_Result_std__string_(const std::exception_ptr& error) noexcept {
100
+ return Result<std::string>::withError(error);
101
+ }
102
+
103
+ // pragma MARK: Result<AppStateListener>
104
+ using Result_AppStateListener_ = Result<AppStateListener>;
105
+ inline Result_AppStateListener_ create_Result_AppStateListener_(const AppStateListener& value) noexcept {
106
+ return Result<AppStateListener>::withValue(value);
107
+ }
108
+ inline Result_AppStateListener_ create_Result_AppStateListener_(const std::exception_ptr& error) noexcept {
109
+ return Result<AppStateListener>::withError(error);
110
+ }
111
+
112
+ } // namespace margelo::nitro::appstate::bridge::swift
@@ -0,0 +1,51 @@
1
+ ///
2
+ /// NitroAppState-Swift-Cxx-Umbrella.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
+ // Forward declarations of C++ defined types
11
+ // Forward declaration of `AppStateChangeEvent` to properly resolve imports.
12
+ namespace margelo::nitro::appstate { struct AppStateChangeEvent; }
13
+ // Forward declaration of `AppStateListener` to properly resolve imports.
14
+ namespace margelo::nitro::appstate { struct AppStateListener; }
15
+ // Forward declaration of `HybridAppStateModuleSpec` to properly resolve imports.
16
+ namespace margelo::nitro::appstate { class HybridAppStateModuleSpec; }
17
+
18
+ // Include C++ defined types
19
+ #include "AppStateChangeEvent.hpp"
20
+ #include "AppStateListener.hpp"
21
+ #include "HybridAppStateModuleSpec.hpp"
22
+ #include <NitroModules/Result.hpp>
23
+ #include <exception>
24
+ #include <functional>
25
+ #include <memory>
26
+ #include <string>
27
+
28
+ // C++ helpers for Swift
29
+ #include "NitroAppState-Swift-Cxx-Bridge.hpp"
30
+
31
+ // Common C++ types used in Swift
32
+ #include <NitroModules/ArrayBufferHolder.hpp>
33
+ #include <NitroModules/AnyMapUtils.hpp>
34
+ #include <NitroModules/RuntimeError.hpp>
35
+ #include <NitroModules/DateToChronoDate.hpp>
36
+
37
+ // Forward declarations of Swift defined types
38
+ // Forward declaration of `HybridAppStateModuleSpec_cxx` to properly resolve imports.
39
+ namespace NitroAppState { class HybridAppStateModuleSpec_cxx; }
40
+
41
+ // Include Swift defined types
42
+ #if __has_include("NitroAppState-Swift.h")
43
+ // This header is generated by Xcode/Swift on every app build.
44
+ // If it cannot be found, make sure the Swift module's name (= podspec name) is actually "NitroAppState".
45
+ #include "NitroAppState-Swift.h"
46
+ // Same as above, but used when building with frameworks (`use_frameworks`)
47
+ #elif __has_include(<NitroAppState/NitroAppState-Swift.h>)
48
+ #include <NitroAppState/NitroAppState-Swift.h>
49
+ #else
50
+ #error NitroAppState's autogenerated Swift header cannot be found! Make sure the Swift module's name (= podspec name) is actually "NitroAppState", and try building the app first.
51
+ #endif
@@ -0,0 +1,33 @@
1
+ ///
2
+ /// NitroAppStateAutolinking.mm
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
+ #import <Foundation/Foundation.h>
9
+ #import <NitroModules/HybridObjectRegistry.hpp>
10
+ #import "NitroAppState-Swift-Cxx-Umbrella.hpp"
11
+ #import <type_traits>
12
+
13
+ #include "HybridAppStateModuleSpecSwift.hpp"
14
+
15
+ @interface NitroAppStateAutolinking : NSObject
16
+ @end
17
+
18
+ @implementation NitroAppStateAutolinking
19
+
20
+ + (void) load {
21
+ using namespace margelo::nitro;
22
+ using namespace margelo::nitro::appstate;
23
+
24
+ HybridObjectRegistry::registerHybridObjectConstructor(
25
+ "AppStateModule",
26
+ []() -> std::shared_ptr<HybridObject> {
27
+ std::shared_ptr<HybridAppStateModuleSpec> hybridObject = NitroAppState::NitroAppStateAutolinking::createAppStateModule();
28
+ return hybridObject;
29
+ }
30
+ );
31
+ }
32
+
33
+ @end
@@ -0,0 +1,26 @@
1
+ ///
2
+ /// NitroAppStateAutolinking.swift
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
+ import NitroModules
9
+
10
+ // TODO: Use empty enums once Swift supports exporting them as namespaces
11
+ // See: https://github.com/swiftlang/swift/pull/83616
12
+ public final class NitroAppStateAutolinking {
13
+ public typealias bridge = margelo.nitro.appstate.bridge.swift
14
+
15
+ public static func createAppStateModule() -> bridge.std__shared_ptr_HybridAppStateModuleSpec_ {
16
+ let hybridObject = HybridAppState()
17
+ return { () -> bridge.std__shared_ptr_HybridAppStateModuleSpec_ in
18
+ let __cxxWrapped = hybridObject.getCxxWrapper()
19
+ return __cxxWrapped.getCxxPart()
20
+ }()
21
+ }
22
+
23
+ public static func isAppStateModuleRecyclable() -> Bool {
24
+ return HybridAppState.self is any RecyclableView.Type
25
+ }
26
+ }
@@ -0,0 +1,11 @@
1
+ ///
2
+ /// HybridAppStateModuleSpecSwift.cpp
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
+ #include "HybridAppStateModuleSpecSwift.hpp"
9
+
10
+ namespace margelo::nitro::appstate {
11
+ } // namespace margelo::nitro::appstate
@@ -0,0 +1,106 @@
1
+ ///
2
+ /// HybridAppStateModuleSpecSwift.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 "HybridAppStateModuleSpec.hpp"
11
+
12
+ // Forward declaration of `HybridAppStateModuleSpec_cxx` to properly resolve imports.
13
+ namespace NitroAppState { class HybridAppStateModuleSpec_cxx; }
14
+
15
+ // Forward declaration of `AppStateListener` to properly resolve imports.
16
+ namespace margelo::nitro::appstate { struct AppStateListener; }
17
+ // Forward declaration of `AppStateChangeEvent` to properly resolve imports.
18
+ namespace margelo::nitro::appstate { struct AppStateChangeEvent; }
19
+
20
+ #include <string>
21
+ #include "AppStateListener.hpp"
22
+ #include <functional>
23
+ #include "AppStateChangeEvent.hpp"
24
+
25
+ #include "NitroAppState-Swift-Cxx-Umbrella.hpp"
26
+
27
+ namespace margelo::nitro::appstate {
28
+
29
+ /**
30
+ * The C++ part of HybridAppStateModuleSpec_cxx.swift.
31
+ *
32
+ * HybridAppStateModuleSpecSwift (C++) accesses HybridAppStateModuleSpec_cxx (Swift), and might
33
+ * contain some additional bridging code for C++ <> Swift interop.
34
+ *
35
+ * Since this obviously introduces an overhead, I hope at some point in
36
+ * the future, HybridAppStateModuleSpec_cxx can directly inherit from the C++ class HybridAppStateModuleSpec
37
+ * to simplify the whole structure and memory management.
38
+ */
39
+ class HybridAppStateModuleSpecSwift: public virtual HybridAppStateModuleSpec {
40
+ public:
41
+ // Constructor from a Swift instance
42
+ explicit HybridAppStateModuleSpecSwift(const NitroAppState::HybridAppStateModuleSpec_cxx& swiftPart):
43
+ HybridObject(HybridAppStateModuleSpec::TAG),
44
+ _swiftPart(swiftPart) { }
45
+
46
+ public:
47
+ // Get the Swift part
48
+ inline NitroAppState::HybridAppStateModuleSpec_cxx& getSwiftPart() noexcept {
49
+ return _swiftPart;
50
+ }
51
+
52
+ public:
53
+ inline size_t getExternalMemorySize() noexcept override {
54
+ return _swiftPart.getMemorySize();
55
+ }
56
+ bool equals(const std::shared_ptr<HybridObject>& other) override {
57
+ if (auto otherCast = std::dynamic_pointer_cast<HybridAppStateModuleSpecSwift>(other)) {
58
+ return _swiftPart.equals(otherCast->_swiftPart);
59
+ }
60
+ return false;
61
+ }
62
+ void dispose() noexcept override {
63
+ _swiftPart.dispose();
64
+ }
65
+ std::string toString() override {
66
+ return _swiftPart.toString();
67
+ }
68
+
69
+ public:
70
+ // Properties
71
+ inline bool getWasKilledLastSession() noexcept override {
72
+ return _swiftPart.getWasKilledLastSession();
73
+ }
74
+
75
+ public:
76
+ // Methods
77
+ inline std::string getCurrentState() override {
78
+ auto __result = _swiftPart.getCurrentState();
79
+ if (__result.hasError()) [[unlikely]] {
80
+ std::rethrow_exception(__result.error());
81
+ }
82
+ auto __value = std::move(__result.value());
83
+ return __value;
84
+ }
85
+ inline AppStateListener addListener(const std::function<void(const AppStateChangeEvent& /* event */)>& onStateChange) override {
86
+ auto __result = _swiftPart.addListener(onStateChange);
87
+ if (__result.hasError()) [[unlikely]] {
88
+ std::rethrow_exception(__result.error());
89
+ }
90
+ auto __value = std::move(__result.value());
91
+ return __value;
92
+ }
93
+ inline std::string getStateOnNotification() override {
94
+ auto __result = _swiftPart.getStateOnNotification();
95
+ if (__result.hasError()) [[unlikely]] {
96
+ std::rethrow_exception(__result.error());
97
+ }
98
+ auto __value = std::move(__result.value());
99
+ return __value;
100
+ }
101
+
102
+ private:
103
+ NitroAppState::HybridAppStateModuleSpec_cxx _swiftPart;
104
+ };
105
+
106
+ } // namespace margelo::nitro::appstate
@@ -0,0 +1,29 @@
1
+ ///
2
+ /// AppStateChangeEvent.swift
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
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `AppStateChangeEvent`, backed by a C++ struct.
12
+ */
13
+ public typealias AppStateChangeEvent = margelo.nitro.appstate.AppStateChangeEvent
14
+
15
+ public extension AppStateChangeEvent {
16
+ private typealias bridge = margelo.nitro.appstate.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `AppStateChangeEvent`.
20
+ */
21
+ init(state: String) {
22
+ self.init(std.string(state))
23
+ }
24
+
25
+ @inline(__always)
26
+ var state: String {
27
+ return String(self.__state)
28
+ }
29
+ }
@@ -0,0 +1,37 @@
1
+ ///
2
+ /// AppStateListener.swift
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
+ import NitroModules
9
+
10
+ /**
11
+ * Represents an instance of `AppStateListener`, backed by a C++ struct.
12
+ */
13
+ public typealias AppStateListener = margelo.nitro.appstate.AppStateListener
14
+
15
+ public extension AppStateListener {
16
+ private typealias bridge = margelo.nitro.appstate.bridge.swift
17
+
18
+ /**
19
+ * Create a new instance of `AppStateListener`.
20
+ */
21
+ init(remove: @escaping () -> Void) {
22
+ self.init({ () -> bridge.Func_void in
23
+ let __closureWrapper = Func_void(remove)
24
+ return bridge.create_Func_void(__closureWrapper.toUnsafe())
25
+ }())
26
+ }
27
+
28
+ @inline(__always)
29
+ var remove: () -> Void {
30
+ return { () -> () -> Void in
31
+ let __wrappedFunction = bridge.wrap_Func_void(self.__remove)
32
+ return { () -> Void in
33
+ __wrappedFunction.call()
34
+ }
35
+ }()
36
+ }
37
+ }
@@ -0,0 +1,46 @@
1
+ ///
2
+ /// Func_void.swift
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
+ import NitroModules
9
+
10
+ /**
11
+ * Wraps a Swift `() -> Void` as a class.
12
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
13
+ */
14
+ public final class Func_void {
15
+ public typealias bridge = margelo.nitro.appstate.bridge.swift
16
+
17
+ private let closure: () -> Void
18
+
19
+ public init(_ closure: @escaping () -> Void) {
20
+ self.closure = closure
21
+ }
22
+
23
+ @inline(__always)
24
+ public func call() -> Void {
25
+ self.closure()
26
+ }
27
+
28
+ /**
29
+ * Casts this instance to a retained unsafe raw pointer.
30
+ * This acquires one additional strong reference on the object!
31
+ */
32
+ @inline(__always)
33
+ public func toUnsafe() -> UnsafeMutableRawPointer {
34
+ return Unmanaged.passRetained(self).toOpaque()
35
+ }
36
+
37
+ /**
38
+ * Casts an unsafe pointer to a `Func_void`.
39
+ * The pointer has to be a retained opaque `Unmanaged<Func_void>`.
40
+ * This removes one strong reference from the object!
41
+ */
42
+ @inline(__always)
43
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void {
44
+ return Unmanaged<Func_void>.fromOpaque(pointer).takeRetainedValue()
45
+ }
46
+ }