react-native-nitro-geolocation 0.0.1 → 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 (79) hide show
  1. package/LICENSE +4 -1
  2. package/README.md +598 -0
  3. package/android/src/main/java/com/margelo/nitro/nitrogeolocation/GetCurrentPosition.kt +341 -0
  4. package/android/src/main/java/com/margelo/nitro/nitrogeolocation/NitroGeolocation.kt +76 -5
  5. package/android/src/main/java/com/margelo/nitro/nitrogeolocation/RequestAuthorization.kt +164 -0
  6. package/android/src/main/java/com/margelo/nitro/nitrogeolocation/WatchPosition.kt +228 -0
  7. package/ios/LocationManager.swift +529 -0
  8. package/ios/NitroGeolocation.swift +96 -2
  9. package/nitrogen/generated/.gitattributes +1 -0
  10. package/nitrogen/generated/android/c++/JAuthorizationLevelInternal.hpp +62 -0
  11. package/nitrogen/generated/android/c++/JFunc_void.hpp +74 -0
  12. package/nitrogen/generated/android/c++/JFunc_void_GeolocationError.hpp +77 -0
  13. package/nitrogen/generated/android/c++/JFunc_void_GeolocationResponse.hpp +79 -0
  14. package/nitrogen/generated/android/c++/JGeolocationCoordinates.hpp +77 -0
  15. package/nitrogen/generated/android/c++/JGeolocationError.hpp +69 -0
  16. package/nitrogen/generated/android/c++/JGeolocationOptions.hpp +77 -0
  17. package/nitrogen/generated/android/c++/JGeolocationResponse.hpp +59 -0
  18. package/nitrogen/generated/android/c++/JHybridNitroGeolocationSpec.cpp +98 -0
  19. package/nitrogen/generated/android/c++/JHybridNitroGeolocationSpec.hpp +69 -0
  20. package/nitrogen/generated/android/c++/JLocationProviderInternal.hpp +62 -0
  21. package/nitrogen/generated/android/c++/JRNConfigurationInternal.hpp +69 -0
  22. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/AuthorizationLevelInternal.kt +22 -0
  23. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/Func_void.kt +81 -0
  24. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/Func_void_GeolocationError.kt +81 -0
  25. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/Func_void_GeolocationResponse.kt +81 -0
  26. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/GeolocationCoordinates.kt +47 -0
  27. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/GeolocationError.kt +41 -0
  28. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/GeolocationOptions.kt +47 -0
  29. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/GeolocationResponse.kt +32 -0
  30. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/HybridNitroGeolocationSpec.kt +87 -0
  31. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/LocationProviderInternal.kt +22 -0
  32. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/RNConfigurationInternal.kt +38 -0
  33. package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrogeolocation/nitrogeolocationOnLoad.kt +35 -0
  34. package/nitrogen/generated/android/nitrogeolocation+autolinking.cmake +81 -0
  35. package/nitrogen/generated/android/nitrogeolocation+autolinking.gradle +27 -0
  36. package/nitrogen/generated/android/nitrogeolocationOnLoad.cpp +50 -0
  37. package/nitrogen/generated/android/nitrogeolocationOnLoad.hpp +25 -0
  38. package/nitrogen/generated/ios/NitroGeolocation+autolinking.rb +60 -0
  39. package/nitrogen/generated/ios/NitroGeolocation-Swift-Cxx-Bridge.cpp +56 -0
  40. package/nitrogen/generated/ios/NitroGeolocation-Swift-Cxx-Bridge.hpp +252 -0
  41. package/nitrogen/generated/ios/NitroGeolocation-Swift-Cxx-Umbrella.hpp +67 -0
  42. package/nitrogen/generated/ios/NitroGeolocationAutolinking.mm +33 -0
  43. package/nitrogen/generated/ios/NitroGeolocationAutolinking.swift +25 -0
  44. package/nitrogen/generated/ios/c++/HybridNitroGeolocationSpecSwift.cpp +11 -0
  45. package/nitrogen/generated/ios/c++/HybridNitroGeolocationSpecSwift.hpp +125 -0
  46. package/nitrogen/generated/ios/swift/AuthorizationLevelInternal.swift +44 -0
  47. package/nitrogen/generated/ios/swift/Func_void.swift +47 -0
  48. package/nitrogen/generated/ios/swift/Func_void_GeolocationError.swift +47 -0
  49. package/nitrogen/generated/ios/swift/Func_void_GeolocationResponse.swift +47 -0
  50. package/nitrogen/generated/ios/swift/GeolocationCoordinates.swift +149 -0
  51. package/nitrogen/generated/ios/swift/GeolocationError.swift +79 -0
  52. package/nitrogen/generated/ios/swift/GeolocationOptions.swift +185 -0
  53. package/nitrogen/generated/ios/swift/GeolocationResponse.swift +46 -0
  54. package/nitrogen/generated/ios/swift/HybridNitroGeolocationSpec.swift +54 -0
  55. package/nitrogen/generated/ios/swift/HybridNitroGeolocationSpec_cxx.swift +236 -0
  56. package/nitrogen/generated/ios/swift/LocationProviderInternal.swift +44 -0
  57. package/nitrogen/generated/ios/swift/RNConfigurationInternal.swift +104 -0
  58. package/nitrogen/generated/shared/c++/AuthorizationLevelInternal.hpp +80 -0
  59. package/nitrogen/generated/shared/c++/GeolocationCoordinates.hpp +91 -0
  60. package/nitrogen/generated/shared/c++/GeolocationError.hpp +83 -0
  61. package/nitrogen/generated/shared/c++/GeolocationOptions.hpp +91 -0
  62. package/nitrogen/generated/shared/c++/GeolocationResponse.hpp +72 -0
  63. package/nitrogen/generated/shared/c++/HybridNitroGeolocationSpec.cpp +26 -0
  64. package/nitrogen/generated/shared/c++/HybridNitroGeolocationSpec.hpp +79 -0
  65. package/nitrogen/generated/shared/c++/LocationProviderInternal.hpp +80 -0
  66. package/nitrogen/generated/shared/c++/RNConfigurationInternal.hpp +84 -0
  67. package/package.json +34 -10
  68. package/src/NitroGeolocation.nitro.ts +38 -3
  69. package/src/NitroGeolocationModule.ts +5 -0
  70. package/src/clearWatch.ts +13 -0
  71. package/src/getCurrentPosition.ts +14 -0
  72. package/src/index.tsx +32 -7
  73. package/src/requestAuthorization.ts +9 -0
  74. package/src/setRNConfiguration.ts +22 -0
  75. package/src/stopObserving.ts +12 -0
  76. package/src/types.ts +43 -0
  77. package/src/watchPosition.ts +26 -0
  78. package/nitro.json +0 -17
  79. package/turbo.json +0 -42
@@ -0,0 +1,91 @@
1
+ ///
2
+ /// GeolocationOptions.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
+ #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
+
21
+
22
+
23
+ #include <optional>
24
+
25
+ namespace margelo::nitro::nitrogeolocation {
26
+
27
+ /**
28
+ * A struct which can be represented as a JavaScript object (GeolocationOptions).
29
+ */
30
+ struct GeolocationOptions {
31
+ public:
32
+ std::optional<double> timeout SWIFT_PRIVATE;
33
+ std::optional<double> maximumAge SWIFT_PRIVATE;
34
+ std::optional<bool> enableHighAccuracy SWIFT_PRIVATE;
35
+ std::optional<double> interval SWIFT_PRIVATE;
36
+ std::optional<double> fastestInterval SWIFT_PRIVATE;
37
+ std::optional<double> distanceFilter SWIFT_PRIVATE;
38
+ std::optional<bool> useSignificantChanges SWIFT_PRIVATE;
39
+
40
+ public:
41
+ GeolocationOptions() = default;
42
+ explicit GeolocationOptions(std::optional<double> timeout, std::optional<double> maximumAge, std::optional<bool> enableHighAccuracy, std::optional<double> interval, std::optional<double> fastestInterval, std::optional<double> distanceFilter, std::optional<bool> useSignificantChanges): timeout(timeout), maximumAge(maximumAge), enableHighAccuracy(enableHighAccuracy), interval(interval), fastestInterval(fastestInterval), distanceFilter(distanceFilter), useSignificantChanges(useSignificantChanges) {}
43
+ };
44
+
45
+ } // namespace margelo::nitro::nitrogeolocation
46
+
47
+ namespace margelo::nitro {
48
+
49
+ // C++ GeolocationOptions <> JS GeolocationOptions (object)
50
+ template <>
51
+ struct JSIConverter<margelo::nitro::nitrogeolocation::GeolocationOptions> final {
52
+ static inline margelo::nitro::nitrogeolocation::GeolocationOptions fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
53
+ jsi::Object obj = arg.asObject(runtime);
54
+ return margelo::nitro::nitrogeolocation::GeolocationOptions(
55
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "timeout")),
56
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "maximumAge")),
57
+ JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "enableHighAccuracy")),
58
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "interval")),
59
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "fastestInterval")),
60
+ JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, "distanceFilter")),
61
+ JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "useSignificantChanges"))
62
+ );
63
+ }
64
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrogeolocation::GeolocationOptions& arg) {
65
+ jsi::Object obj(runtime);
66
+ obj.setProperty(runtime, "timeout", JSIConverter<std::optional<double>>::toJSI(runtime, arg.timeout));
67
+ obj.setProperty(runtime, "maximumAge", JSIConverter<std::optional<double>>::toJSI(runtime, arg.maximumAge));
68
+ obj.setProperty(runtime, "enableHighAccuracy", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.enableHighAccuracy));
69
+ obj.setProperty(runtime, "interval", JSIConverter<std::optional<double>>::toJSI(runtime, arg.interval));
70
+ obj.setProperty(runtime, "fastestInterval", JSIConverter<std::optional<double>>::toJSI(runtime, arg.fastestInterval));
71
+ obj.setProperty(runtime, "distanceFilter", JSIConverter<std::optional<double>>::toJSI(runtime, arg.distanceFilter));
72
+ obj.setProperty(runtime, "useSignificantChanges", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.useSignificantChanges));
73
+ return obj;
74
+ }
75
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
76
+ if (!value.isObject()) {
77
+ return false;
78
+ }
79
+ jsi::Object obj = value.getObject(runtime);
80
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "timeout"))) return false;
81
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "maximumAge"))) return false;
82
+ if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "enableHighAccuracy"))) return false;
83
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "interval"))) return false;
84
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "fastestInterval"))) return false;
85
+ if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, "distanceFilter"))) return false;
86
+ if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "useSignificantChanges"))) return false;
87
+ return true;
88
+ }
89
+ };
90
+
91
+ } // namespace margelo::nitro
@@ -0,0 +1,72 @@
1
+ ///
2
+ /// GeolocationResponse.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
+ #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
+
21
+ // Forward declaration of `GeolocationCoordinates` to properly resolve imports.
22
+ namespace margelo::nitro::nitrogeolocation { struct GeolocationCoordinates; }
23
+
24
+ #include "GeolocationCoordinates.hpp"
25
+
26
+ namespace margelo::nitro::nitrogeolocation {
27
+
28
+ /**
29
+ * A struct which can be represented as a JavaScript object (GeolocationResponse).
30
+ */
31
+ struct GeolocationResponse {
32
+ public:
33
+ GeolocationCoordinates coords SWIFT_PRIVATE;
34
+ double timestamp SWIFT_PRIVATE;
35
+
36
+ public:
37
+ GeolocationResponse() = default;
38
+ explicit GeolocationResponse(GeolocationCoordinates coords, double timestamp): coords(coords), timestamp(timestamp) {}
39
+ };
40
+
41
+ } // namespace margelo::nitro::nitrogeolocation
42
+
43
+ namespace margelo::nitro {
44
+
45
+ // C++ GeolocationResponse <> JS GeolocationResponse (object)
46
+ template <>
47
+ struct JSIConverter<margelo::nitro::nitrogeolocation::GeolocationResponse> final {
48
+ static inline margelo::nitro::nitrogeolocation::GeolocationResponse fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
49
+ jsi::Object obj = arg.asObject(runtime);
50
+ return margelo::nitro::nitrogeolocation::GeolocationResponse(
51
+ JSIConverter<margelo::nitro::nitrogeolocation::GeolocationCoordinates>::fromJSI(runtime, obj.getProperty(runtime, "coords")),
52
+ JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, "timestamp"))
53
+ );
54
+ }
55
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrogeolocation::GeolocationResponse& arg) {
56
+ jsi::Object obj(runtime);
57
+ obj.setProperty(runtime, "coords", JSIConverter<margelo::nitro::nitrogeolocation::GeolocationCoordinates>::toJSI(runtime, arg.coords));
58
+ obj.setProperty(runtime, "timestamp", JSIConverter<double>::toJSI(runtime, arg.timestamp));
59
+ return obj;
60
+ }
61
+ static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
62
+ if (!value.isObject()) {
63
+ return false;
64
+ }
65
+ jsi::Object obj = value.getObject(runtime);
66
+ if (!JSIConverter<margelo::nitro::nitrogeolocation::GeolocationCoordinates>::canConvert(runtime, obj.getProperty(runtime, "coords"))) return false;
67
+ if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, "timestamp"))) return false;
68
+ return true;
69
+ }
70
+ };
71
+
72
+ } // namespace margelo::nitro
@@ -0,0 +1,26 @@
1
+ ///
2
+ /// HybridNitroGeolocationSpec.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 "HybridNitroGeolocationSpec.hpp"
9
+
10
+ namespace margelo::nitro::nitrogeolocation {
11
+
12
+ void HybridNitroGeolocationSpec::loadHybridMethods() {
13
+ // load base methods/properties
14
+ HybridObject::loadHybridMethods();
15
+ // load custom methods/properties
16
+ registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("setRNConfiguration", &HybridNitroGeolocationSpec::setRNConfiguration);
18
+ prototype.registerHybridMethod("requestAuthorization", &HybridNitroGeolocationSpec::requestAuthorization);
19
+ prototype.registerHybridMethod("getCurrentPosition", &HybridNitroGeolocationSpec::getCurrentPosition);
20
+ prototype.registerHybridMethod("watchPosition", &HybridNitroGeolocationSpec::watchPosition);
21
+ prototype.registerHybridMethod("clearWatch", &HybridNitroGeolocationSpec::clearWatch);
22
+ prototype.registerHybridMethod("stopObserving", &HybridNitroGeolocationSpec::stopObserving);
23
+ });
24
+ }
25
+
26
+ } // namespace margelo::nitro::nitrogeolocation
@@ -0,0 +1,79 @@
1
+ ///
2
+ /// HybridNitroGeolocationSpec.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
+ #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 `RNConfigurationInternal` to properly resolve imports.
17
+ namespace margelo::nitro::nitrogeolocation { struct RNConfigurationInternal; }
18
+ // Forward declaration of `GeolocationError` to properly resolve imports.
19
+ namespace margelo::nitro::nitrogeolocation { struct GeolocationError; }
20
+ // Forward declaration of `GeolocationResponse` to properly resolve imports.
21
+ namespace margelo::nitro::nitrogeolocation { struct GeolocationResponse; }
22
+ // Forward declaration of `GeolocationOptions` to properly resolve imports.
23
+ namespace margelo::nitro::nitrogeolocation { struct GeolocationOptions; }
24
+
25
+ #include "RNConfigurationInternal.hpp"
26
+ #include <functional>
27
+ #include <optional>
28
+ #include "GeolocationError.hpp"
29
+ #include "GeolocationResponse.hpp"
30
+ #include "GeolocationOptions.hpp"
31
+
32
+ namespace margelo::nitro::nitrogeolocation {
33
+
34
+ using namespace margelo::nitro;
35
+
36
+ /**
37
+ * An abstract base class for `NitroGeolocation`
38
+ * Inherit this class to create instances of `HybridNitroGeolocationSpec` in C++.
39
+ * You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
40
+ * @example
41
+ * ```cpp
42
+ * class HybridNitroGeolocation: public HybridNitroGeolocationSpec {
43
+ * public:
44
+ * HybridNitroGeolocation(...): HybridObject(TAG) { ... }
45
+ * // ...
46
+ * };
47
+ * ```
48
+ */
49
+ class HybridNitroGeolocationSpec: public virtual HybridObject {
50
+ public:
51
+ // Constructor
52
+ explicit HybridNitroGeolocationSpec(): HybridObject(TAG) { }
53
+
54
+ // Destructor
55
+ ~HybridNitroGeolocationSpec() override = default;
56
+
57
+ public:
58
+ // Properties
59
+
60
+
61
+ public:
62
+ // Methods
63
+ virtual void setRNConfiguration(const RNConfigurationInternal& config) = 0;
64
+ virtual void requestAuthorization(const std::optional<std::function<void()>>& success, const std::optional<std::function<void(const GeolocationError& /* error */)>>& error) = 0;
65
+ virtual 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) = 0;
66
+ virtual 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) = 0;
67
+ virtual void clearWatch(double watchId) = 0;
68
+ virtual void stopObserving() = 0;
69
+
70
+ protected:
71
+ // Hybrid Setup
72
+ void loadHybridMethods() override;
73
+
74
+ protected:
75
+ // Tag for logging
76
+ static constexpr auto TAG = "NitroGeolocation";
77
+ };
78
+
79
+ } // namespace margelo::nitro::nitrogeolocation
@@ -0,0 +1,80 @@
1
+ ///
2
+ /// LocationProviderInternal.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
+ #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::nitrogeolocation {
27
+
28
+ /**
29
+ * An enum which can be represented as a JavaScript union (LocationProviderInternal).
30
+ */
31
+ enum class LocationProviderInternal {
32
+ AUTO SWIFT_NAME(auto) = 0,
33
+ PLAYSERVICES SWIFT_NAME(playservices) = 1,
34
+ ANDROID_PLATFORM SWIFT_NAME(androidPlatform) = 2,
35
+ } CLOSED_ENUM;
36
+
37
+ } // namespace margelo::nitro::nitrogeolocation
38
+
39
+ namespace margelo::nitro {
40
+
41
+ // C++ LocationProviderInternal <> JS LocationProviderInternal (union)
42
+ template <>
43
+ struct JSIConverter<margelo::nitro::nitrogeolocation::LocationProviderInternal> final {
44
+ static inline margelo::nitro::nitrogeolocation::LocationProviderInternal 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("auto"): return margelo::nitro::nitrogeolocation::LocationProviderInternal::AUTO;
48
+ case hashString("playServices"): return margelo::nitro::nitrogeolocation::LocationProviderInternal::PLAYSERVICES;
49
+ case hashString("android_platform"): return margelo::nitro::nitrogeolocation::LocationProviderInternal::ANDROID_PLATFORM;
50
+ default: [[unlikely]]
51
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum LocationProviderInternal - invalid value!");
52
+ }
53
+ }
54
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::nitrogeolocation::LocationProviderInternal arg) {
55
+ switch (arg) {
56
+ case margelo::nitro::nitrogeolocation::LocationProviderInternal::AUTO: return JSIConverter<std::string>::toJSI(runtime, "auto");
57
+ case margelo::nitro::nitrogeolocation::LocationProviderInternal::PLAYSERVICES: return JSIConverter<std::string>::toJSI(runtime, "playServices");
58
+ case margelo::nitro::nitrogeolocation::LocationProviderInternal::ANDROID_PLATFORM: return JSIConverter<std::string>::toJSI(runtime, "android_platform");
59
+ default: [[unlikely]]
60
+ throw std::invalid_argument("Cannot convert LocationProviderInternal 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("auto"):
71
+ case hashString("playServices"):
72
+ case hashString("android_platform"):
73
+ return true;
74
+ default:
75
+ return false;
76
+ }
77
+ }
78
+ };
79
+
80
+ } // namespace margelo::nitro
@@ -0,0 +1,84 @@
1
+ ///
2
+ /// RNConfigurationInternal.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
+ #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
+
21
+ // Forward declaration of `AuthorizationLevelInternal` to properly resolve imports.
22
+ namespace margelo::nitro::nitrogeolocation { enum class AuthorizationLevelInternal; }
23
+ // Forward declaration of `LocationProviderInternal` to properly resolve imports.
24
+ namespace margelo::nitro::nitrogeolocation { enum class LocationProviderInternal; }
25
+
26
+ #include "AuthorizationLevelInternal.hpp"
27
+ #include <optional>
28
+ #include "LocationProviderInternal.hpp"
29
+
30
+ namespace margelo::nitro::nitrogeolocation {
31
+
32
+ /**
33
+ * A struct which can be represented as a JavaScript object (RNConfigurationInternal).
34
+ */
35
+ struct RNConfigurationInternal {
36
+ public:
37
+ bool skipPermissionRequests SWIFT_PRIVATE;
38
+ std::optional<AuthorizationLevelInternal> authorizationLevel SWIFT_PRIVATE;
39
+ std::optional<bool> enableBackgroundLocationUpdates SWIFT_PRIVATE;
40
+ std::optional<LocationProviderInternal> locationProvider SWIFT_PRIVATE;
41
+
42
+ public:
43
+ RNConfigurationInternal() = default;
44
+ explicit RNConfigurationInternal(bool skipPermissionRequests, std::optional<AuthorizationLevelInternal> authorizationLevel, std::optional<bool> enableBackgroundLocationUpdates, std::optional<LocationProviderInternal> locationProvider): skipPermissionRequests(skipPermissionRequests), authorizationLevel(authorizationLevel), enableBackgroundLocationUpdates(enableBackgroundLocationUpdates), locationProvider(locationProvider) {}
45
+ };
46
+
47
+ } // namespace margelo::nitro::nitrogeolocation
48
+
49
+ namespace margelo::nitro {
50
+
51
+ // C++ RNConfigurationInternal <> JS RNConfigurationInternal (object)
52
+ template <>
53
+ struct JSIConverter<margelo::nitro::nitrogeolocation::RNConfigurationInternal> final {
54
+ static inline margelo::nitro::nitrogeolocation::RNConfigurationInternal fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
55
+ jsi::Object obj = arg.asObject(runtime);
56
+ return margelo::nitro::nitrogeolocation::RNConfigurationInternal(
57
+ JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, "skipPermissionRequests")),
58
+ JSIConverter<std::optional<margelo::nitro::nitrogeolocation::AuthorizationLevelInternal>>::fromJSI(runtime, obj.getProperty(runtime, "authorizationLevel")),
59
+ JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, "enableBackgroundLocationUpdates")),
60
+ JSIConverter<std::optional<margelo::nitro::nitrogeolocation::LocationProviderInternal>>::fromJSI(runtime, obj.getProperty(runtime, "locationProvider"))
61
+ );
62
+ }
63
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrogeolocation::RNConfigurationInternal& arg) {
64
+ jsi::Object obj(runtime);
65
+ obj.setProperty(runtime, "skipPermissionRequests", JSIConverter<bool>::toJSI(runtime, arg.skipPermissionRequests));
66
+ obj.setProperty(runtime, "authorizationLevel", JSIConverter<std::optional<margelo::nitro::nitrogeolocation::AuthorizationLevelInternal>>::toJSI(runtime, arg.authorizationLevel));
67
+ obj.setProperty(runtime, "enableBackgroundLocationUpdates", JSIConverter<std::optional<bool>>::toJSI(runtime, arg.enableBackgroundLocationUpdates));
68
+ obj.setProperty(runtime, "locationProvider", JSIConverter<std::optional<margelo::nitro::nitrogeolocation::LocationProviderInternal>>::toJSI(runtime, arg.locationProvider));
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 (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, "skipPermissionRequests"))) return false;
77
+ if (!JSIConverter<std::optional<margelo::nitro::nitrogeolocation::AuthorizationLevelInternal>>::canConvert(runtime, obj.getProperty(runtime, "authorizationLevel"))) return false;
78
+ if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, "enableBackgroundLocationUpdates"))) return false;
79
+ if (!JSIConverter<std::optional<margelo::nitro::nitrogeolocation::LocationProviderInternal>>::canConvert(runtime, obj.getProperty(runtime, "locationProvider"))) return false;
80
+ return true;
81
+ }
82
+ };
83
+
84
+ } // namespace margelo::nitro
package/package.json CHANGED
@@ -1,36 +1,60 @@
1
1
  {
2
2
  "name": "react-native-nitro-geolocation",
3
- "version": "0.0.1",
3
+ "version": "0.1.0",
4
4
  "description": "⚡🚀Blazing-fast geolocation for React Native powered by Nitro Modules",
5
5
  "main": "src/index",
6
+ "source": "src/index",
6
7
  "codegenConfig": {
7
8
  "name": "NitroGeolocationSpec",
8
9
  "type": "modules",
9
10
  "jsSrcsDir": "src"
10
11
  },
12
+ "scripts": {
13
+ "typecheck": "tsc --noEmit"
14
+ },
11
15
  "author": "jingjing2222",
12
16
  "license": "MIT",
13
- "homepage": "#readme",
17
+ "homepage": "https://react-native-nitro-geolocation.pages.dev",
14
18
  "repository": "https://github.com/jingjing2222/react-native-nitro-geolocation",
15
19
  "files": [
16
20
  "src",
17
- "android",
18
- "ios",
19
- "nitro.json",
20
- "NitroGeolocation.podspec",
21
- "turbo.json",
22
- "LICENSE"
21
+ "react-native.config.js",
22
+ "lib",
23
+ "nitrogen",
24
+ "cpp",
25
+ "android/build.gradle",
26
+ "android/fix-prefab.gradle",
27
+ "android/gradle.properties",
28
+ "android/CMakeLists.txt",
29
+ "android/src",
30
+ "ios/**/*.h",
31
+ "ios/**/*.m",
32
+ "ios/**/*.mm",
33
+ "ios/**/*.cpp",
34
+ "ios/**/*.swift",
35
+ "app.plugin.js",
36
+ "*.podspec",
37
+ "README.md"
23
38
  ],
24
39
  "devDependencies": {
25
40
  "@react-native/babel-preset": "0.81.1",
41
+ "@tsconfig/react-native": "^3.0.7",
26
42
  "@types/react": "^19.1.0",
43
+ "@types/react-test-renderer": "^18.0.0",
27
44
  "react": "19.1.0",
28
- "react-native": "0.81.1"
45
+ "react-native": "0.81.1",
46
+ "react-native-nitro-modules": "^0.29.7",
47
+ "typescript": "^5.9.3"
48
+ },
49
+ "peerDependencies": {
50
+ "react-native-nitro-modules": "*"
29
51
  },
30
52
  "create-react-native-library": {
31
53
  "languages": "kotlin-swift",
32
54
  "type": "nitro-module",
33
55
  "version": "0.54.3"
34
56
  },
35
- "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
57
+ "installConfig": {
58
+ "hoistingLimits": "workspaces"
59
+ }
36
60
  }
@@ -1,6 +1,41 @@
1
- import type { HybridObject } from 'react-native-nitro-modules';
1
+ import type { HybridObject } from "react-native-nitro-modules";
2
+ import type {
3
+ GeolocationError,
4
+ GeolocationOptions,
5
+ GeolocationResponse
6
+ } from "./types";
7
+
8
+ // Configuration - Internal (for C++ codegen, avoiding ANDROID macro conflict)
9
+ export type AuthorizationLevelInternal = "always" | "whenInUse" | "auto";
10
+ export type LocationProviderInternal =
11
+ | "playServices"
12
+ | "android_platform"
13
+ | "auto";
14
+
15
+ export interface RNConfigurationInternal {
16
+ skipPermissionRequests: boolean;
17
+ authorizationLevel?: AuthorizationLevelInternal;
18
+ enableBackgroundLocationUpdates?: boolean;
19
+ locationProvider?: LocationProviderInternal;
20
+ }
2
21
 
3
22
  export interface NitroGeolocation
4
- extends HybridObject<{ ios: 'swift'; android: 'kotlin' }> {
5
- multiply(a: number, b: number): number;
23
+ extends HybridObject<{ ios: "swift"; android: "kotlin" }> {
24
+ setRNConfiguration(config: RNConfigurationInternal): void;
25
+ requestAuthorization(
26
+ success?: () => void,
27
+ error?: (error: GeolocationError) => void
28
+ ): void;
29
+ getCurrentPosition(
30
+ success: (position: GeolocationResponse) => void,
31
+ error?: (error: GeolocationError) => void,
32
+ options?: GeolocationOptions
33
+ ): void;
34
+ watchPosition(
35
+ success: (position: GeolocationResponse) => void,
36
+ error?: (error: GeolocationError) => void,
37
+ options?: GeolocationOptions
38
+ ): number;
39
+ clearWatch(watchId: number): void;
40
+ stopObserving(): void;
6
41
  }
@@ -0,0 +1,5 @@
1
+ import { NitroModules } from "react-native-nitro-modules";
2
+ import type { NitroGeolocation } from "./NitroGeolocation.nitro";
3
+
4
+ export const NitroGeolocationHybridObject =
5
+ NitroModules.createHybridObject<NitroGeolocation>("NitroGeolocation");
@@ -0,0 +1,13 @@
1
+ import { NitroModules } from "react-native-nitro-modules";
2
+ import type { NitroGeolocation } from "./NitroGeolocation.nitro";
3
+
4
+ /**
5
+ * Clears a specific watch session identified by watchId.
6
+ *
7
+ * @param watchId - The ID returned by watchPosition()
8
+ */
9
+ export function clearWatch(watchId: number): void {
10
+ const nitroGeolocation =
11
+ NitroModules.createHybridObject<NitroGeolocation>("NitroGeolocation");
12
+ nitroGeolocation.clearWatch(watchId);
13
+ }
@@ -0,0 +1,14 @@
1
+ import { NitroGeolocationHybridObject } from "./NitroGeolocationModule";
2
+ import type {
3
+ GeolocationError,
4
+ GeolocationOptions,
5
+ GeolocationResponse
6
+ } from "./types";
7
+
8
+ export function getCurrentPosition(
9
+ success: (position: GeolocationResponse) => void,
10
+ error?: (error: GeolocationError) => void,
11
+ options?: GeolocationOptions
12
+ ): void {
13
+ NitroGeolocationHybridObject.getCurrentPosition(success, error, options);
14
+ }
package/src/index.tsx CHANGED
@@ -1,9 +1,34 @@
1
- import { NitroModules } from 'react-native-nitro-modules';
2
- import type { NitroGeolocation } from './NitroGeolocation.nitro';
1
+ // Export methods
2
+ export { clearWatch } from "./clearWatch";
3
+ export { getCurrentPosition } from "./getCurrentPosition";
4
+ export { requestAuthorization } from "./requestAuthorization";
5
+ export { setRNConfiguration } from "./setRNConfiguration";
6
+ export { stopObserving } from "./stopObserving";
7
+ export { watchPosition } from "./watchPosition";
3
8
 
4
- const NitroGeolocationHybridObject =
5
- NitroModules.createHybridObject<NitroGeolocation>('NitroGeolocation');
9
+ // Default export for compatibility
10
+ import { clearWatch } from "./clearWatch";
11
+ import { getCurrentPosition } from "./getCurrentPosition";
12
+ import { requestAuthorization } from "./requestAuthorization";
13
+ import { setRNConfiguration } from "./setRNConfiguration";
14
+ import { stopObserving } from "./stopObserving";
15
+ import { watchPosition } from "./watchPosition";
6
16
 
7
- export function multiply(a: number, b: number): number {
8
- return NitroGeolocationHybridObject.multiply(a, b);
9
- }
17
+ const Geolocation = {
18
+ setRNConfiguration,
19
+ requestAuthorization,
20
+ getCurrentPosition,
21
+ watchPosition,
22
+ clearWatch,
23
+ stopObserving
24
+ };
25
+
26
+ // Export types
27
+ export type {
28
+ GeolocationConfiguration,
29
+ GeolocationResponse,
30
+ GeolocationError,
31
+ GeolocationOptions
32
+ } from "./types";
33
+
34
+ export default Geolocation;
@@ -0,0 +1,9 @@
1
+ import { NitroGeolocationHybridObject } from "./NitroGeolocationModule";
2
+ import type { GeolocationError } from "./types";
3
+
4
+ export function requestAuthorization(
5
+ success?: () => void,
6
+ error?: (error: GeolocationError) => void
7
+ ): void {
8
+ NitroGeolocationHybridObject.requestAuthorization(success, error);
9
+ }