react-native-nitro-compass 0.1.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 (105) hide show
  1. package/LICENSE +21 -0
  2. package/NitroCompass.podspec +31 -0
  3. package/README.md +206 -0
  4. package/android/CMakeLists.txt +32 -0
  5. package/android/build.gradle +148 -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 +9 -0
  10. package/android/src/main/java/com/margelo/nitro/nitrocompass/HybridNitroCompass.kt +481 -0
  11. package/android/src/main/java/com/margelo/nitro/nitrocompass/NitroCompassPackage.kt +18 -0
  12. package/app.plugin.js +16 -0
  13. package/ios/Bridge.h +8 -0
  14. package/ios/HybridNitroCompass.swift +473 -0
  15. package/lib/commonjs/hook.js +69 -0
  16. package/lib/commonjs/hook.js.map +1 -0
  17. package/lib/commonjs/index.js +39 -0
  18. package/lib/commonjs/index.js.map +1 -0
  19. package/lib/commonjs/multiplex.js +109 -0
  20. package/lib/commonjs/multiplex.js.map +1 -0
  21. package/lib/commonjs/native.js +9 -0
  22. package/lib/commonjs/native.js.map +1 -0
  23. package/lib/commonjs/package.json +1 -0
  24. package/lib/commonjs/specs/NitroCompass.nitro.js +6 -0
  25. package/lib/commonjs/specs/NitroCompass.nitro.js.map +1 -0
  26. package/lib/module/hook.js +65 -0
  27. package/lib/module/hook.js.map +1 -0
  28. package/lib/module/index.js +6 -0
  29. package/lib/module/index.js.map +1 -0
  30. package/lib/module/multiplex.js +103 -0
  31. package/lib/module/multiplex.js.map +1 -0
  32. package/lib/module/native.js +5 -0
  33. package/lib/module/native.js.map +1 -0
  34. package/lib/module/specs/NitroCompass.nitro.js +4 -0
  35. package/lib/module/specs/NitroCompass.nitro.js.map +1 -0
  36. package/lib/typescript/src/hook.d.ts +49 -0
  37. package/lib/typescript/src/hook.d.ts.map +1 -0
  38. package/lib/typescript/src/index.d.ts +8 -0
  39. package/lib/typescript/src/index.d.ts.map +1 -0
  40. package/lib/typescript/src/multiplex.d.ts +38 -0
  41. package/lib/typescript/src/multiplex.d.ts.map +1 -0
  42. package/lib/typescript/src/native.d.ts +3 -0
  43. package/lib/typescript/src/native.d.ts.map +1 -0
  44. package/lib/typescript/src/specs/NitroCompass.nitro.d.ts +176 -0
  45. package/lib/typescript/src/specs/NitroCompass.nitro.d.ts.map +1 -0
  46. package/nitro.json +30 -0
  47. package/nitrogen/generated/.gitattributes +1 -0
  48. package/nitrogen/generated/android/NitroCompass+autolinking.cmake +81 -0
  49. package/nitrogen/generated/android/NitroCompass+autolinking.gradle +27 -0
  50. package/nitrogen/generated/android/NitroCompassOnLoad.cpp +60 -0
  51. package/nitrogen/generated/android/NitroCompassOnLoad.hpp +34 -0
  52. package/nitrogen/generated/android/c++/JAccuracyQuality.hpp +64 -0
  53. package/nitrogen/generated/android/c++/JCompassSample.hpp +61 -0
  54. package/nitrogen/generated/android/c++/JFunc_void_AccuracyQuality.hpp +77 -0
  55. package/nitrogen/generated/android/c++/JFunc_void_CompassSample.hpp +77 -0
  56. package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
  57. package/nitrogen/generated/android/c++/JHybridNitroCompassSpec.cpp +143 -0
  58. package/nitrogen/generated/android/c++/JHybridNitroCompassSpec.hpp +75 -0
  59. package/nitrogen/generated/android/c++/JPermissionStatus.hpp +61 -0
  60. package/nitrogen/generated/android/c++/JSensorDiagnostics.hpp +58 -0
  61. package/nitrogen/generated/android/c++/JSensorKind.hpp +61 -0
  62. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/AccuracyQuality.kt +25 -0
  63. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/CompassSample.kt +56 -0
  64. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/Func_void_AccuracyQuality.kt +80 -0
  65. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/Func_void_CompassSample.kt +80 -0
  66. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/Func_void_bool.kt +80 -0
  67. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/HybridNitroCompassSpec.kt +118 -0
  68. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/NitroCompassOnLoad.kt +35 -0
  69. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/PermissionStatus.kt +24 -0
  70. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/SensorDiagnostics.kt +51 -0
  71. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocompass/SensorKind.kt +24 -0
  72. package/nitrogen/generated/ios/NitroCompass+autolinking.rb +62 -0
  73. package/nitrogen/generated/ios/NitroCompass-Swift-Cxx-Bridge.cpp +73 -0
  74. package/nitrogen/generated/ios/NitroCompass-Swift-Cxx-Bridge.hpp +267 -0
  75. package/nitrogen/generated/ios/NitroCompass-Swift-Cxx-Umbrella.hpp +61 -0
  76. package/nitrogen/generated/ios/NitroCompassAutolinking.mm +33 -0
  77. package/nitrogen/generated/ios/NitroCompassAutolinking.swift +26 -0
  78. package/nitrogen/generated/ios/c++/HybridNitroCompassSpecSwift.cpp +11 -0
  79. package/nitrogen/generated/ios/c++/HybridNitroCompassSpecSwift.hpp +180 -0
  80. package/nitrogen/generated/ios/swift/AccuracyQuality.swift +48 -0
  81. package/nitrogen/generated/ios/swift/CompassSample.swift +34 -0
  82. package/nitrogen/generated/ios/swift/Func_void_AccuracyQuality.swift +46 -0
  83. package/nitrogen/generated/ios/swift/Func_void_CompassSample.swift +46 -0
  84. package/nitrogen/generated/ios/swift/Func_void_PermissionStatus.swift +46 -0
  85. package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
  86. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
  87. package/nitrogen/generated/ios/swift/HybridNitroCompassSpec.swift +67 -0
  88. package/nitrogen/generated/ios/swift/HybridNitroCompassSpec_cxx.swift +309 -0
  89. package/nitrogen/generated/ios/swift/PermissionStatus.swift +44 -0
  90. package/nitrogen/generated/ios/swift/SensorDiagnostics.swift +29 -0
  91. package/nitrogen/generated/ios/swift/SensorKind.swift +44 -0
  92. package/nitrogen/generated/shared/c++/AccuracyQuality.hpp +84 -0
  93. package/nitrogen/generated/shared/c++/CompassSample.hpp +87 -0
  94. package/nitrogen/generated/shared/c++/HybridNitroCompassSpec.cpp +33 -0
  95. package/nitrogen/generated/shared/c++/HybridNitroCompassSpec.hpp +87 -0
  96. package/nitrogen/generated/shared/c++/PermissionStatus.hpp +80 -0
  97. package/nitrogen/generated/shared/c++/SensorDiagnostics.hpp +84 -0
  98. package/nitrogen/generated/shared/c++/SensorKind.hpp +80 -0
  99. package/package.json +136 -0
  100. package/react-native.config.js +11 -0
  101. package/src/hook.ts +118 -0
  102. package/src/index.ts +28 -0
  103. package/src/multiplex.ts +117 -0
  104. package/src/native.ts +5 -0
  105. package/src/specs/NitroCompass.nitro.ts +193 -0
@@ -0,0 +1,44 @@
1
+ ///
2
+ /// SensorKind.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
+ /**
9
+ * Represents the JS union `SensorKind`, backed by a C++ enum.
10
+ */
11
+ public typealias SensorKind = margelo.nitro.nitrocompass.SensorKind
12
+
13
+ public extension SensorKind {
14
+ /**
15
+ * Get a SensorKind for the given String value, or
16
+ * return `nil` if the given value was invalid/unknown.
17
+ */
18
+ init?(fromString string: String) {
19
+ switch string {
20
+ case "rotationVector":
21
+ self = .rotationvector
22
+ case "geomagneticRotationVector":
23
+ self = .geomagneticrotationvector
24
+ case "coreLocation":
25
+ self = .corelocation
26
+ default:
27
+ return nil
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Get the String value this SensorKind represents.
33
+ */
34
+ var stringValue: String {
35
+ switch self {
36
+ case .rotationvector:
37
+ return "rotationVector"
38
+ case .geomagneticrotationvector:
39
+ return "geomagneticRotationVector"
40
+ case .corelocation:
41
+ return "coreLocation"
42
+ }
43
+ }
44
+ }
@@ -0,0 +1,84 @@
1
+ ///
2
+ /// AccuracyQuality.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
+ #if __has_include(<NitroModules/NitroHash.hpp>)
11
+ #include <NitroModules/NitroHash.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
16
+ #include <NitroModules/JSIConverter.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
21
+ #include <NitroModules/NitroDefines.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ namespace margelo::nitro::nitrocompass {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (AccuracyQuality).
30
+ */
31
+ enum class AccuracyQuality {
32
+ HIGH SWIFT_NAME(high) = 0,
33
+ MEDIUM SWIFT_NAME(medium) = 1,
34
+ LOW SWIFT_NAME(low) = 2,
35
+ UNRELIABLE SWIFT_NAME(unreliable) = 3,
36
+ } CLOSED_ENUM;
37
+
38
+ } // namespace margelo::nitro::nitrocompass
39
+
40
+ namespace margelo::nitro {
41
+
42
+ // C++ AccuracyQuality <> JS AccuracyQuality (union)
43
+ template <>
44
+ struct JSIConverter<margelo::nitro::nitrocompass::AccuracyQuality> final {
45
+ static inline margelo::nitro::nitrocompass::AccuracyQuality fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
46
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
47
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
48
+ case hashString("high"): return margelo::nitro::nitrocompass::AccuracyQuality::HIGH;
49
+ case hashString("medium"): return margelo::nitro::nitrocompass::AccuracyQuality::MEDIUM;
50
+ case hashString("low"): return margelo::nitro::nitrocompass::AccuracyQuality::LOW;
51
+ case hashString("unreliable"): return margelo::nitro::nitrocompass::AccuracyQuality::UNRELIABLE;
52
+ default: [[unlikely]]
53
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum AccuracyQuality - invalid value!");
54
+ }
55
+ }
56
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::nitrocompass::AccuracyQuality arg) {
57
+ switch (arg) {
58
+ case margelo::nitro::nitrocompass::AccuracyQuality::HIGH: return JSIConverter<std::string>::toJSI(runtime, "high");
59
+ case margelo::nitro::nitrocompass::AccuracyQuality::MEDIUM: return JSIConverter<std::string>::toJSI(runtime, "medium");
60
+ case margelo::nitro::nitrocompass::AccuracyQuality::LOW: return JSIConverter<std::string>::toJSI(runtime, "low");
61
+ case margelo::nitro::nitrocompass::AccuracyQuality::UNRELIABLE: return JSIConverter<std::string>::toJSI(runtime, "unreliable");
62
+ default: [[unlikely]]
63
+ throw std::invalid_argument("Cannot convert AccuracyQuality to JS - invalid value: "
64
+ + std::to_string(static_cast<int>(arg)) + "!");
65
+ }
66
+ }
67
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
68
+ if (!value.isString()) {
69
+ return false;
70
+ }
71
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
72
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
73
+ case hashString("high"):
74
+ case hashString("medium"):
75
+ case hashString("low"):
76
+ case hashString("unreliable"):
77
+ return true;
78
+ default:
79
+ return false;
80
+ }
81
+ }
82
+ };
83
+
84
+ } // namespace margelo::nitro
@@ -0,0 +1,87 @@
1
+ ///
2
+ /// CompassSample.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
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+
32
+
33
+
34
+
35
+ namespace margelo::nitro::nitrocompass {
36
+
37
+ /**
38
+ * A struct which can be represented as a JavaScript object (CompassSample).
39
+ */
40
+ struct CompassSample final {
41
+ public:
42
+ double heading SWIFT_PRIVATE;
43
+ double accuracy SWIFT_PRIVATE;
44
+
45
+ public:
46
+ CompassSample() = default;
47
+ explicit CompassSample(double heading, double accuracy): heading(heading), accuracy(accuracy) {}
48
+
49
+ public:
50
+ friend bool operator==(const CompassSample& lhs, const CompassSample& rhs) = default;
51
+ };
52
+
53
+ } // namespace margelo::nitro::nitrocompass
54
+
55
+ namespace margelo::nitro {
56
+
57
+ // C++ CompassSample <> JS CompassSample (object)
58
+ template <>
59
+ struct JSIConverter<margelo::nitro::nitrocompass::CompassSample> final {
60
+ static inline margelo::nitro::nitrocompass::CompassSample fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
61
+ jsi::Object obj = arg.asObject(runtime);
62
+ return margelo::nitro::nitrocompass::CompassSample(
63
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "heading"))),
64
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "accuracy")))
65
+ );
66
+ }
67
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrocompass::CompassSample& arg) {
68
+ jsi::Object obj(runtime);
69
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "heading"), JSIConverter<double>::toJSI(runtime, arg.heading));
70
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "accuracy"), JSIConverter<double>::toJSI(runtime, arg.accuracy));
71
+ return obj;
72
+ }
73
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
74
+ if (!value.isObject()) {
75
+ return false;
76
+ }
77
+ jsi::Object obj = value.getObject(runtime);
78
+ if (!nitro::isPlainObject(runtime, obj)) {
79
+ return false;
80
+ }
81
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "heading")))) return false;
82
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "accuracy")))) return false;
83
+ return true;
84
+ }
85
+ };
86
+
87
+ } // namespace margelo::nitro
@@ -0,0 +1,33 @@
1
+ ///
2
+ /// HybridNitroCompassSpec.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 "HybridNitroCompassSpec.hpp"
9
+
10
+ namespace margelo::nitro::nitrocompass {
11
+
12
+ void HybridNitroCompassSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("start", &HybridNitroCompassSpec::start);
18
+ prototype.registerHybridMethod("stop", &HybridNitroCompassSpec::stop);
19
+ prototype.registerHybridMethod("isStarted", &HybridNitroCompassSpec::isStarted);
20
+ prototype.registerHybridMethod("setFilter", &HybridNitroCompassSpec::setFilter);
21
+ prototype.registerHybridMethod("getDiagnostics", &HybridNitroCompassSpec::getDiagnostics);
22
+ prototype.registerHybridMethod("hasCompass", &HybridNitroCompassSpec::hasCompass);
23
+ prototype.registerHybridMethod("getCurrentHeading", &HybridNitroCompassSpec::getCurrentHeading);
24
+ prototype.registerHybridMethod("setDeclination", &HybridNitroCompassSpec::setDeclination);
25
+ prototype.registerHybridMethod("setOnCalibrationNeeded", &HybridNitroCompassSpec::setOnCalibrationNeeded);
26
+ prototype.registerHybridMethod("setOnInterferenceDetected", &HybridNitroCompassSpec::setOnInterferenceDetected);
27
+ prototype.registerHybridMethod("setPauseOnBackground", &HybridNitroCompassSpec::setPauseOnBackground);
28
+ prototype.registerHybridMethod("getPermissionStatus", &HybridNitroCompassSpec::getPermissionStatus);
29
+ prototype.registerHybridMethod("requestPermission", &HybridNitroCompassSpec::requestPermission);
30
+ });
31
+ }
32
+
33
+ } // namespace margelo::nitro::nitrocompass
@@ -0,0 +1,87 @@
1
+ ///
2
+ /// HybridNitroCompassSpec.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
+ #if __has_include(<NitroModules/HybridObject.hpp>)
11
+ #include <NitroModules/HybridObject.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+
16
+ // Forward declaration of `CompassSample` to properly resolve imports.
17
+ namespace margelo::nitro::nitrocompass { struct CompassSample; }
18
+ // Forward declaration of `SensorDiagnostics` to properly resolve imports.
19
+ namespace margelo::nitro::nitrocompass { struct SensorDiagnostics; }
20
+ // Forward declaration of `AccuracyQuality` to properly resolve imports.
21
+ namespace margelo::nitro::nitrocompass { enum class AccuracyQuality; }
22
+ // Forward declaration of `PermissionStatus` to properly resolve imports.
23
+ namespace margelo::nitro::nitrocompass { enum class PermissionStatus; }
24
+
25
+ #include "CompassSample.hpp"
26
+ #include <functional>
27
+ #include "SensorDiagnostics.hpp"
28
+ #include <optional>
29
+ #include "AccuracyQuality.hpp"
30
+ #include "PermissionStatus.hpp"
31
+ #include <NitroModules/Promise.hpp>
32
+
33
+ namespace margelo::nitro::nitrocompass {
34
+
35
+ using namespace margelo::nitro;
36
+
37
+ /**
38
+ * An abstract base class for `NitroCompass`
39
+ * Inherit this class to create instances of `HybridNitroCompassSpec` in C++.
40
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
41
+ * @example
42
+ * ```cpp
43
+ * class HybridNitroCompass: public HybridNitroCompassSpec {
44
+ * public:
45
+ * HybridNitroCompass(...): HybridObject(TAG) { ... }
46
+ * // ...
47
+ * };
48
+ * ```
49
+ */
50
+ class HybridNitroCompassSpec: public virtual HybridObject {
51
+ public:
52
+ // Constructor
53
+ explicit HybridNitroCompassSpec(): HybridObject(TAG) { }
54
+
55
+ // Destructor
56
+ ~HybridNitroCompassSpec() override = default;
57
+
58
+ public:
59
+ // Properties
60
+
61
+
62
+ public:
63
+ // Methods
64
+ virtual void start(double filterDegrees, const std::function<void(const CompassSample& /* sample */)>& onHeading) = 0;
65
+ virtual void stop() = 0;
66
+ virtual bool isStarted() = 0;
67
+ virtual void setFilter(double degrees) = 0;
68
+ virtual std::optional<SensorDiagnostics> getDiagnostics() = 0;
69
+ virtual bool hasCompass() = 0;
70
+ virtual std::optional<CompassSample> getCurrentHeading() = 0;
71
+ virtual void setDeclination(double degrees) = 0;
72
+ virtual void setOnCalibrationNeeded(const std::function<void(AccuracyQuality /* quality */)>& onChange) = 0;
73
+ virtual void setOnInterferenceDetected(const std::function<void(bool /* interferenceDetected */)>& onChange) = 0;
74
+ virtual void setPauseOnBackground(bool enabled) = 0;
75
+ virtual PermissionStatus getPermissionStatus() = 0;
76
+ virtual std::shared_ptr<Promise<PermissionStatus>> requestPermission() = 0;
77
+
78
+ protected:
79
+ // Hybrid Setup
80
+ void loadHybridMethods() override;
81
+
82
+ protected:
83
+ // Tag for logging
84
+ static constexpr auto TAG = "NitroCompass";
85
+ };
86
+
87
+ } // namespace margelo::nitro::nitrocompass
@@ -0,0 +1,80 @@
1
+ ///
2
+ /// PermissionStatus.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
+ #if __has_include(<NitroModules/NitroHash.hpp>)
11
+ #include <NitroModules/NitroHash.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
16
+ #include <NitroModules/JSIConverter.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
21
+ #include <NitroModules/NitroDefines.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ namespace margelo::nitro::nitrocompass {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (PermissionStatus).
30
+ */
31
+ enum class PermissionStatus {
32
+ GRANTED SWIFT_NAME(granted) = 0,
33
+ DENIED SWIFT_NAME(denied) = 1,
34
+ UNKNOWN SWIFT_NAME(unknown) = 2,
35
+ } CLOSED_ENUM;
36
+
37
+ } // namespace margelo::nitro::nitrocompass
38
+
39
+ namespace margelo::nitro {
40
+
41
+ // C++ PermissionStatus <> JS PermissionStatus (union)
42
+ template <>
43
+ struct JSIConverter<margelo::nitro::nitrocompass::PermissionStatus> final {
44
+ static inline margelo::nitro::nitrocompass::PermissionStatus fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
45
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
46
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
47
+ case hashString("granted"): return margelo::nitro::nitrocompass::PermissionStatus::GRANTED;
48
+ case hashString("denied"): return margelo::nitro::nitrocompass::PermissionStatus::DENIED;
49
+ case hashString("unknown"): return margelo::nitro::nitrocompass::PermissionStatus::UNKNOWN;
50
+ default: [[unlikely]]
51
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum PermissionStatus - invalid value!");
52
+ }
53
+ }
54
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::nitrocompass::PermissionStatus arg) {
55
+ switch (arg) {
56
+ case margelo::nitro::nitrocompass::PermissionStatus::GRANTED: return JSIConverter<std::string>::toJSI(runtime, "granted");
57
+ case margelo::nitro::nitrocompass::PermissionStatus::DENIED: return JSIConverter<std::string>::toJSI(runtime, "denied");
58
+ case margelo::nitro::nitrocompass::PermissionStatus::UNKNOWN: return JSIConverter<std::string>::toJSI(runtime, "unknown");
59
+ default: [[unlikely]]
60
+ throw std::invalid_argument("Cannot convert PermissionStatus to JS - invalid value: "
61
+ + std::to_string(static_cast<int>(arg)) + "!");
62
+ }
63
+ }
64
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
65
+ if (!value.isString()) {
66
+ return false;
67
+ }
68
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
69
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
70
+ case hashString("granted"):
71
+ case hashString("denied"):
72
+ case hashString("unknown"):
73
+ return true;
74
+ default:
75
+ return false;
76
+ }
77
+ }
78
+ };
79
+
80
+ } // namespace margelo::nitro
@@ -0,0 +1,84 @@
1
+ ///
2
+ /// SensorDiagnostics.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
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
11
+ #include <NitroModules/JSIConverter.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
16
+ #include <NitroModules/NitroDefines.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/JSIHelpers.hpp>)
21
+ #include <NitroModules/JSIHelpers.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+ #if __has_include(<NitroModules/PropNameIDCache.hpp>)
26
+ #include <NitroModules/PropNameIDCache.hpp>
27
+ #else
28
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
29
+ #endif
30
+
31
+ // Forward declaration of `SensorKind` to properly resolve imports.
32
+ namespace margelo::nitro::nitrocompass { enum class SensorKind; }
33
+
34
+ #include "SensorKind.hpp"
35
+
36
+ namespace margelo::nitro::nitrocompass {
37
+
38
+ /**
39
+ * A struct which can be represented as a JavaScript object (SensorDiagnostics).
40
+ */
41
+ struct SensorDiagnostics final {
42
+ public:
43
+ SensorKind sensor SWIFT_PRIVATE;
44
+
45
+ public:
46
+ SensorDiagnostics() = default;
47
+ explicit SensorDiagnostics(SensorKind sensor): sensor(sensor) {}
48
+
49
+ public:
50
+ friend bool operator==(const SensorDiagnostics& lhs, const SensorDiagnostics& rhs) = default;
51
+ };
52
+
53
+ } // namespace margelo::nitro::nitrocompass
54
+
55
+ namespace margelo::nitro {
56
+
57
+ // C++ SensorDiagnostics <> JS SensorDiagnostics (object)
58
+ template <>
59
+ struct JSIConverter<margelo::nitro::nitrocompass::SensorDiagnostics> final {
60
+ static inline margelo::nitro::nitrocompass::SensorDiagnostics fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
61
+ jsi::Object obj = arg.asObject(runtime);
62
+ return margelo::nitro::nitrocompass::SensorDiagnostics(
63
+ JSIConverter<margelo::nitro::nitrocompass::SensorKind>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "sensor")))
64
+ );
65
+ }
66
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrocompass::SensorDiagnostics& arg) {
67
+ jsi::Object obj(runtime);
68
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "sensor"), JSIConverter<margelo::nitro::nitrocompass::SensorKind>::toJSI(runtime, arg.sensor));
69
+ return obj;
70
+ }
71
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
72
+ if (!value.isObject()) {
73
+ return false;
74
+ }
75
+ jsi::Object obj = value.getObject(runtime);
76
+ if (!nitro::isPlainObject(runtime, obj)) {
77
+ return false;
78
+ }
79
+ if (!JSIConverter<margelo::nitro::nitrocompass::SensorKind>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "sensor")))) return false;
80
+ return true;
81
+ }
82
+ };
83
+
84
+ } // namespace margelo::nitro
@@ -0,0 +1,80 @@
1
+ ///
2
+ /// SensorKind.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
+ #if __has_include(<NitroModules/NitroHash.hpp>)
11
+ #include <NitroModules/NitroHash.hpp>
12
+ #else
13
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
+ #endif
15
+ #if __has_include(<NitroModules/JSIConverter.hpp>)
16
+ #include <NitroModules/JSIConverter.hpp>
17
+ #else
18
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
+ #endif
20
+ #if __has_include(<NitroModules/NitroDefines.hpp>)
21
+ #include <NitroModules/NitroDefines.hpp>
22
+ #else
23
+ #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
24
+ #endif
25
+
26
+ namespace margelo::nitro::nitrocompass {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (SensorKind).
30
+ */
31
+ enum class SensorKind {
32
+ ROTATIONVECTOR SWIFT_NAME(rotationvector) = 0,
33
+ GEOMAGNETICROTATIONVECTOR SWIFT_NAME(geomagneticrotationvector) = 1,
34
+ CORELOCATION SWIFT_NAME(corelocation) = 2,
35
+ } CLOSED_ENUM;
36
+
37
+ } // namespace margelo::nitro::nitrocompass
38
+
39
+ namespace margelo::nitro {
40
+
41
+ // C++ SensorKind <> JS SensorKind (union)
42
+ template <>
43
+ struct JSIConverter<margelo::nitro::nitrocompass::SensorKind> final {
44
+ static inline margelo::nitro::nitrocompass::SensorKind fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
45
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, arg);
46
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
47
+ case hashString("rotationVector"): return margelo::nitro::nitrocompass::SensorKind::ROTATIONVECTOR;
48
+ case hashString("geomagneticRotationVector"): return margelo::nitro::nitrocompass::SensorKind::GEOMAGNETICROTATIONVECTOR;
49
+ case hashString("coreLocation"): return margelo::nitro::nitrocompass::SensorKind::CORELOCATION;
50
+ default: [[unlikely]]
51
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum SensorKind - invalid value!");
52
+ }
53
+ }
54
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::nitrocompass::SensorKind arg) {
55
+ switch (arg) {
56
+ case margelo::nitro::nitrocompass::SensorKind::ROTATIONVECTOR: return JSIConverter<std::string>::toJSI(runtime, "rotationVector");
57
+ case margelo::nitro::nitrocompass::SensorKind::GEOMAGNETICROTATIONVECTOR: return JSIConverter<std::string>::toJSI(runtime, "geomagneticRotationVector");
58
+ case margelo::nitro::nitrocompass::SensorKind::CORELOCATION: return JSIConverter<std::string>::toJSI(runtime, "coreLocation");
59
+ default: [[unlikely]]
60
+ throw std::invalid_argument("Cannot convert SensorKind to JS - invalid value: "
61
+ + std::to_string(static_cast<int>(arg)) + "!");
62
+ }
63
+ }
64
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
65
+ if (!value.isString()) {
66
+ return false;
67
+ }
68
+ std::string unionValue = JSIConverter<std::string>::fromJSI(runtime, value);
69
+ switch (hashString(unionValue.c_str(), unionValue.size())) {
70
+ case hashString("rotationVector"):
71
+ case hashString("geomagneticRotationVector"):
72
+ case hashString("coreLocation"):
73
+ return true;
74
+ default:
75
+ return false;
76
+ }
77
+ }
78
+ };
79
+
80
+ } // namespace margelo::nitro