react-native-nitro-geolocation 0.1.2 → 0.2.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 +44 -0
  116. package/src/hooks/useRequestPermission.ts +38 -0
  117. package/src/hooks/useWatchPosition.ts +127 -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,84 @@
1
+ ///
2
+ /// PermissionStatus.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 (PermissionStatus).
30
+ */
31
+ enum class PermissionStatus {
32
+ GRANTED SWIFT_NAME(granted) = 0,
33
+ DENIED SWIFT_NAME(denied) = 1,
34
+ RESTRICTED SWIFT_NAME(restricted) = 2,
35
+ UNDETERMINED SWIFT_NAME(undetermined) = 3,
36
+ } CLOSED_ENUM;
37
+
38
+ } // namespace margelo::nitro::nitrogeolocation
39
+
40
+ namespace margelo::nitro {
41
+
42
+ // C++ PermissionStatus <> JS PermissionStatus (union)
43
+ template <>
44
+ struct JSIConverter<margelo::nitro::nitrogeolocation::PermissionStatus> final {
45
+ static inline margelo::nitro::nitrogeolocation::PermissionStatus 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("granted"): return margelo::nitro::nitrogeolocation::PermissionStatus::GRANTED;
49
+ case hashString("denied"): return margelo::nitro::nitrogeolocation::PermissionStatus::DENIED;
50
+ case hashString("restricted"): return margelo::nitro::nitrogeolocation::PermissionStatus::RESTRICTED;
51
+ case hashString("undetermined"): return margelo::nitro::nitrogeolocation::PermissionStatus::UNDETERMINED;
52
+ default: [[unlikely]]
53
+ throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum PermissionStatus - invalid value!");
54
+ }
55
+ }
56
+ static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::nitrogeolocation::PermissionStatus arg) {
57
+ switch (arg) {
58
+ case margelo::nitro::nitrogeolocation::PermissionStatus::GRANTED: return JSIConverter<std::string>::toJSI(runtime, "granted");
59
+ case margelo::nitro::nitrogeolocation::PermissionStatus::DENIED: return JSIConverter<std::string>::toJSI(runtime, "denied");
60
+ case margelo::nitro::nitrogeolocation::PermissionStatus::RESTRICTED: return JSIConverter<std::string>::toJSI(runtime, "restricted");
61
+ case margelo::nitro::nitrogeolocation::PermissionStatus::UNDETERMINED: return JSIConverter<std::string>::toJSI(runtime, "undetermined");
62
+ default: [[unlikely]]
63
+ throw std::invalid_argument("Cannot convert PermissionStatus 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("granted"):
74
+ case hashString("denied"):
75
+ case hashString("restricted"):
76
+ case hashString("undetermined"):
77
+ return true;
78
+ default:
79
+ return false;
80
+ }
81
+ }
82
+ };
83
+
84
+ } // namespace margelo::nitro
@@ -17,6 +17,16 @@
17
17
  #else
18
18
  #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
19
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
20
30
 
21
31
  // Forward declaration of `AuthorizationLevelInternal` to properly resolve imports.
22
32
  namespace margelo::nitro::nitrogeolocation { enum class AuthorizationLevelInternal; }
@@ -32,7 +42,7 @@ namespace margelo::nitro::nitrogeolocation {
32
42
  /**
33
43
  * A struct which can be represented as a JavaScript object (RNConfigurationInternal).
34
44
  */
35
- struct RNConfigurationInternal {
45
+ struct RNConfigurationInternal final {
36
46
  public:
37
47
  bool skipPermissionRequests SWIFT_PRIVATE;
38
48
  std::optional<AuthorizationLevelInternal> authorizationLevel SWIFT_PRIVATE;
@@ -42,6 +52,9 @@ namespace margelo::nitro::nitrogeolocation {
42
52
  public:
43
53
  RNConfigurationInternal() = default;
44
54
  explicit RNConfigurationInternal(bool skipPermissionRequests, std::optional<AuthorizationLevelInternal> authorizationLevel, std::optional<bool> enableBackgroundLocationUpdates, std::optional<LocationProviderInternal> locationProvider): skipPermissionRequests(skipPermissionRequests), authorizationLevel(authorizationLevel), enableBackgroundLocationUpdates(enableBackgroundLocationUpdates), locationProvider(locationProvider) {}
55
+
56
+ public:
57
+ friend bool operator==(const RNConfigurationInternal& lhs, const RNConfigurationInternal& rhs) = default;
45
58
  };
46
59
 
47
60
  } // namespace margelo::nitro::nitrogeolocation
@@ -54,18 +67,18 @@ namespace margelo::nitro {
54
67
  static inline margelo::nitro::nitrogeolocation::RNConfigurationInternal fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
55
68
  jsi::Object obj = arg.asObject(runtime);
56
69
  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"))
70
+ JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "skipPermissionRequests"))),
71
+ JSIConverter<std::optional<margelo::nitro::nitrogeolocation::AuthorizationLevelInternal>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "authorizationLevel"))),
72
+ JSIConverter<std::optional<bool>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "enableBackgroundLocationUpdates"))),
73
+ JSIConverter<std::optional<margelo::nitro::nitrogeolocation::LocationProviderInternal>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "locationProvider")))
61
74
  );
62
75
  }
63
76
  static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrogeolocation::RNConfigurationInternal& arg) {
64
77
  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));
78
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "skipPermissionRequests"), JSIConverter<bool>::toJSI(runtime, arg.skipPermissionRequests));
79
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "authorizationLevel"), JSIConverter<std::optional<margelo::nitro::nitrogeolocation::AuthorizationLevelInternal>>::toJSI(runtime, arg.authorizationLevel));
80
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "enableBackgroundLocationUpdates"), JSIConverter<std::optional<bool>>::toJSI(runtime, arg.enableBackgroundLocationUpdates));
81
+ obj.setProperty(runtime, PropNameIDCache::get(runtime, "locationProvider"), JSIConverter<std::optional<margelo::nitro::nitrogeolocation::LocationProviderInternal>>::toJSI(runtime, arg.locationProvider));
69
82
  return obj;
70
83
  }
71
84
  static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
@@ -73,10 +86,13 @@ namespace margelo::nitro {
73
86
  return false;
74
87
  }
75
88
  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;
89
+ if (!nitro::isPlainObject(runtime, obj)) {
90
+ return false;
91
+ }
92
+ if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "skipPermissionRequests")))) return false;
93
+ if (!JSIConverter<std::optional<margelo::nitro::nitrogeolocation::AuthorizationLevelInternal>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "authorizationLevel")))) return false;
94
+ if (!JSIConverter<std::optional<bool>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "enableBackgroundLocationUpdates")))) return false;
95
+ if (!JSIConverter<std::optional<margelo::nitro::nitrogeolocation::LocationProviderInternal>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "locationProvider")))) return false;
80
96
  return true;
81
97
  }
82
98
  };
package/package.json CHANGED
@@ -1,9 +1,19 @@
1
1
  {
2
2
  "name": "react-native-nitro-geolocation",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "⚡🚀Blazing-fast geolocation for React Native powered by Nitro Modules",
5
5
  "main": "src/index",
6
6
  "source": "src/index",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./src/index.tsx",
10
+ "default": "./src/index.tsx"
11
+ },
12
+ "./compat": {
13
+ "types": "./src/compat/index.tsx",
14
+ "default": "./src/compat/index.tsx"
15
+ }
16
+ },
7
17
  "codegenConfig": {
8
18
  "name": "NitroGeolocationSpec",
9
19
  "type": "modules",
@@ -26,7 +36,7 @@
26
36
  "android/fix-prefab.gradle",
27
37
  "android/gradle.properties",
28
38
  "android/CMakeLists.txt",
29
- "android/src",
39
+ "android/src/**/*",
30
40
  "ios/**/*.h",
31
41
  "ios/**/*.m",
32
42
  "ios/**/*.mm",
@@ -43,18 +53,17 @@
43
53
  "@types/react-test-renderer": "^18.0.0",
44
54
  "react": "19.1.0",
45
55
  "react-native": "0.81.1",
46
- "react-native-nitro-modules": "^0.29.6",
56
+ "react-native-nitro-modules": "0.32.0",
47
57
  "typescript": "^5.9.3"
48
58
  },
49
59
  "peerDependencies": {
50
- "react-native-nitro-modules": "*"
60
+ "react": ">=18.0.0",
61
+ "react-native": ">=0.75.0",
62
+ "react-native-nitro-modules": ">=0.32.0"
51
63
  },
52
64
  "create-react-native-library": {
53
65
  "languages": "kotlin-swift",
54
66
  "type": "nitro-module",
55
67
  "version": "0.54.3"
56
- },
57
- "installConfig": {
58
- "hoistingLimits": "workspaces"
59
68
  }
60
69
  }
@@ -0,0 +1,116 @@
1
+ import type {
2
+ LocationError,
3
+ LocationRequestOptions,
4
+ ModernGeolocationConfiguration as NitroModernGeolocationConfiguration,
5
+ PermissionStatus
6
+ } from "./NitroGeolocation.nitro";
7
+ import { NitroGeolocationHybridObject } from "./NitroGeolocationModule";
8
+ import type { ModernGeolocationConfiguration } from "./types";
9
+ import type { GeolocationResponse } from "./types";
10
+
11
+ export interface GeolocationClientConfig
12
+ extends ModernGeolocationConfiguration {}
13
+
14
+ /**
15
+ * GeolocationClient provides direct access to geolocation methods.
16
+ *
17
+ * Usage:
18
+ * ```tsx
19
+ * // With provider
20
+ * const client = new GeolocationClient({ locationProvider: 'auto' });
21
+ * <GeolocationClientProvider client={client}>
22
+ * <App />
23
+ * </GeolocationClientProvider>
24
+ *
25
+ * // Without provider
26
+ * const standaloneClient = new GeolocationClient();
27
+ * await standaloneClient.getCurrentPosition();
28
+ * ```
29
+ */
30
+ export class GeolocationClient {
31
+ private config: GeolocationClientConfig;
32
+
33
+ constructor(config: GeolocationClientConfig = {}) {
34
+ this.config = config;
35
+
36
+ // Set configuration on Nitro module
37
+ if (Object.keys(config).length > 0) {
38
+ const nativeConfig: NitroModernGeolocationConfiguration = {
39
+ ...config,
40
+ locationProvider:
41
+ config.locationProvider === "android"
42
+ ? "android_platform"
43
+ : config.locationProvider
44
+ };
45
+
46
+ NitroGeolocationHybridObject.setConfiguration(nativeConfig);
47
+ }
48
+ }
49
+
50
+ /**
51
+ * Check current location permission status.
52
+ * Does NOT request permission, only checks current state.
53
+ */
54
+ checkPermission = (): Promise<PermissionStatus> => {
55
+ return NitroGeolocationHybridObject.checkPermission();
56
+ };
57
+
58
+ /**
59
+ * Request location permission from the user.
60
+ * Shows system permission dialog if not yet determined.
61
+ */
62
+ requestPermission = (): Promise<PermissionStatus> => {
63
+ return NitroGeolocationHybridObject.requestPermission();
64
+ };
65
+
66
+ /**
67
+ * Get current location (one-time request).
68
+ *
69
+ * @param options - Location request options
70
+ * @returns Promise resolving to current position
71
+ */
72
+ getCurrentPosition = (
73
+ options?: LocationRequestOptions
74
+ ): Promise<GeolocationResponse> => {
75
+ return NitroGeolocationHybridObject.getCurrentPosition(options);
76
+ };
77
+
78
+ /**
79
+ * Start watching for continuous location updates.
80
+ *
81
+ * @param success - Called on each successful location update
82
+ * @param error - Called when an error occurs
83
+ * @param options - Location request options
84
+ * @returns Subscription token (UUID string) for cleanup
85
+ */
86
+ watchPosition = (
87
+ success: (position: GeolocationResponse) => void,
88
+ error?: (error: LocationError) => void,
89
+ options?: LocationRequestOptions
90
+ ): string => {
91
+ return NitroGeolocationHybridObject.watchPosition(success, error, options);
92
+ };
93
+
94
+ /**
95
+ * Stop a specific watch subscription.
96
+ *
97
+ * @param token - Subscription token from watchPosition()
98
+ */
99
+ unwatch = (token: string): void => {
100
+ NitroGeolocationHybridObject.unwatch(token);
101
+ };
102
+
103
+ /**
104
+ * Stop ALL watch subscriptions immediately.
105
+ */
106
+ stopObserving = (): void => {
107
+ NitroGeolocationHybridObject.stopObserving();
108
+ };
109
+
110
+ /**
111
+ * Get the current client configuration.
112
+ */
113
+ getConfig = (): Readonly<GeolocationClientConfig> => {
114
+ return { ...this.config };
115
+ };
116
+ }
@@ -1,41 +1,188 @@
1
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;
2
+ import type { GeolocationResponse } from "./types";
3
+
4
+ /**
5
+ * Permission status for location services.
6
+ * Matches native permission states across iOS and Android.
7
+ */
8
+ export type PermissionStatus =
9
+ | "granted" // User has granted location permission
10
+ | "denied" // User has denied permission
11
+ | "restricted" // Permission is restricted (iOS parental controls)
12
+ | "undetermined"; // Permission not yet requested
13
+
14
+ /**
15
+ * iOS authorization level.
16
+ */
17
+ export type AuthorizationLevel = "always" | "whenInUse" | "auto";
18
+
19
+ /**
20
+ * Android location provider (internal).
21
+ * Note: Use "android_platform" instead of "android" to avoid C++ macro conflicts.
22
+ */
23
+ export type LocationProvider = "playServices" | "android_platform" | "auto";
24
+
25
+ /**
26
+ * Global configuration for geolocation services.
27
+ * Set once via GeolocationProvider.
28
+ */
29
+ export interface ModernGeolocationConfiguration {
30
+ /**
31
+ * Automatically request location permission when GeolocationProvider mounts.
32
+ * When true, permission is requested immediately on app start.
33
+ * When false, you must manually call useRequestPermission().
34
+ * @default false
35
+ */
36
+ autoRequestPermission?: boolean;
37
+
38
+ /**
39
+ * iOS: Authorization level
40
+ * - 'always': Request "Always" permission (background + foreground)
41
+ * - 'whenInUse': Request "When In Use" permission (foreground only)
42
+ * - 'auto': Auto-detect from Info.plist keys
43
+ */
44
+ authorizationLevel?: AuthorizationLevel;
45
+
46
+ /**
47
+ * iOS: Enable background location updates.
48
+ * Requires "UIBackgroundModes" with "location" in Info.plist.
49
+ */
18
50
  enableBackgroundLocationUpdates?: boolean;
19
- locationProvider?: LocationProviderInternal;
51
+
52
+ /**
53
+ * Android: Location provider
54
+ * - 'playServices': Use Google Play Services (fused location)
55
+ * - 'android_platform': Use Android platform LocationManager
56
+ * - 'auto': Auto-select (prefer Play Services if available)
57
+ */
58
+ locationProvider?: LocationProvider;
59
+ }
60
+
61
+ /**
62
+ * Options for location requests.
63
+ */
64
+ export interface LocationRequestOptions {
65
+ /** Timeout in milliseconds (default: 600000 / 10 minutes) */
66
+ timeout?: number;
67
+
68
+ /** Maximum age of cached location in milliseconds (default: 0) */
69
+ maximumAge?: number;
70
+
71
+ /** Enable high accuracy mode (GPS) */
72
+ enableHighAccuracy?: boolean;
73
+
74
+ /** Minimum time interval between updates in milliseconds (watch only) */
75
+ interval?: number;
76
+
77
+ /** Fastest interval for updates in milliseconds (Android watch only) */
78
+ fastestInterval?: number;
79
+
80
+ /** Minimum distance change in meters for updates (watch only) */
81
+ distanceFilter?: number;
82
+
83
+ /** Use significant location changes mode (iOS watch only) */
84
+ useSignificantChanges?: boolean;
20
85
  }
21
86
 
87
+ /**
88
+ * Location error structure.
89
+ */
90
+ export interface LocationError {
91
+ code: number; // 1: PERMISSION_DENIED, 2: POSITION_UNAVAILABLE, 3: TIMEOUT
92
+ message: string;
93
+ }
94
+
95
+ /**
96
+ * Modern Geolocation Nitro Module.
97
+ *
98
+ * Key Features:
99
+ * - Promise-based for async operations
100
+ * - First-class function callbacks for continuous updates
101
+ * - Token-based subscriptions (internal use only)
102
+ * - Type-safe across JS ↔ Native boundary
103
+ */
22
104
  export interface NitroGeolocation
23
105
  extends HybridObject<{ ios: "swift"; android: "kotlin" }> {
24
- setRNConfiguration(config: RNConfigurationInternal): void;
25
- requestAuthorization(
26
- success?: () => void,
27
- error?: (error: GeolocationError) => void
28
- ): void;
106
+ /**
107
+ * Set global geolocation configuration.
108
+ * Should be called once at app startup via GeolocationProvider.
109
+ *
110
+ * @param config - Platform-specific configuration
111
+ */
112
+ setConfiguration(config: ModernGeolocationConfiguration): void;
113
+
114
+ /**
115
+ * Check current location permission status.
116
+ * Does NOT request permission, only checks current state.
117
+ *
118
+ * @returns Promise resolving to current permission status
119
+ */
120
+ checkPermission(): Promise<PermissionStatus>;
121
+
122
+ /**
123
+ * Request location permission from the user.
124
+ * Shows system permission dialog if not yet determined.
125
+ *
126
+ * @returns Promise resolving to new permission status
127
+ */
128
+ requestPermission(): Promise<PermissionStatus>;
129
+
130
+ /**
131
+ * Get current location (one-time request).
132
+ *
133
+ * Strategy:
134
+ * 1. Check cached location (if maximumAge allows)
135
+ * 2. Request fresh location from GPS/Network
136
+ * 3. Timeout after specified duration
137
+ *
138
+ * @param options - Location request options
139
+ * @returns Promise resolving to current position
140
+ * @throws LocationError if permission denied, timeout, or unavailable
141
+ */
29
142
  getCurrentPosition(
30
- success: (position: GeolocationResponse) => void,
31
- error?: (error: GeolocationError) => void,
32
- options?: GeolocationOptions
33
- ): void;
143
+ options?: LocationRequestOptions
144
+ ): Promise<GeolocationResponse>;
145
+
146
+ /**
147
+ * Start watching for continuous location updates.
148
+ *
149
+ * IMPORTANT: This is a LOW-LEVEL API.
150
+ * Users should use useWatchPosition() hook instead.
151
+ *
152
+ * Nitro Advantage: Functions are first-class citizens!
153
+ * We can store callbacks and call them multiple times,
154
+ * unlike Turbo Modules which require Events.
155
+ *
156
+ * @param success - Called on each successful location update
157
+ * @param error - Called when an error occurs
158
+ * @param options - Location request options
159
+ * @returns Subscription token (UUID string) for cleanup
160
+ */
34
161
  watchPosition(
35
162
  success: (position: GeolocationResponse) => void,
36
- error?: (error: GeolocationError) => void,
37
- options?: GeolocationOptions
38
- ): number;
39
- clearWatch(watchId: number): void;
163
+ error?: (error: LocationError) => void,
164
+ options?: LocationRequestOptions
165
+ ): string;
166
+
167
+ /**
168
+ * Stop a specific watch subscription.
169
+ *
170
+ * IMPORTANT: This is a LOW-LEVEL API.
171
+ * Cleanup is handled automatically by useWatchPosition() hook.
172
+ *
173
+ * @param token - Subscription token from watchPosition()
174
+ */
175
+ unwatch(token: string): void;
176
+
177
+ /**
178
+ * Stop ALL watch subscriptions immediately.
179
+ *
180
+ * Use cases:
181
+ * - Emergency cleanup
182
+ * - App termination
183
+ * - User logout
184
+ *
185
+ * Note: Individual subscriptions should use unwatch() instead.
186
+ */
40
187
  stopObserving(): void;
41
188
  }
@@ -0,0 +1,41 @@
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
+ }
21
+
22
+ export interface NitroGeolocationCompat
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;
41
+ }
@@ -1,5 +1,11 @@
1
1
  import { NitroModules } from "react-native-nitro-modules";
2
2
  import type { NitroGeolocation } from "./NitroGeolocation.nitro";
3
+ import type { NitroGeolocationCompat } from "./NitroGeolocationCompat.nitro";
3
4
 
4
5
  export const NitroGeolocationHybridObject =
5
6
  NitroModules.createHybridObject<NitroGeolocation>("NitroGeolocation");
7
+
8
+ export const NitroGeolocationHybridCompatObject =
9
+ NitroModules.createHybridObject<NitroGeolocationCompat>(
10
+ "NitroGeolocationCompat"
11
+ );
@@ -0,0 +1,9 @@
1
+ import { NitroGeolocationHybridCompatObject } from "../NitroGeolocationModule";
2
+ /**
3
+ * Clears a specific watch session identified by watchId.
4
+ *
5
+ * @param watchId - The ID returned by watchPosition()
6
+ */
7
+ export function clearWatch(watchId: number): void {
8
+ NitroGeolocationHybridCompatObject.clearWatch(watchId);
9
+ }
@@ -1,14 +1,18 @@
1
- import { NitroGeolocationHybridObject } from "./NitroGeolocationModule";
1
+ import { NitroGeolocationHybridCompatObject } from "../NitroGeolocationModule";
2
2
  import type {
3
3
  GeolocationError,
4
4
  GeolocationOptions,
5
5
  GeolocationResponse
6
- } from "./types";
6
+ } from "../types";
7
7
 
8
8
  export function getCurrentPosition(
9
9
  success: (position: GeolocationResponse) => void,
10
10
  error?: (error: GeolocationError) => void,
11
11
  options?: GeolocationOptions
12
12
  ): void {
13
- NitroGeolocationHybridObject.getCurrentPosition(success, error, options);
13
+ NitroGeolocationHybridCompatObject.getCurrentPosition(
14
+ success,
15
+ error,
16
+ options
17
+ );
14
18
  }
@@ -0,0 +1,34 @@
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";
8
+
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";
16
+
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;