@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.
- package/FLOW.md +239 -0
- package/NitroAppState.podspec +31 -0
- package/README.md +72 -0
- package/android/CMakeLists.txt +29 -0
- package/android/build.gradle +140 -0
- package/android/fix-prefab.gradle +51 -0
- package/android/gradle.properties +5 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/appstate/HybridAppState.kt +188 -0
- package/android/src/main/java/com/margelo/nitro/appstate/NitroAppStatePackage.kt +18 -0
- package/ios/HybridAppState.swift +224 -0
- package/nitro.json +24 -0
- package/nitrogen/generated/.gitattributes +1 -0
- package/nitrogen/generated/android/NitroAppState+autolinking.cmake +81 -0
- package/nitrogen/generated/android/NitroAppState+autolinking.gradle +27 -0
- package/nitrogen/generated/android/NitroAppStateOnLoad.cpp +48 -0
- package/nitrogen/generated/android/NitroAppStateOnLoad.hpp +25 -0
- package/nitrogen/generated/android/c++/JAppStateChangeEvent.hpp +57 -0
- package/nitrogen/generated/android/c++/JAppStateListener.hpp +67 -0
- package/nitrogen/generated/android/c++/JFunc_void.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_AppStateChangeEvent.hpp +78 -0
- package/nitrogen/generated/android/c++/JHybridAppStateModuleSpec.cpp +84 -0
- package/nitrogen/generated/android/c++/JHybridAppStateModuleSpec.hpp +68 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/appstate/AppStateChangeEvent.kt +38 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/appstate/AppStateListener.kt +42 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/appstate/Func_void.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/appstate/Func_void_AppStateChangeEvent.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/appstate/HybridAppStateModuleSpec.kt +72 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/appstate/NitroAppStateOnLoad.kt +35 -0
- package/nitrogen/generated/ios/NitroAppState+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroAppState-Swift-Cxx-Bridge.cpp +49 -0
- package/nitrogen/generated/ios/NitroAppState-Swift-Cxx-Bridge.hpp +112 -0
- package/nitrogen/generated/ios/NitroAppState-Swift-Cxx-Umbrella.hpp +51 -0
- package/nitrogen/generated/ios/NitroAppStateAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroAppStateAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridAppStateModuleSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridAppStateModuleSpecSwift.hpp +106 -0
- package/nitrogen/generated/ios/swift/AppStateChangeEvent.swift +29 -0
- package/nitrogen/generated/ios/swift/AppStateListener.swift +37 -0
- package/nitrogen/generated/ios/swift/Func_void.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_AppStateChangeEvent.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridAppStateModuleSpec.swift +57 -0
- package/nitrogen/generated/ios/swift/HybridAppStateModuleSpec_cxx.swift +172 -0
- package/nitrogen/generated/shared/c++/AppStateChangeEvent.hpp +83 -0
- package/nitrogen/generated/shared/c++/AppStateListener.hpp +83 -0
- package/nitrogen/generated/shared/c++/HybridAppStateModuleSpec.cpp +24 -0
- package/nitrogen/generated/shared/c++/HybridAppStateModuleSpec.hpp +70 -0
- package/package.json +54 -0
- package/src/index.ts +2 -0
- package/src/specs/AppState.nitro.ts +57 -0
- package/src/useNitroAppState/index.ts +2 -0
- package/src/useNitroAppState/types.ts +21 -0
- package/src/useNitroAppState/useNitroAppState.native.ts +142 -0
- package/src/useNitroAppState/useNitroAppState.web.ts +56 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JAppStateChangeEvent.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 "AppStateChangeEvent.hpp"
|
|
12
|
+
|
|
13
|
+
#include <string>
|
|
14
|
+
|
|
15
|
+
namespace margelo::nitro::appstate {
|
|
16
|
+
|
|
17
|
+
using namespace facebook;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The C++ JNI bridge between the C++ struct "AppStateChangeEvent" and the the Kotlin data class "AppStateChangeEvent".
|
|
21
|
+
*/
|
|
22
|
+
struct JAppStateChangeEvent final: public jni::JavaClass<JAppStateChangeEvent> {
|
|
23
|
+
public:
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/appstate/AppStateChangeEvent;";
|
|
25
|
+
|
|
26
|
+
public:
|
|
27
|
+
/**
|
|
28
|
+
* Convert this Java/Kotlin-based struct to the C++ struct AppStateChangeEvent by copying all values to C++.
|
|
29
|
+
*/
|
|
30
|
+
[[maybe_unused]]
|
|
31
|
+
[[nodiscard]]
|
|
32
|
+
AppStateChangeEvent toCpp() const {
|
|
33
|
+
static const auto clazz = javaClassStatic();
|
|
34
|
+
static const auto fieldState = clazz->getField<jni::JString>("state");
|
|
35
|
+
jni::local_ref<jni::JString> state = this->getFieldValue(fieldState);
|
|
36
|
+
return AppStateChangeEvent(
|
|
37
|
+
state->toStdString()
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public:
|
|
42
|
+
/**
|
|
43
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
44
|
+
*/
|
|
45
|
+
[[maybe_unused]]
|
|
46
|
+
static jni::local_ref<JAppStateChangeEvent::javaobject> fromCpp(const AppStateChangeEvent& value) {
|
|
47
|
+
using JSignature = JAppStateChangeEvent(jni::alias_ref<jni::JString>);
|
|
48
|
+
static const auto clazz = javaClassStatic();
|
|
49
|
+
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
50
|
+
return create(
|
|
51
|
+
clazz,
|
|
52
|
+
jni::make_jstring(value.state)
|
|
53
|
+
);
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
} // namespace margelo::nitro::appstate
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JAppStateListener.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 "AppStateListener.hpp"
|
|
12
|
+
|
|
13
|
+
#include "JFunc_void.hpp"
|
|
14
|
+
#include <NitroModules/JNICallable.hpp>
|
|
15
|
+
#include <functional>
|
|
16
|
+
|
|
17
|
+
namespace margelo::nitro::appstate {
|
|
18
|
+
|
|
19
|
+
using namespace facebook;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* The C++ JNI bridge between the C++ struct "AppStateListener" and the the Kotlin data class "AppStateListener".
|
|
23
|
+
*/
|
|
24
|
+
struct JAppStateListener final: public jni::JavaClass<JAppStateListener> {
|
|
25
|
+
public:
|
|
26
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/appstate/AppStateListener;";
|
|
27
|
+
|
|
28
|
+
public:
|
|
29
|
+
/**
|
|
30
|
+
* Convert this Java/Kotlin-based struct to the C++ struct AppStateListener by copying all values to C++.
|
|
31
|
+
*/
|
|
32
|
+
[[maybe_unused]]
|
|
33
|
+
[[nodiscard]]
|
|
34
|
+
AppStateListener toCpp() const {
|
|
35
|
+
static const auto clazz = javaClassStatic();
|
|
36
|
+
static const auto fieldRemove = clazz->getField<JFunc_void::javaobject>("remove");
|
|
37
|
+
jni::local_ref<JFunc_void::javaobject> remove = this->getFieldValue(fieldRemove);
|
|
38
|
+
return AppStateListener(
|
|
39
|
+
[&]() -> std::function<void()> {
|
|
40
|
+
if (remove->isInstanceOf(JFunc_void_cxx::javaClassStatic())) [[likely]] {
|
|
41
|
+
auto downcast = jni::static_ref_cast<JFunc_void_cxx::javaobject>(remove);
|
|
42
|
+
return downcast->cthis()->getFunction();
|
|
43
|
+
} else {
|
|
44
|
+
auto removeRef = jni::make_global(remove);
|
|
45
|
+
return JNICallable<JFunc_void, void()>(std::move(removeRef));
|
|
46
|
+
}
|
|
47
|
+
}()
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
public:
|
|
52
|
+
/**
|
|
53
|
+
* Create a Java/Kotlin-based struct by copying all values from the given C++ struct to Java.
|
|
54
|
+
*/
|
|
55
|
+
[[maybe_unused]]
|
|
56
|
+
static jni::local_ref<JAppStateListener::javaobject> fromCpp(const AppStateListener& value) {
|
|
57
|
+
using JSignature = JAppStateListener(jni::alias_ref<JFunc_void::javaobject>);
|
|
58
|
+
static const auto clazz = javaClassStatic();
|
|
59
|
+
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
60
|
+
return create(
|
|
61
|
+
clazz,
|
|
62
|
+
JFunc_void_cxx::fromCpp(value.remove)
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
} // namespace margelo::nitro::appstate
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JFunc_void.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 <functional>
|
|
14
|
+
#include <NitroModules/JNICallable.hpp>
|
|
15
|
+
|
|
16
|
+
namespace margelo::nitro::appstate {
|
|
17
|
+
|
|
18
|
+
using namespace facebook;
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Represents the Java/Kotlin callback `() -> Unit`.
|
|
22
|
+
* This can be passed around between C++ and Java/Kotlin.
|
|
23
|
+
*/
|
|
24
|
+
struct JFunc_void: public jni::JavaClass<JFunc_void> {
|
|
25
|
+
public:
|
|
26
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/appstate/Func_void;";
|
|
27
|
+
|
|
28
|
+
public:
|
|
29
|
+
/**
|
|
30
|
+
* Invokes the function this `JFunc_void` instance holds through JNI.
|
|
31
|
+
*/
|
|
32
|
+
void invoke() const {
|
|
33
|
+
static const auto method = javaClassStatic()->getMethod<void()>("invoke");
|
|
34
|
+
method(self());
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* An implementation of Func_void that is backed by a C++ implementation (using `std::function<...>`)
|
|
40
|
+
*/
|
|
41
|
+
class JFunc_void_cxx final: public jni::HybridClass<JFunc_void_cxx, JFunc_void> {
|
|
42
|
+
public:
|
|
43
|
+
static jni::local_ref<JFunc_void::javaobject> fromCpp(const std::function<void()>& func) {
|
|
44
|
+
return JFunc_void_cxx::newObjectCxxArgs(func);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
/**
|
|
49
|
+
* Invokes the C++ `std::function<...>` this `JFunc_void_cxx` instance holds.
|
|
50
|
+
*/
|
|
51
|
+
void invoke_cxx() {
|
|
52
|
+
_func();
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
[[nodiscard]]
|
|
57
|
+
inline const std::function<void()>& getFunction() const {
|
|
58
|
+
return _func;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
public:
|
|
62
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/appstate/Func_void_cxx;";
|
|
63
|
+
static void registerNatives() {
|
|
64
|
+
registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_cxx::invoke_cxx)});
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
private:
|
|
68
|
+
explicit JFunc_void_cxx(const std::function<void()>& func): _func(func) { }
|
|
69
|
+
|
|
70
|
+
private:
|
|
71
|
+
friend HybridBase;
|
|
72
|
+
std::function<void()> _func;
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
} // namespace margelo::nitro::appstate
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JFunc_void_AppStateChangeEvent.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 "AppStateChangeEvent.hpp"
|
|
14
|
+
#include <functional>
|
|
15
|
+
#include <NitroModules/JNICallable.hpp>
|
|
16
|
+
#include "JAppStateChangeEvent.hpp"
|
|
17
|
+
#include <string>
|
|
18
|
+
|
|
19
|
+
namespace margelo::nitro::appstate {
|
|
20
|
+
|
|
21
|
+
using namespace facebook;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Represents the Java/Kotlin callback `(event: AppStateChangeEvent) -> Unit`.
|
|
25
|
+
* This can be passed around between C++ and Java/Kotlin.
|
|
26
|
+
*/
|
|
27
|
+
struct JFunc_void_AppStateChangeEvent: public jni::JavaClass<JFunc_void_AppStateChangeEvent> {
|
|
28
|
+
public:
|
|
29
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/appstate/Func_void_AppStateChangeEvent;";
|
|
30
|
+
|
|
31
|
+
public:
|
|
32
|
+
/**
|
|
33
|
+
* Invokes the function this `JFunc_void_AppStateChangeEvent` instance holds through JNI.
|
|
34
|
+
*/
|
|
35
|
+
void invoke(const AppStateChangeEvent& event) const {
|
|
36
|
+
static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JAppStateChangeEvent> /* event */)>("invoke");
|
|
37
|
+
method(self(), JAppStateChangeEvent::fromCpp(event));
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* An implementation of Func_void_AppStateChangeEvent that is backed by a C++ implementation (using `std::function<...>`)
|
|
43
|
+
*/
|
|
44
|
+
class JFunc_void_AppStateChangeEvent_cxx final: public jni::HybridClass<JFunc_void_AppStateChangeEvent_cxx, JFunc_void_AppStateChangeEvent> {
|
|
45
|
+
public:
|
|
46
|
+
static jni::local_ref<JFunc_void_AppStateChangeEvent::javaobject> fromCpp(const std::function<void(const AppStateChangeEvent& /* event */)>& func) {
|
|
47
|
+
return JFunc_void_AppStateChangeEvent_cxx::newObjectCxxArgs(func);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
/**
|
|
52
|
+
* Invokes the C++ `std::function<...>` this `JFunc_void_AppStateChangeEvent_cxx` instance holds.
|
|
53
|
+
*/
|
|
54
|
+
void invoke_cxx(jni::alias_ref<JAppStateChangeEvent> event) {
|
|
55
|
+
_func(event->toCpp());
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
[[nodiscard]]
|
|
60
|
+
inline const std::function<void(const AppStateChangeEvent& /* event */)>& getFunction() const {
|
|
61
|
+
return _func;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
public:
|
|
65
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/appstate/Func_void_AppStateChangeEvent_cxx;";
|
|
66
|
+
static void registerNatives() {
|
|
67
|
+
registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_AppStateChangeEvent_cxx::invoke_cxx)});
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
private:
|
|
71
|
+
explicit JFunc_void_AppStateChangeEvent_cxx(const std::function<void(const AppStateChangeEvent& /* event */)>& func): _func(func) { }
|
|
72
|
+
|
|
73
|
+
private:
|
|
74
|
+
friend HybridBase;
|
|
75
|
+
std::function<void(const AppStateChangeEvent& /* event */)> _func;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
} // namespace margelo::nitro::appstate
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// JHybridAppStateModuleSpec.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 "JHybridAppStateModuleSpec.hpp"
|
|
9
|
+
|
|
10
|
+
// Forward declaration of `AppStateListener` to properly resolve imports.
|
|
11
|
+
namespace margelo::nitro::appstate { struct AppStateListener; }
|
|
12
|
+
// Forward declaration of `AppStateChangeEvent` to properly resolve imports.
|
|
13
|
+
namespace margelo::nitro::appstate { struct AppStateChangeEvent; }
|
|
14
|
+
|
|
15
|
+
#include <string>
|
|
16
|
+
#include "AppStateListener.hpp"
|
|
17
|
+
#include "JAppStateListener.hpp"
|
|
18
|
+
#include <functional>
|
|
19
|
+
#include "JFunc_void.hpp"
|
|
20
|
+
#include <NitroModules/JNICallable.hpp>
|
|
21
|
+
#include "AppStateChangeEvent.hpp"
|
|
22
|
+
#include "JFunc_void_AppStateChangeEvent.hpp"
|
|
23
|
+
#include "JAppStateChangeEvent.hpp"
|
|
24
|
+
|
|
25
|
+
namespace margelo::nitro::appstate {
|
|
26
|
+
|
|
27
|
+
jni::local_ref<JHybridAppStateModuleSpec::jhybriddata> JHybridAppStateModuleSpec::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
28
|
+
return makeCxxInstance(jThis);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
void JHybridAppStateModuleSpec::registerNatives() {
|
|
32
|
+
registerHybrid({
|
|
33
|
+
makeNativeMethod("initHybrid", JHybridAppStateModuleSpec::initHybrid),
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
size_t JHybridAppStateModuleSpec::getExternalMemorySize() noexcept {
|
|
38
|
+
static const auto method = javaClassStatic()->getMethod<jlong()>("getMemorySize");
|
|
39
|
+
return method(_javaPart);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
bool JHybridAppStateModuleSpec::equals(const std::shared_ptr<HybridObject>& other) {
|
|
43
|
+
if (auto otherCast = std::dynamic_pointer_cast<JHybridAppStateModuleSpec>(other)) {
|
|
44
|
+
return _javaPart == otherCast->_javaPart;
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
void JHybridAppStateModuleSpec::dispose() noexcept {
|
|
50
|
+
static const auto method = javaClassStatic()->getMethod<void()>("dispose");
|
|
51
|
+
method(_javaPart);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
std::string JHybridAppStateModuleSpec::toString() {
|
|
55
|
+
static const auto method = javaClassStatic()->getMethod<jni::JString()>("toString");
|
|
56
|
+
auto javaString = method(_javaPart);
|
|
57
|
+
return javaString->toStdString();
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// Properties
|
|
61
|
+
bool JHybridAppStateModuleSpec::getWasKilledLastSession() {
|
|
62
|
+
static const auto method = javaClassStatic()->getMethod<jboolean()>("getWasKilledLastSession");
|
|
63
|
+
auto __result = method(_javaPart);
|
|
64
|
+
return static_cast<bool>(__result);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Methods
|
|
68
|
+
std::string JHybridAppStateModuleSpec::getCurrentState() {
|
|
69
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getCurrentState");
|
|
70
|
+
auto __result = method(_javaPart);
|
|
71
|
+
return __result->toStdString();
|
|
72
|
+
}
|
|
73
|
+
AppStateListener JHybridAppStateModuleSpec::addListener(const std::function<void(const AppStateChangeEvent& /* event */)>& onStateChange) {
|
|
74
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JAppStateListener>(jni::alias_ref<JFunc_void_AppStateChangeEvent::javaobject> /* onStateChange */)>("addListener_cxx");
|
|
75
|
+
auto __result = method(_javaPart, JFunc_void_AppStateChangeEvent_cxx::fromCpp(onStateChange));
|
|
76
|
+
return __result->toCpp();
|
|
77
|
+
}
|
|
78
|
+
std::string JHybridAppStateModuleSpec::getStateOnNotification() {
|
|
79
|
+
static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JString>()>("getStateOnNotification");
|
|
80
|
+
auto __result = method(_javaPart);
|
|
81
|
+
return __result->toStdString();
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
} // namespace margelo::nitro::appstate
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridAppStateModuleSpec.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 <NitroModules/JHybridObject.hpp>
|
|
11
|
+
#include <fbjni/fbjni.h>
|
|
12
|
+
#include "HybridAppStateModuleSpec.hpp"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
namespace margelo::nitro::appstate {
|
|
18
|
+
|
|
19
|
+
using namespace facebook;
|
|
20
|
+
|
|
21
|
+
class JHybridAppStateModuleSpec: public jni::HybridClass<JHybridAppStateModuleSpec, JHybridObject>,
|
|
22
|
+
public virtual HybridAppStateModuleSpec {
|
|
23
|
+
public:
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/appstate/HybridAppStateModuleSpec;";
|
|
25
|
+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
26
|
+
static void registerNatives();
|
|
27
|
+
|
|
28
|
+
protected:
|
|
29
|
+
// C++ constructor (called from Java via `initHybrid()`)
|
|
30
|
+
explicit JHybridAppStateModuleSpec(jni::alias_ref<jhybridobject> jThis) :
|
|
31
|
+
HybridObject(HybridAppStateModuleSpec::TAG),
|
|
32
|
+
HybridBase(jThis),
|
|
33
|
+
_javaPart(jni::make_global(jThis)) {}
|
|
34
|
+
|
|
35
|
+
public:
|
|
36
|
+
~JHybridAppStateModuleSpec() override {
|
|
37
|
+
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
38
|
+
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
public:
|
|
42
|
+
size_t getExternalMemorySize() noexcept override;
|
|
43
|
+
bool equals(const std::shared_ptr<HybridObject>& other) override;
|
|
44
|
+
void dispose() noexcept override;
|
|
45
|
+
std::string toString() override;
|
|
46
|
+
|
|
47
|
+
public:
|
|
48
|
+
inline const jni::global_ref<JHybridAppStateModuleSpec::javaobject>& getJavaPart() const noexcept {
|
|
49
|
+
return _javaPart;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public:
|
|
53
|
+
// Properties
|
|
54
|
+
bool getWasKilledLastSession() override;
|
|
55
|
+
|
|
56
|
+
public:
|
|
57
|
+
// Methods
|
|
58
|
+
std::string getCurrentState() override;
|
|
59
|
+
AppStateListener addListener(const std::function<void(const AppStateChangeEvent& /* event */)>& onStateChange) override;
|
|
60
|
+
std::string getStateOnNotification() override;
|
|
61
|
+
|
|
62
|
+
private:
|
|
63
|
+
friend HybridBase;
|
|
64
|
+
using HybridBase::HybridBase;
|
|
65
|
+
jni::global_ref<JHybridAppStateModuleSpec::javaobject> _javaPart;
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
} // namespace margelo::nitro::appstate
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// AppStateChangeEvent.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.proguard.annotations.DoNotStrip
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Represents the JavaScript object/struct "AppStateChangeEvent".
|
|
16
|
+
*/
|
|
17
|
+
@DoNotStrip
|
|
18
|
+
@Keep
|
|
19
|
+
data class AppStateChangeEvent(
|
|
20
|
+
@DoNotStrip
|
|
21
|
+
@Keep
|
|
22
|
+
val state: String
|
|
23
|
+
) {
|
|
24
|
+
/* primary constructor */
|
|
25
|
+
|
|
26
|
+
companion object {
|
|
27
|
+
/**
|
|
28
|
+
* Constructor called from C++
|
|
29
|
+
*/
|
|
30
|
+
@DoNotStrip
|
|
31
|
+
@Keep
|
|
32
|
+
@Suppress("unused")
|
|
33
|
+
@JvmStatic
|
|
34
|
+
private fun fromCpp(state: String): AppStateChangeEvent {
|
|
35
|
+
return AppStateChangeEvent(state)
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// AppStateListener.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.proguard.annotations.DoNotStrip
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Represents the JavaScript object/struct "AppStateListener".
|
|
16
|
+
*/
|
|
17
|
+
@DoNotStrip
|
|
18
|
+
@Keep
|
|
19
|
+
data class AppStateListener(
|
|
20
|
+
@DoNotStrip
|
|
21
|
+
@Keep
|
|
22
|
+
val remove: Func_void
|
|
23
|
+
) {
|
|
24
|
+
/**
|
|
25
|
+
* Create a new instance of AppStateListener from Kotlin
|
|
26
|
+
*/
|
|
27
|
+
constructor(remove: () -> Unit):
|
|
28
|
+
this(Func_void_java(remove))
|
|
29
|
+
|
|
30
|
+
companion object {
|
|
31
|
+
/**
|
|
32
|
+
* Constructor called from C++
|
|
33
|
+
*/
|
|
34
|
+
@DoNotStrip
|
|
35
|
+
@Keep
|
|
36
|
+
@Suppress("unused")
|
|
37
|
+
@JvmStatic
|
|
38
|
+
private fun fromCpp(remove: Func_void): AppStateListener {
|
|
39
|
+
return AppStateListener(remove)
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void.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 dalvik.annotation.optimization.FastNative
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Represents the JavaScript callback `() => void`.
|
|
18
|
+
* This can be either implemented in C++ (in which case it might be a callback coming from JS),
|
|
19
|
+
* or in Kotlin/Java (in which case it is a native callback).
|
|
20
|
+
*/
|
|
21
|
+
@DoNotStrip
|
|
22
|
+
@Keep
|
|
23
|
+
@Suppress("ClassName", "RedundantUnitReturnType")
|
|
24
|
+
fun interface Func_void: () -> Unit {
|
|
25
|
+
/**
|
|
26
|
+
* Call the given JS callback.
|
|
27
|
+
* @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
|
|
28
|
+
*/
|
|
29
|
+
@DoNotStrip
|
|
30
|
+
@Keep
|
|
31
|
+
override fun invoke(): Unit
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Represents the JavaScript callback `() => void`.
|
|
36
|
+
* This is implemented in C++, via a `std::function<...>`.
|
|
37
|
+
* The callback might be coming from JS.
|
|
38
|
+
*/
|
|
39
|
+
@DoNotStrip
|
|
40
|
+
@Keep
|
|
41
|
+
@Suppress(
|
|
42
|
+
"KotlinJniMissingFunction", "unused",
|
|
43
|
+
"RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
|
|
44
|
+
"ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
|
|
45
|
+
)
|
|
46
|
+
class Func_void_cxx: Func_void {
|
|
47
|
+
@DoNotStrip
|
|
48
|
+
@Keep
|
|
49
|
+
private val mHybridData: HybridData
|
|
50
|
+
|
|
51
|
+
@DoNotStrip
|
|
52
|
+
@Keep
|
|
53
|
+
private constructor(hybridData: HybridData) {
|
|
54
|
+
mHybridData = hybridData
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@DoNotStrip
|
|
58
|
+
@Keep
|
|
59
|
+
override fun invoke(): Unit
|
|
60
|
+
= invoke_cxx()
|
|
61
|
+
|
|
62
|
+
@FastNative
|
|
63
|
+
private external fun invoke_cxx(): Unit
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Represents the JavaScript callback `() => void`.
|
|
68
|
+
* This is implemented in Java/Kotlin, via a `() -> Unit`.
|
|
69
|
+
* The callback is always coming from native.
|
|
70
|
+
*/
|
|
71
|
+
@DoNotStrip
|
|
72
|
+
@Keep
|
|
73
|
+
@Suppress("ClassName", "RedundantUnitReturnType", "unused")
|
|
74
|
+
class Func_void_java(private val function: () -> Unit): Func_void {
|
|
75
|
+
@DoNotStrip
|
|
76
|
+
@Keep
|
|
77
|
+
override fun invoke(): Unit {
|
|
78
|
+
return this.function()
|
|
79
|
+
}
|
|
80
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// Func_void_AppStateChangeEvent.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 dalvik.annotation.optimization.FastNative
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Represents the JavaScript callback `(event: struct) => void`.
|
|
18
|
+
* This can be either implemented in C++ (in which case it might be a callback coming from JS),
|
|
19
|
+
* or in Kotlin/Java (in which case it is a native callback).
|
|
20
|
+
*/
|
|
21
|
+
@DoNotStrip
|
|
22
|
+
@Keep
|
|
23
|
+
@Suppress("ClassName", "RedundantUnitReturnType")
|
|
24
|
+
fun interface Func_void_AppStateChangeEvent: (AppStateChangeEvent) -> Unit {
|
|
25
|
+
/**
|
|
26
|
+
* Call the given JS callback.
|
|
27
|
+
* @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
|
|
28
|
+
*/
|
|
29
|
+
@DoNotStrip
|
|
30
|
+
@Keep
|
|
31
|
+
override fun invoke(event: AppStateChangeEvent): Unit
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Represents the JavaScript callback `(event: struct) => void`.
|
|
36
|
+
* This is implemented in C++, via a `std::function<...>`.
|
|
37
|
+
* The callback might be coming from JS.
|
|
38
|
+
*/
|
|
39
|
+
@DoNotStrip
|
|
40
|
+
@Keep
|
|
41
|
+
@Suppress(
|
|
42
|
+
"KotlinJniMissingFunction", "unused",
|
|
43
|
+
"RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
|
|
44
|
+
"ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
|
|
45
|
+
)
|
|
46
|
+
class Func_void_AppStateChangeEvent_cxx: Func_void_AppStateChangeEvent {
|
|
47
|
+
@DoNotStrip
|
|
48
|
+
@Keep
|
|
49
|
+
private val mHybridData: HybridData
|
|
50
|
+
|
|
51
|
+
@DoNotStrip
|
|
52
|
+
@Keep
|
|
53
|
+
private constructor(hybridData: HybridData) {
|
|
54
|
+
mHybridData = hybridData
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@DoNotStrip
|
|
58
|
+
@Keep
|
|
59
|
+
override fun invoke(event: AppStateChangeEvent): Unit
|
|
60
|
+
= invoke_cxx(event)
|
|
61
|
+
|
|
62
|
+
@FastNative
|
|
63
|
+
private external fun invoke_cxx(event: AppStateChangeEvent): Unit
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Represents the JavaScript callback `(event: struct) => void`.
|
|
68
|
+
* This is implemented in Java/Kotlin, via a `(AppStateChangeEvent) -> Unit`.
|
|
69
|
+
* The callback is always coming from native.
|
|
70
|
+
*/
|
|
71
|
+
@DoNotStrip
|
|
72
|
+
@Keep
|
|
73
|
+
@Suppress("ClassName", "RedundantUnitReturnType", "unused")
|
|
74
|
+
class Func_void_AppStateChangeEvent_java(private val function: (AppStateChangeEvent) -> Unit): Func_void_AppStateChangeEvent {
|
|
75
|
+
@DoNotStrip
|
|
76
|
+
@Keep
|
|
77
|
+
override fun invoke(event: AppStateChangeEvent): Unit {
|
|
78
|
+
return this.function(event)
|
|
79
|
+
}
|
|
80
|
+
}
|