react-native-nitro-geolocation 0.1.2 → 0.3.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 (127) hide show
  1. package/android/src/main/java/com/margelo/nitro/nitrogeolocation/GetCurrentPosition.kt +4 -4
  2. package/android/src/main/java/com/margelo/nitro/nitrogeolocation/NitroGeolocation.kt +642 -50
  3. package/android/src/main/java/com/margelo/nitro/nitrogeolocation/NitroGeolocationCompat.kt +81 -0
  4. package/android/src/main/java/com/margelo/nitro/nitrogeolocation/WatchPosition.kt +4 -4
  5. package/ios/LocationManager.swift +4 -4
  6. package/ios/NitroGeolocation.swift +543 -68
  7. package/ios/NitroGeolocationCompat.swift +109 -0
  8. package/nitrogen/generated/android/c++/JAuthorizationLevel.hpp +61 -0
  9. package/nitrogen/generated/android/c++/JAuthorizationLevelInternal.hpp +3 -4
  10. package/nitrogen/generated/android/c++/JFunc_void.hpp +2 -1
  11. package/nitrogen/generated/android/c++/JFunc_void_GeolocationError.hpp +2 -1
  12. package/nitrogen/generated/android/c++/JFunc_void_GeolocationResponse.hpp +6 -1
  13. package/nitrogen/generated/android/c++/JFunc_void_LocationError.hpp +78 -0
  14. package/nitrogen/generated/android/c++/JGeolocationCoordinates.hpp +25 -17
  15. package/nitrogen/generated/android/c++/JGeolocationError.hpp +5 -1
  16. package/nitrogen/generated/android/c++/JGeolocationOptions.hpp +5 -1
  17. package/nitrogen/generated/android/c++/JGeolocationResponse.hpp +9 -1
  18. package/nitrogen/generated/android/c++/JHybridNitroGeolocationCompatSpec.cpp +109 -0
  19. package/nitrogen/generated/android/c++/JHybridNitroGeolocationCompatSpec.hpp +70 -0
  20. package/nitrogen/generated/android/c++/JHybridNitroGeolocationSpec.cpp +98 -42
  21. package/nitrogen/generated/android/c++/JHybridNitroGeolocationSpec.hpp +7 -5
  22. package/nitrogen/generated/android/c++/JLocationError.hpp +61 -0
  23. package/nitrogen/generated/android/c++/JLocationProvider.hpp +61 -0
  24. package/nitrogen/generated/android/c++/JLocationProviderInternal.hpp +3 -4
  25. package/nitrogen/generated/android/c++/JLocationRequestOptions.hpp +81 -0
  26. package/nitrogen/generated/android/c++/JModernGeolocationConfiguration.hpp +73 -0
  27. package/nitrogen/generated/android/c++/JNullableDouble.cpp +26 -0
  28. package/nitrogen/generated/android/c++/JNullableDouble.hpp +69 -0
  29. package/nitrogen/generated/android/c++/JPermissionStatus.hpp +64 -0
  30. package/nitrogen/generated/android/c++/JRNConfigurationInternal.hpp +5 -1
  31. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/AuthorizationLevel.kt +24 -0
  32. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/AuthorizationLevelInternal.kt +2 -0
  33. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/Func_void.kt +0 -1
  34. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/Func_void_GeolocationError.kt +0 -1
  35. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/Func_void_GeolocationResponse.kt +0 -1
  36. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/Func_void_LocationError.kt +80 -0
  37. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/GeolocationCoordinates.kt +34 -25
  38. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/GeolocationError.kt +27 -18
  39. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/GeolocationOptions.kt +33 -24
  40. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/GeolocationResponse.kt +18 -9
  41. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/HybridNitroGeolocationCompatSpec.kt +92 -0
  42. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/HybridNitroGeolocationSpec.kt +17 -17
  43. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/LocationError.kt +41 -0
  44. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/LocationProvider.kt +24 -0
  45. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/LocationProviderInternal.kt +2 -0
  46. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/LocationRequestOptions.kt +56 -0
  47. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/ModernGeolocationConfiguration.kt +47 -0
  48. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/NullableDouble.kt +59 -0
  49. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/PermissionStatus.kt +25 -0
  50. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/RNConfigurationInternal.kt +24 -15
  51. package/nitrogen/generated/android/nitrogeolocation+autolinking.cmake +3 -0
  52. package/nitrogen/generated/android/nitrogeolocationOnLoad.cpp +14 -2
  53. package/nitrogen/generated/ios/NitroGeolocation+autolinking.rb +1 -1
  54. package/nitrogen/generated/ios/NitroGeolocation-Swift-Cxx-Bridge.cpp +55 -13
  55. package/nitrogen/generated/ios/NitroGeolocation-Swift-Cxx-Bridge.hpp +325 -68
  56. package/nitrogen/generated/ios/NitroGeolocation-Swift-Cxx-Umbrella.hpp +26 -0
  57. package/nitrogen/generated/ios/NitroGeolocationAutolinking.mm +8 -0
  58. package/nitrogen/generated/ios/NitroGeolocationAutolinking.swift +15 -0
  59. package/nitrogen/generated/ios/c++/HybridNitroGeolocationCompatSpecSwift.cpp +11 -0
  60. package/nitrogen/generated/ios/c++/HybridNitroGeolocationCompatSpecSwift.hpp +130 -0
  61. package/nitrogen/generated/ios/c++/HybridNitroGeolocationSpecSwift.hpp +47 -26
  62. package/nitrogen/generated/ios/swift/AuthorizationLevel.swift +44 -0
  63. package/nitrogen/generated/ios/swift/Func_void.swift +1 -1
  64. package/nitrogen/generated/ios/swift/Func_void_GeolocationError.swift +1 -1
  65. package/nitrogen/generated/ios/swift/Func_void_GeolocationResponse.swift +1 -1
  66. package/nitrogen/generated/ios/swift/Func_void_LocationError.swift +47 -0
  67. package/nitrogen/generated/ios/swift/Func_void_PermissionStatus.swift +47 -0
  68. package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +47 -0
  69. package/nitrogen/generated/ios/swift/GeolocationCoordinates.swift +132 -93
  70. package/nitrogen/generated/ios/swift/GeolocationError.swift +11 -40
  71. package/nitrogen/generated/ios/swift/GeolocationOptions.swift +29 -98
  72. package/nitrogen/generated/ios/swift/GeolocationResponse.swift +5 -16
  73. package/nitrogen/generated/ios/swift/HybridNitroGeolocationCompatSpec.swift +61 -0
  74. package/nitrogen/generated/ios/swift/HybridNitroGeolocationCompatSpec_cxx.swift +244 -0
  75. package/nitrogen/generated/ios/swift/HybridNitroGeolocationSpec.swift +13 -5
  76. package/nitrogen/generated/ios/swift/HybridNitroGeolocationSpec_cxx.swift +66 -64
  77. package/nitrogen/generated/ios/swift/LocationError.swift +35 -0
  78. package/nitrogen/generated/ios/swift/LocationProvider.swift +44 -0
  79. package/nitrogen/generated/ios/swift/LocationRequestOptions.swift +116 -0
  80. package/nitrogen/generated/ios/swift/ModernGeolocationConfiguration.swift +83 -0
  81. package/nitrogen/generated/ios/swift/NullableDouble.swift +18 -0
  82. package/nitrogen/generated/ios/swift/PermissionStatus.swift +48 -0
  83. package/nitrogen/generated/ios/swift/RNConfigurationInternal.swift +16 -50
  84. package/nitrogen/generated/shared/c++/AuthorizationLevel.hpp +80 -0
  85. package/nitrogen/generated/shared/c++/GeolocationCoordinates.hpp +45 -27
  86. package/nitrogen/generated/shared/c++/GeolocationError.hpp +32 -16
  87. package/nitrogen/generated/shared/c++/GeolocationOptions.hpp +38 -22
  88. package/nitrogen/generated/shared/c++/GeolocationResponse.hpp +23 -7
  89. package/nitrogen/generated/shared/c++/HybridNitroGeolocationCompatSpec.cpp +26 -0
  90. package/nitrogen/generated/shared/c++/HybridNitroGeolocationCompatSpec.hpp +79 -0
  91. package/nitrogen/generated/shared/c++/HybridNitroGeolocationSpec.cpp +4 -3
  92. package/nitrogen/generated/shared/c++/HybridNitroGeolocationSpec.hpp +22 -16
  93. package/nitrogen/generated/shared/c++/LocationError.hpp +87 -0
  94. package/nitrogen/generated/shared/c++/LocationProvider.hpp +80 -0
  95. package/nitrogen/generated/shared/c++/LocationRequestOptions.hpp +107 -0
  96. package/nitrogen/generated/shared/c++/ModernGeolocationConfiguration.hpp +100 -0
  97. package/nitrogen/generated/shared/c++/PermissionStatus.hpp +84 -0
  98. package/nitrogen/generated/shared/c++/RNConfigurationInternal.hpp +29 -13
  99. package/package.json +16 -7
  100. package/src/GeolocationClient.ts +116 -0
  101. package/src/NitroGeolocation.nitro.ts +177 -30
  102. package/src/NitroGeolocationCompat.nitro.ts +41 -0
  103. package/src/NitroGeolocationModule.ts +6 -0
  104. package/src/compat/clearWatch.ts +9 -0
  105. package/src/{getCurrentPosition.ts → compat/getCurrentPosition.ts} +7 -3
  106. package/src/compat/index.tsx +34 -0
  107. package/src/compat/requestAuthorization.ts +9 -0
  108. package/src/{setRNConfiguration.ts → compat/setRNConfiguration.ts} +6 -4
  109. package/src/{stopObserving.ts → compat/stopObserving.ts} +4 -2
  110. package/src/{watchPosition.ts → compat/watchPosition.ts} +7 -6
  111. package/src/components/GeolocationProvider.tsx +91 -0
  112. package/src/components/index.ts +13 -0
  113. package/src/hooks/index.ts +9 -0
  114. package/src/hooks/useCheckPermission.ts +46 -0
  115. package/src/hooks/useGetCurrentPosition.ts +140 -0
  116. package/src/hooks/useRequestPermission.ts +98 -0
  117. package/src/hooks/useWatchPosition.ts +130 -0
  118. package/src/index.tsx +72 -27
  119. package/src/types.ts +32 -4
  120. package/src/utils/cache.ts +25 -0
  121. package/src/utils/config.ts +93 -0
  122. package/src/utils/errors.ts +82 -0
  123. package/src/utils/index.ts +27 -0
  124. package/src/utils/provider.ts +61 -0
  125. package/src/utils/quality.ts +98 -0
  126. package/src/clearWatch.ts +0 -13
  127. package/src/requestAuthorization.ts +0 -9
@@ -0,0 +1,109 @@
1
+ import CoreLocation
2
+
3
+ class NitroGeolocationCompat: HybridNitroGeolocationCompatSpec {
4
+ // MARK: - Properties
5
+
6
+ private var configuration: RNConfigurationInternal = RNConfigurationInternal(
7
+ skipPermissionRequests: false,
8
+ authorizationLevel: nil,
9
+ enableBackgroundLocationUpdates: nil,
10
+ locationProvider: nil
11
+ )
12
+
13
+ private let locationManager = LocationManager()
14
+
15
+ // MARK: - Public API
16
+
17
+ public func setRNConfiguration(config: RNConfigurationInternal) throws {
18
+ configuration = config
19
+ }
20
+
21
+ public func requestAuthorization(success: (() -> Void)?, error: ((GeolocationError) -> Void)?)
22
+ throws
23
+ {
24
+ let authType = determineAuthorizationType()
25
+ let skipPermissionRequests = configuration.skipPermissionRequests
26
+ let enableBackgroundLocationUpdates = configuration.enableBackgroundLocationUpdates ?? false
27
+
28
+ locationManager.requestAuthorization(
29
+ authType: authType,
30
+ skipPermissionRequests: skipPermissionRequests,
31
+ enableBackgroundLocationUpdates: enableBackgroundLocationUpdates,
32
+ success: success,
33
+ error: error
34
+ )
35
+ }
36
+
37
+ public func getCurrentPosition(
38
+ success: @escaping (GeolocationResponse) -> Void, error: ((GeolocationError) -> Void)?,
39
+ options: GeolocationOptions?
40
+ ) throws {
41
+ // Fast path: check cached location immediately (no dispatch overhead!)
42
+ let parsedOptions = LocationManager.ParsedOptions.parse(from: options)
43
+
44
+ if let cached = locationManager.lastLocation,
45
+ locationManager.isCachedLocationValid(cached, options: parsedOptions) {
46
+ success(locationManager.locationToPosition(cached))
47
+ return
48
+ }
49
+
50
+ // Slow path: need GPS
51
+ locationManager.getCurrentPosition(success: success, error: error, options: options)
52
+ }
53
+
54
+ public func watchPosition(
55
+ success: @escaping (GeolocationResponse) -> Void, error: ((GeolocationError) -> Void)?,
56
+ options: GeolocationOptions?
57
+ ) throws -> Double {
58
+ return locationManager.watchPosition(success: success, error: error, options: options)
59
+ }
60
+
61
+ public func clearWatch(watchId: Double) throws {
62
+ locationManager.clearWatch(watchId: watchId)
63
+ }
64
+
65
+ public func stopObserving() throws {
66
+ locationManager.stopObserving()
67
+ }
68
+
69
+ // MARK: - Authorization Helpers
70
+
71
+ private func determineAuthorizationType() -> LocationManager.AuthorizationType {
72
+ guard let authLevel = configuration.authorizationLevel else {
73
+ return determineAuthorizationTypeFromInfoPlist()
74
+ }
75
+
76
+ switch authLevel {
77
+ case .always:
78
+ return .always
79
+ case .wheninuse:
80
+ return .whenInUse
81
+ case .auto:
82
+ return determineAuthorizationTypeFromInfoPlist()
83
+ }
84
+ }
85
+
86
+ private func determineAuthorizationTypeFromInfoPlist() -> LocationManager.AuthorizationType {
87
+ if hasInfoPlistKey(for: .always) {
88
+ return .always
89
+ } else if hasInfoPlistKey(for: .whenInUse) {
90
+ return .whenInUse
91
+ }
92
+ return .none
93
+ }
94
+
95
+ private func hasInfoPlistKey(for type: LocationManager.AuthorizationType) -> Bool {
96
+ switch type {
97
+ case .always:
98
+ return Bundle.main.object(forInfoDictionaryKey: "NSLocationAlwaysUsageDescription")
99
+ != nil
100
+ || Bundle.main.object(
101
+ forInfoDictionaryKey: "NSLocationAlwaysAndWhenInUseUsageDescription") != nil
102
+ case .whenInUse:
103
+ return Bundle.main.object(forInfoDictionaryKey: "NSLocationWhenInUseUsageDescription")
104
+ != nil
105
+ case .none:
106
+ return false
107
+ }
108
+ }
109
+ }
@@ -0,0 +1,61 @@
1
+ ///
2
+ /// JAuthorizationLevel.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include "AuthorizationLevel.hpp"
12
+
13
+ namespace margelo::nitro::nitrogeolocation {
14
+
15
+ using namespace facebook;
16
+
17
+ /**
18
+ * The C++ JNI bridge between the C++ enum "AuthorizationLevel" and the the Kotlin enum "AuthorizationLevel".
19
+ */
20
+ struct JAuthorizationLevel final: public jni::JavaClass<JAuthorizationLevel> {
21
+ public:
22
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrogeolocation/AuthorizationLevel;";
23
+
24
+ public:
25
+ /**
26
+ * Convert this Java/Kotlin-based enum to the C++ enum AuthorizationLevel.
27
+ */
28
+ [[maybe_unused]]
29
+ [[nodiscard]]
30
+ AuthorizationLevel toCpp() const {
31
+ static const auto clazz = javaClassStatic();
32
+ static const auto fieldOrdinal = clazz->getField<int>("value");
33
+ int ordinal = this->getFieldValue(fieldOrdinal);
34
+ return static_cast<AuthorizationLevel>(ordinal);
35
+ }
36
+
37
+ public:
38
+ /**
39
+ * Create a Java/Kotlin-based enum with the given C++ enum's value.
40
+ */
41
+ [[maybe_unused]]
42
+ static jni::alias_ref<JAuthorizationLevel> fromCpp(AuthorizationLevel value) {
43
+ static const auto clazz = javaClassStatic();
44
+ switch (value) {
45
+ case AuthorizationLevel::ALWAYS:
46
+ static const auto fieldALWAYS = clazz->getStaticField<JAuthorizationLevel>("ALWAYS");
47
+ return clazz->getStaticFieldValue(fieldALWAYS);
48
+ case AuthorizationLevel::WHENINUSE:
49
+ static const auto fieldWHENINUSE = clazz->getStaticField<JAuthorizationLevel>("WHENINUSE");
50
+ return clazz->getStaticFieldValue(fieldWHENINUSE);
51
+ case AuthorizationLevel::AUTO:
52
+ static const auto fieldAUTO = clazz->getStaticField<JAuthorizationLevel>("AUTO");
53
+ return clazz->getStaticFieldValue(fieldAUTO);
54
+ default:
55
+ std::string stringValue = std::to_string(static_cast<int>(value));
56
+ throw std::invalid_argument("Invalid enum value (" + stringValue + "!");
57
+ }
58
+ }
59
+ };
60
+
61
+ } // namespace margelo::nitro::nitrogeolocation
@@ -41,16 +41,15 @@ namespace margelo::nitro::nitrogeolocation {
41
41
  [[maybe_unused]]
42
42
  static jni::alias_ref<JAuthorizationLevelInternal> fromCpp(AuthorizationLevelInternal value) {
43
43
  static const auto clazz = javaClassStatic();
44
- static const auto fieldALWAYS = clazz->getStaticField<JAuthorizationLevelInternal>("ALWAYS");
45
- static const auto fieldWHENINUSE = clazz->getStaticField<JAuthorizationLevelInternal>("WHENINUSE");
46
- static const auto fieldAUTO = clazz->getStaticField<JAuthorizationLevelInternal>("AUTO");
47
-
48
44
  switch (value) {
49
45
  case AuthorizationLevelInternal::ALWAYS:
46
+ static const auto fieldALWAYS = clazz->getStaticField<JAuthorizationLevelInternal>("ALWAYS");
50
47
  return clazz->getStaticFieldValue(fieldALWAYS);
51
48
  case AuthorizationLevelInternal::WHENINUSE:
49
+ static const auto fieldWHENINUSE = clazz->getStaticField<JAuthorizationLevelInternal>("WHENINUSE");
52
50
  return clazz->getStaticFieldValue(fieldWHENINUSE);
53
51
  case AuthorizationLevelInternal::AUTO:
52
+ static const auto fieldAUTO = clazz->getStaticField<JAuthorizationLevelInternal>("AUTO");
54
53
  return clazz->getStaticFieldValue(fieldAUTO);
55
54
  default:
56
55
  std::string stringValue = std::to_string(static_cast<int>(value));
@@ -11,6 +11,7 @@
11
11
  #include <functional>
12
12
 
13
13
  #include <functional>
14
+ #include <NitroModules/JNICallable.hpp>
14
15
 
15
16
  namespace margelo::nitro::nitrogeolocation {
16
17
 
@@ -37,7 +38,7 @@ namespace margelo::nitro::nitrogeolocation {
37
38
  /**
38
39
  * An implementation of Func_void that is backed by a C++ implementation (using `std::function<...>`)
39
40
  */
40
- struct JFunc_void_cxx final: public jni::HybridClass<JFunc_void_cxx, JFunc_void> {
41
+ class JFunc_void_cxx final: public jni::HybridClass<JFunc_void_cxx, JFunc_void> {
41
42
  public:
42
43
  static jni::local_ref<JFunc_void::javaobject> fromCpp(const std::function<void()>& func) {
43
44
  return JFunc_void_cxx::newObjectCxxArgs(func);
@@ -12,6 +12,7 @@
12
12
 
13
13
  #include "GeolocationError.hpp"
14
14
  #include <functional>
15
+ #include <NitroModules/JNICallable.hpp>
15
16
  #include "JGeolocationError.hpp"
16
17
  #include <string>
17
18
 
@@ -40,7 +41,7 @@ namespace margelo::nitro::nitrogeolocation {
40
41
  /**
41
42
  * An implementation of Func_void_GeolocationError that is backed by a C++ implementation (using `std::function<...>`)
42
43
  */
43
- struct JFunc_void_GeolocationError_cxx final: public jni::HybridClass<JFunc_void_GeolocationError_cxx, JFunc_void_GeolocationError> {
44
+ class JFunc_void_GeolocationError_cxx final: public jni::HybridClass<JFunc_void_GeolocationError_cxx, JFunc_void_GeolocationError> {
44
45
  public:
45
46
  static jni::local_ref<JFunc_void_GeolocationError::javaobject> fromCpp(const std::function<void(const GeolocationError& /* error */)>& func) {
46
47
  return JFunc_void_GeolocationError_cxx::newObjectCxxArgs(func);
@@ -12,10 +12,15 @@
12
12
 
13
13
  #include "GeolocationResponse.hpp"
14
14
  #include <functional>
15
+ #include <NitroModules/JNICallable.hpp>
15
16
  #include "JGeolocationResponse.hpp"
16
17
  #include "GeolocationCoordinates.hpp"
17
18
  #include "JGeolocationCoordinates.hpp"
19
+ #include <NitroModules/Null.hpp>
20
+ #include <variant>
18
21
  #include <optional>
22
+ #include "JNullableDouble.hpp"
23
+ #include <NitroModules/JNull.hpp>
19
24
 
20
25
  namespace margelo::nitro::nitrogeolocation {
21
26
 
@@ -42,7 +47,7 @@ namespace margelo::nitro::nitrogeolocation {
42
47
  /**
43
48
  * An implementation of Func_void_GeolocationResponse that is backed by a C++ implementation (using `std::function<...>`)
44
49
  */
45
- struct JFunc_void_GeolocationResponse_cxx final: public jni::HybridClass<JFunc_void_GeolocationResponse_cxx, JFunc_void_GeolocationResponse> {
50
+ class JFunc_void_GeolocationResponse_cxx final: public jni::HybridClass<JFunc_void_GeolocationResponse_cxx, JFunc_void_GeolocationResponse> {
46
51
  public:
47
52
  static jni::local_ref<JFunc_void_GeolocationResponse::javaobject> fromCpp(const std::function<void(const GeolocationResponse& /* position */)>& func) {
48
53
  return JFunc_void_GeolocationResponse_cxx::newObjectCxxArgs(func);
@@ -0,0 +1,78 @@
1
+ ///
2
+ /// JFunc_void_LocationError.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include <functional>
12
+
13
+ #include "LocationError.hpp"
14
+ #include <functional>
15
+ #include <NitroModules/JNICallable.hpp>
16
+ #include "JLocationError.hpp"
17
+ #include <string>
18
+
19
+ namespace margelo::nitro::nitrogeolocation {
20
+
21
+ using namespace facebook;
22
+
23
+ /**
24
+ * Represents the Java/Kotlin callback `(error: LocationError) -> Unit`.
25
+ * This can be passed around between C++ and Java/Kotlin.
26
+ */
27
+ struct JFunc_void_LocationError: public jni::JavaClass<JFunc_void_LocationError> {
28
+ public:
29
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrogeolocation/Func_void_LocationError;";
30
+
31
+ public:
32
+ /**
33
+ * Invokes the function this `JFunc_void_LocationError` instance holds through JNI.
34
+ */
35
+ void invoke(const LocationError& error) const {
36
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JLocationError> /* error */)>("invoke");
37
+ method(self(), JLocationError::fromCpp(error));
38
+ }
39
+ };
40
+
41
+ /**
42
+ * An implementation of Func_void_LocationError that is backed by a C++ implementation (using `std::function<...>`)
43
+ */
44
+ class JFunc_void_LocationError_cxx final: public jni::HybridClass<JFunc_void_LocationError_cxx, JFunc_void_LocationError> {
45
+ public:
46
+ static jni::local_ref<JFunc_void_LocationError::javaobject> fromCpp(const std::function<void(const LocationError& /* error */)>& func) {
47
+ return JFunc_void_LocationError_cxx::newObjectCxxArgs(func);
48
+ }
49
+
50
+ public:
51
+ /**
52
+ * Invokes the C++ `std::function<...>` this `JFunc_void_LocationError_cxx` instance holds.
53
+ */
54
+ void invoke_cxx(jni::alias_ref<JLocationError> error) {
55
+ _func(error->toCpp());
56
+ }
57
+
58
+ public:
59
+ [[nodiscard]]
60
+ inline const std::function<void(const LocationError& /* error */)>& getFunction() const {
61
+ return _func;
62
+ }
63
+
64
+ public:
65
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrogeolocation/Func_void_LocationError_cxx;";
66
+ static void registerNatives() {
67
+ registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_LocationError_cxx::invoke_cxx)});
68
+ }
69
+
70
+ private:
71
+ explicit JFunc_void_LocationError_cxx(const std::function<void(const LocationError& /* error */)>& func): _func(func) { }
72
+
73
+ private:
74
+ friend HybridBase;
75
+ std::function<void(const LocationError& /* error */)> _func;
76
+ };
77
+
78
+ } // namespace margelo::nitro::nitrogeolocation
@@ -10,7 +10,11 @@
10
10
  #include <fbjni/fbjni.h>
11
11
  #include "GeolocationCoordinates.hpp"
12
12
 
13
+ #include "JNullableDouble.hpp"
14
+ #include <NitroModules/JNull.hpp>
15
+ #include <NitroModules/Null.hpp>
13
16
  #include <optional>
17
+ #include <variant>
14
18
 
15
19
  namespace margelo::nitro::nitrogeolocation {
16
20
 
@@ -35,24 +39,24 @@ namespace margelo::nitro::nitrogeolocation {
35
39
  double latitude = this->getFieldValue(fieldLatitude);
36
40
  static const auto fieldLongitude = clazz->getField<double>("longitude");
37
41
  double longitude = this->getFieldValue(fieldLongitude);
38
- static const auto fieldAltitude = clazz->getField<jni::JDouble>("altitude");
39
- jni::local_ref<jni::JDouble> altitude = this->getFieldValue(fieldAltitude);
42
+ static const auto fieldAltitude = clazz->getField<JNullableDouble>("altitude");
43
+ jni::local_ref<JNullableDouble> altitude = this->getFieldValue(fieldAltitude);
40
44
  static const auto fieldAccuracy = clazz->getField<double>("accuracy");
41
45
  double accuracy = this->getFieldValue(fieldAccuracy);
42
- static const auto fieldAltitudeAccuracy = clazz->getField<jni::JDouble>("altitudeAccuracy");
43
- jni::local_ref<jni::JDouble> altitudeAccuracy = this->getFieldValue(fieldAltitudeAccuracy);
44
- static const auto fieldHeading = clazz->getField<jni::JDouble>("heading");
45
- jni::local_ref<jni::JDouble> heading = this->getFieldValue(fieldHeading);
46
- static const auto fieldSpeed = clazz->getField<jni::JDouble>("speed");
47
- jni::local_ref<jni::JDouble> speed = this->getFieldValue(fieldSpeed);
46
+ static const auto fieldAltitudeAccuracy = clazz->getField<JNullableDouble>("altitudeAccuracy");
47
+ jni::local_ref<JNullableDouble> altitudeAccuracy = this->getFieldValue(fieldAltitudeAccuracy);
48
+ static const auto fieldHeading = clazz->getField<JNullableDouble>("heading");
49
+ jni::local_ref<JNullableDouble> heading = this->getFieldValue(fieldHeading);
50
+ static const auto fieldSpeed = clazz->getField<JNullableDouble>("speed");
51
+ jni::local_ref<JNullableDouble> speed = this->getFieldValue(fieldSpeed);
48
52
  return GeolocationCoordinates(
49
53
  latitude,
50
54
  longitude,
51
- altitude != nullptr ? std::make_optional(altitude->value()) : std::nullopt,
55
+ altitude != nullptr ? std::make_optional(altitude->toCpp()) : std::nullopt,
52
56
  accuracy,
53
- altitudeAccuracy != nullptr ? std::make_optional(altitudeAccuracy->value()) : std::nullopt,
54
- heading != nullptr ? std::make_optional(heading->value()) : std::nullopt,
55
- speed != nullptr ? std::make_optional(speed->value()) : std::nullopt
57
+ altitudeAccuracy != nullptr ? std::make_optional(altitudeAccuracy->toCpp()) : std::nullopt,
58
+ heading != nullptr ? std::make_optional(heading->toCpp()) : std::nullopt,
59
+ speed != nullptr ? std::make_optional(speed->toCpp()) : std::nullopt
56
60
  );
57
61
  }
58
62
 
@@ -62,14 +66,18 @@ namespace margelo::nitro::nitrogeolocation {
62
66
  */
63
67
  [[maybe_unused]]
64
68
  static jni::local_ref<JGeolocationCoordinates::javaobject> fromCpp(const GeolocationCoordinates& value) {
65
- return newInstance(
69
+ using JSignature = JGeolocationCoordinates(double, double, jni::alias_ref<JNullableDouble>, double, jni::alias_ref<JNullableDouble>, jni::alias_ref<JNullableDouble>, jni::alias_ref<JNullableDouble>);
70
+ static const auto clazz = javaClassStatic();
71
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
72
+ return create(
73
+ clazz,
66
74
  value.latitude,
67
75
  value.longitude,
68
- value.altitude.has_value() ? jni::JDouble::valueOf(value.altitude.value()) : nullptr,
76
+ value.altitude.has_value() ? JNullableDouble::fromCpp(value.altitude.value()) : nullptr,
69
77
  value.accuracy,
70
- value.altitudeAccuracy.has_value() ? jni::JDouble::valueOf(value.altitudeAccuracy.value()) : nullptr,
71
- value.heading.has_value() ? jni::JDouble::valueOf(value.heading.value()) : nullptr,
72
- value.speed.has_value() ? jni::JDouble::valueOf(value.speed.value()) : nullptr
78
+ value.altitudeAccuracy.has_value() ? JNullableDouble::fromCpp(value.altitudeAccuracy.value()) : nullptr,
79
+ value.heading.has_value() ? JNullableDouble::fromCpp(value.heading.value()) : nullptr,
80
+ value.speed.has_value() ? JNullableDouble::fromCpp(value.speed.value()) : nullptr
73
81
  );
74
82
  }
75
83
  };
@@ -56,7 +56,11 @@ namespace margelo::nitro::nitrogeolocation {
56
56
  */
57
57
  [[maybe_unused]]
58
58
  static jni::local_ref<JGeolocationError::javaobject> fromCpp(const GeolocationError& value) {
59
- return newInstance(
59
+ using JSignature = JGeolocationError(double, jni::alias_ref<jni::JString>, double, double, double);
60
+ static const auto clazz = javaClassStatic();
61
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
62
+ return create(
63
+ clazz,
60
64
  value.code,
61
65
  jni::make_jstring(value.message),
62
66
  value.PERMISSION_DENIED,
@@ -62,7 +62,11 @@ namespace margelo::nitro::nitrogeolocation {
62
62
  */
63
63
  [[maybe_unused]]
64
64
  static jni::local_ref<JGeolocationOptions::javaobject> fromCpp(const GeolocationOptions& value) {
65
- return newInstance(
65
+ using JSignature = JGeolocationOptions(jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JBoolean>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JDouble>, jni::alias_ref<jni::JBoolean>);
66
+ static const auto clazz = javaClassStatic();
67
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
68
+ return create(
69
+ clazz,
66
70
  value.timeout.has_value() ? jni::JDouble::valueOf(value.timeout.value()) : nullptr,
67
71
  value.maximumAge.has_value() ? jni::JDouble::valueOf(value.maximumAge.value()) : nullptr,
68
72
  value.enableHighAccuracy.has_value() ? jni::JBoolean::valueOf(value.enableHighAccuracy.value()) : nullptr,
@@ -12,7 +12,11 @@
12
12
 
13
13
  #include "GeolocationCoordinates.hpp"
14
14
  #include "JGeolocationCoordinates.hpp"
15
+ #include "JNullableDouble.hpp"
16
+ #include <NitroModules/JNull.hpp>
17
+ #include <NitroModules/Null.hpp>
15
18
  #include <optional>
19
+ #include <variant>
16
20
 
17
21
  namespace margelo::nitro::nitrogeolocation {
18
22
 
@@ -49,7 +53,11 @@ namespace margelo::nitro::nitrogeolocation {
49
53
  */
50
54
  [[maybe_unused]]
51
55
  static jni::local_ref<JGeolocationResponse::javaobject> fromCpp(const GeolocationResponse& value) {
52
- return newInstance(
56
+ using JSignature = JGeolocationResponse(jni::alias_ref<JGeolocationCoordinates>, double);
57
+ static const auto clazz = javaClassStatic();
58
+ static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
59
+ return create(
60
+ clazz,
53
61
  JGeolocationCoordinates::fromCpp(value.coords),
54
62
  value.timestamp
55
63
  );
@@ -0,0 +1,109 @@
1
+ ///
2
+ /// JHybridNitroGeolocationCompatSpec.cpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #include "JHybridNitroGeolocationCompatSpec.hpp"
9
+
10
+ // Forward declaration of `RNConfigurationInternal` to properly resolve imports.
11
+ namespace margelo::nitro::nitrogeolocation { struct RNConfigurationInternal; }
12
+ // Forward declaration of `AuthorizationLevelInternal` to properly resolve imports.
13
+ namespace margelo::nitro::nitrogeolocation { enum class AuthorizationLevelInternal; }
14
+ // Forward declaration of `LocationProviderInternal` to properly resolve imports.
15
+ namespace margelo::nitro::nitrogeolocation { enum class LocationProviderInternal; }
16
+ // Forward declaration of `GeolocationError` to properly resolve imports.
17
+ namespace margelo::nitro::nitrogeolocation { struct GeolocationError; }
18
+ // Forward declaration of `GeolocationResponse` to properly resolve imports.
19
+ namespace margelo::nitro::nitrogeolocation { struct GeolocationResponse; }
20
+ // Forward declaration of `GeolocationCoordinates` to properly resolve imports.
21
+ namespace margelo::nitro::nitrogeolocation { struct GeolocationCoordinates; }
22
+ // Forward declaration of `GeolocationOptions` to properly resolve imports.
23
+ namespace margelo::nitro::nitrogeolocation { struct GeolocationOptions; }
24
+
25
+ #include "RNConfigurationInternal.hpp"
26
+ #include "JRNConfigurationInternal.hpp"
27
+ #include "AuthorizationLevelInternal.hpp"
28
+ #include <optional>
29
+ #include "JAuthorizationLevelInternal.hpp"
30
+ #include "LocationProviderInternal.hpp"
31
+ #include "JLocationProviderInternal.hpp"
32
+ #include <functional>
33
+ #include "JFunc_void.hpp"
34
+ #include <NitroModules/JNICallable.hpp>
35
+ #include "GeolocationError.hpp"
36
+ #include "JFunc_void_GeolocationError.hpp"
37
+ #include "JGeolocationError.hpp"
38
+ #include <string>
39
+ #include "GeolocationResponse.hpp"
40
+ #include "JFunc_void_GeolocationResponse.hpp"
41
+ #include "JGeolocationResponse.hpp"
42
+ #include "GeolocationCoordinates.hpp"
43
+ #include "JGeolocationCoordinates.hpp"
44
+ #include <NitroModules/Null.hpp>
45
+ #include <variant>
46
+ #include "JNullableDouble.hpp"
47
+ #include <NitroModules/JNull.hpp>
48
+ #include "GeolocationOptions.hpp"
49
+ #include "JGeolocationOptions.hpp"
50
+
51
+ namespace margelo::nitro::nitrogeolocation {
52
+
53
+ jni::local_ref<JHybridNitroGeolocationCompatSpec::jhybriddata> JHybridNitroGeolocationCompatSpec::initHybrid(jni::alias_ref<jhybridobject> jThis) {
54
+ return makeCxxInstance(jThis);
55
+ }
56
+
57
+ void JHybridNitroGeolocationCompatSpec::registerNatives() {
58
+ registerHybrid({
59
+ makeNativeMethod("initHybrid", JHybridNitroGeolocationCompatSpec::initHybrid),
60
+ });
61
+ }
62
+
63
+ size_t JHybridNitroGeolocationCompatSpec::getExternalMemorySize() noexcept {
64
+ static const auto method = javaClassStatic()->getMethod<jlong()>("getMemorySize");
65
+ return method(_javaPart);
66
+ }
67
+
68
+ void JHybridNitroGeolocationCompatSpec::dispose() noexcept {
69
+ static const auto method = javaClassStatic()->getMethod<void()>("dispose");
70
+ method(_javaPart);
71
+ }
72
+
73
+ std::string JHybridNitroGeolocationCompatSpec::toString() {
74
+ static const auto method = javaClassStatic()->getMethod<jni::JString()>("toString");
75
+ auto javaString = method(_javaPart);
76
+ return javaString->toStdString();
77
+ }
78
+
79
+ // Properties
80
+
81
+
82
+ // Methods
83
+ void JHybridNitroGeolocationCompatSpec::setRNConfiguration(const RNConfigurationInternal& config) {
84
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JRNConfigurationInternal> /* config */)>("setRNConfiguration");
85
+ method(_javaPart, JRNConfigurationInternal::fromCpp(config));
86
+ }
87
+ void JHybridNitroGeolocationCompatSpec::requestAuthorization(const std::optional<std::function<void()>>& success, const std::optional<std::function<void(const GeolocationError& /* error */)>>& error) {
88
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void::javaobject> /* success */, jni::alias_ref<JFunc_void_GeolocationError::javaobject> /* error */)>("requestAuthorization_cxx");
89
+ method(_javaPart, success.has_value() ? JFunc_void_cxx::fromCpp(success.value()) : nullptr, error.has_value() ? JFunc_void_GeolocationError_cxx::fromCpp(error.value()) : nullptr);
90
+ }
91
+ void JHybridNitroGeolocationCompatSpec::getCurrentPosition(const std::function<void(const GeolocationResponse& /* position */)>& success, const std::optional<std::function<void(const GeolocationError& /* error */)>>& error, const std::optional<GeolocationOptions>& options) {
92
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_GeolocationResponse::javaobject> /* success */, jni::alias_ref<JFunc_void_GeolocationError::javaobject> /* error */, jni::alias_ref<JGeolocationOptions> /* options */)>("getCurrentPosition_cxx");
93
+ method(_javaPart, JFunc_void_GeolocationResponse_cxx::fromCpp(success), error.has_value() ? JFunc_void_GeolocationError_cxx::fromCpp(error.value()) : nullptr, options.has_value() ? JGeolocationOptions::fromCpp(options.value()) : nullptr);
94
+ }
95
+ double JHybridNitroGeolocationCompatSpec::watchPosition(const std::function<void(const GeolocationResponse& /* position */)>& success, const std::optional<std::function<void(const GeolocationError& /* error */)>>& error, const std::optional<GeolocationOptions>& options) {
96
+ static const auto method = javaClassStatic()->getMethod<double(jni::alias_ref<JFunc_void_GeolocationResponse::javaobject> /* success */, jni::alias_ref<JFunc_void_GeolocationError::javaobject> /* error */, jni::alias_ref<JGeolocationOptions> /* options */)>("watchPosition_cxx");
97
+ auto __result = method(_javaPart, JFunc_void_GeolocationResponse_cxx::fromCpp(success), error.has_value() ? JFunc_void_GeolocationError_cxx::fromCpp(error.value()) : nullptr, options.has_value() ? JGeolocationOptions::fromCpp(options.value()) : nullptr);
98
+ return __result;
99
+ }
100
+ void JHybridNitroGeolocationCompatSpec::clearWatch(double watchId) {
101
+ static const auto method = javaClassStatic()->getMethod<void(double /* watchId */)>("clearWatch");
102
+ method(_javaPart, watchId);
103
+ }
104
+ void JHybridNitroGeolocationCompatSpec::stopObserving() {
105
+ static const auto method = javaClassStatic()->getMethod<void()>("stopObserving");
106
+ method(_javaPart);
107
+ }
108
+
109
+ } // namespace margelo::nitro::nitrogeolocation
@@ -0,0 +1,70 @@
1
+ ///
2
+ /// HybridNitroGeolocationCompatSpec.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <NitroModules/JHybridObject.hpp>
11
+ #include <fbjni/fbjni.h>
12
+ #include "HybridNitroGeolocationCompatSpec.hpp"
13
+
14
+
15
+
16
+
17
+ namespace margelo::nitro::nitrogeolocation {
18
+
19
+ using namespace facebook;
20
+
21
+ class JHybridNitroGeolocationCompatSpec: public jni::HybridClass<JHybridNitroGeolocationCompatSpec, JHybridObject>,
22
+ public virtual HybridNitroGeolocationCompatSpec {
23
+ public:
24
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrogeolocation/HybridNitroGeolocationCompatSpec;";
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 JHybridNitroGeolocationCompatSpec(jni::alias_ref<jhybridobject> jThis) :
31
+ HybridObject(HybridNitroGeolocationCompatSpec::TAG),
32
+ HybridBase(jThis),
33
+ _javaPart(jni::make_global(jThis)) {}
34
+
35
+ public:
36
+ ~JHybridNitroGeolocationCompatSpec() 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
+ void dispose() noexcept override;
44
+ std::string toString() override;
45
+
46
+ public:
47
+ inline const jni::global_ref<JHybridNitroGeolocationCompatSpec::javaobject>& getJavaPart() const noexcept {
48
+ return _javaPart;
49
+ }
50
+
51
+ public:
52
+ // Properties
53
+
54
+
55
+ public:
56
+ // Methods
57
+ void setRNConfiguration(const RNConfigurationInternal& config) override;
58
+ void requestAuthorization(const std::optional<std::function<void()>>& success, const std::optional<std::function<void(const GeolocationError& /* error */)>>& error) override;
59
+ void getCurrentPosition(const std::function<void(const GeolocationResponse& /* position */)>& success, const std::optional<std::function<void(const GeolocationError& /* error */)>>& error, const std::optional<GeolocationOptions>& options) override;
60
+ double watchPosition(const std::function<void(const GeolocationResponse& /* position */)>& success, const std::optional<std::function<void(const GeolocationError& /* error */)>>& error, const std::optional<GeolocationOptions>& options) override;
61
+ void clearWatch(double watchId) override;
62
+ void stopObserving() override;
63
+
64
+ private:
65
+ friend HybridBase;
66
+ using HybridBase::HybridBase;
67
+ jni::global_ref<JHybridNitroGeolocationCompatSpec::javaobject> _javaPart;
68
+ };
69
+
70
+ } // namespace margelo::nitro::nitrogeolocation