react-native-nitro-location-tracking 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.
- package/LICENSE +20 -0
- package/NitroLocationTracking.podspec +29 -0
- package/README.md +39 -0
- package/android/CMakeLists.txt +24 -0
- package/android/build.gradle +122 -0
- package/android/src/main/AndroidManifest.xml +18 -0
- package/android/src/main/cpp/cpp-adapter.cpp +6 -0
- package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/ConnectionManager.kt +137 -0
- package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/LocationEngine.kt +93 -0
- package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/LocationForegroundService.kt +65 -0
- package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/NativeDBWriter.kt +80 -0
- package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/NitroLocationTracking.kt +180 -0
- package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/NitroLocationTrackingPackage.kt +22 -0
- package/android/src/main/java/com/margelo/nitro/nitrolocationtracking/NotificationService.kt +75 -0
- package/ios/ConnectionManager.swift +144 -0
- package/ios/LocationEngine.swift +146 -0
- package/ios/NativeDBWriter.swift +121 -0
- package/ios/NitroLocationTracking.swift +127 -0
- package/ios/NotificationService.swift +31 -0
- package/lib/module/LocationSmoother.js +33 -0
- package/lib/module/LocationSmoother.js.map +1 -0
- package/lib/module/NitroLocationTracking.nitro.js +4 -0
- package/lib/module/NitroLocationTracking.nitro.js.map +1 -0
- package/lib/module/bearing.js +19 -0
- package/lib/module/bearing.js.map +1 -0
- package/lib/module/db.js +234 -0
- package/lib/module/db.js.map +1 -0
- package/lib/module/index.js +68 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/package.json +1 -0
- package/lib/typescript/src/LocationSmoother.d.ts +19 -0
- package/lib/typescript/src/LocationSmoother.d.ts.map +1 -0
- package/lib/typescript/src/NitroLocationTracking.nitro.d.ts +59 -0
- package/lib/typescript/src/NitroLocationTracking.nitro.d.ts.map +1 -0
- package/lib/typescript/src/bearing.d.ts +9 -0
- package/lib/typescript/src/bearing.d.ts.map +1 -0
- package/lib/typescript/src/db.d.ts +1 -0
- package/lib/typescript/src/db.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +21 -0
- package/lib/typescript/src/index.d.ts.map +1 -0
- package/nitro.json +17 -0
- package/nitrogen/generated/android/c++/JAccuracyLevel.hpp +61 -0
- package/nitrogen/generated/android/c++/JConnectionConfig.hpp +81 -0
- package/nitrogen/generated/android/c++/JConnectionState.hpp +61 -0
- package/nitrogen/generated/android/c++/JFunc_void_ConnectionState.hpp +77 -0
- package/nitrogen/generated/android/c++/JFunc_void_LocationData.hpp +77 -0
- package/nitrogen/generated/android/c++/JFunc_void_bool.hpp +75 -0
- package/nitrogen/generated/android/c++/JFunc_void_std__string.hpp +76 -0
- package/nitrogen/generated/android/c++/JHybridNitroLocationTrackingSpec.cpp +179 -0
- package/nitrogen/generated/android/c++/JHybridNitroLocationTrackingSpec.hpp +83 -0
- package/nitrogen/generated/android/c++/JLocationConfig.hpp +91 -0
- package/nitrogen/generated/android/c++/JLocationData.hpp +81 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolocationtracking/AccuracyLevel.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolocationtracking/ConnectionConfig.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolocationtracking/ConnectionState.kt +24 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolocationtracking/Func_void_ConnectionState.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolocationtracking/Func_void_LocationData.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolocationtracking/Func_void_bool.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolocationtracking/Func_void_std__string.kt +80 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolocationtracking/HybridNitroLocationTrackingSpec.kt +146 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolocationtracking/LocationConfig.kt +62 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolocationtracking/LocationData.kt +56 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrolocationtracking/nitrolocationtrackingOnLoad.kt +35 -0
- package/nitrogen/generated/android/nitrolocationtracking+autolinking.cmake +81 -0
- package/nitrogen/generated/android/nitrolocationtracking+autolinking.gradle +27 -0
- package/nitrogen/generated/android/nitrolocationtrackingOnLoad.cpp +52 -0
- package/nitrogen/generated/android/nitrolocationtrackingOnLoad.hpp +25 -0
- package/nitrogen/generated/ios/NitroLocationTracking+autolinking.rb +60 -0
- package/nitrogen/generated/ios/NitroLocationTracking-Swift-Cxx-Bridge.cpp +73 -0
- package/nitrogen/generated/ios/NitroLocationTracking-Swift-Cxx-Bridge.hpp +231 -0
- package/nitrogen/generated/ios/NitroLocationTracking-Swift-Cxx-Umbrella.hpp +61 -0
- package/nitrogen/generated/ios/NitroLocationTrackingAutolinking.mm +33 -0
- package/nitrogen/generated/ios/NitroLocationTrackingAutolinking.swift +26 -0
- package/nitrogen/generated/ios/c++/HybridNitroLocationTrackingSpecSwift.cpp +11 -0
- package/nitrogen/generated/ios/c++/HybridNitroLocationTrackingSpecSwift.hpp +206 -0
- package/nitrogen/generated/ios/swift/AccuracyLevel.swift +44 -0
- package/nitrogen/generated/ios/swift/ConnectionConfig.swift +59 -0
- package/nitrogen/generated/ios/swift/ConnectionState.swift +44 -0
- package/nitrogen/generated/ios/swift/Func_void_ConnectionState.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_LocationData.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_bool.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__exception_ptr.swift +46 -0
- package/nitrogen/generated/ios/swift/Func_void_std__string.swift +46 -0
- package/nitrogen/generated/ios/swift/HybridNitroLocationTrackingSpec.swift +72 -0
- package/nitrogen/generated/ios/swift/HybridNitroLocationTrackingSpec_cxx.swift +362 -0
- package/nitrogen/generated/ios/swift/LocationConfig.swift +69 -0
- package/nitrogen/generated/ios/swift/LocationData.swift +59 -0
- package/nitrogen/generated/shared/c++/AccuracyLevel.hpp +80 -0
- package/nitrogen/generated/shared/c++/ConnectionConfig.hpp +107 -0
- package/nitrogen/generated/shared/c++/ConnectionState.hpp +80 -0
- package/nitrogen/generated/shared/c++/HybridNitroLocationTrackingSpec.cpp +38 -0
- package/nitrogen/generated/shared/c++/HybridNitroLocationTrackingSpec.hpp +92 -0
- package/nitrogen/generated/shared/c++/LocationConfig.hpp +117 -0
- package/nitrogen/generated/shared/c++/LocationData.hpp +107 -0
- package/package.json +174 -0
- package/src/LocationSmoother.ts +46 -0
- package/src/NitroLocationTracking.nitro.ts +79 -0
- package/src/bearing.ts +22 -0
- package/src/db.ts +232 -0
- package/src/index.tsx +92 -0
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// ConnectionState.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/NitroHash.hpp>)
|
|
11
|
+
#include <NitroModules/NitroHash.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
16
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
21
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
|
|
26
|
+
namespace margelo::nitro::nitrolocationtracking {
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* An enum which can be represented as a JavaScript union (ConnectionState).
|
|
30
|
+
*/
|
|
31
|
+
enum class ConnectionState {
|
|
32
|
+
CONNECTED SWIFT_NAME(connected) = 0,
|
|
33
|
+
DISCONNECTED SWIFT_NAME(disconnected) = 1,
|
|
34
|
+
RECONNECTING SWIFT_NAME(reconnecting) = 2,
|
|
35
|
+
} CLOSED_ENUM;
|
|
36
|
+
|
|
37
|
+
} // namespace margelo::nitro::nitrolocationtracking
|
|
38
|
+
|
|
39
|
+
namespace margelo::nitro {
|
|
40
|
+
|
|
41
|
+
// C++ ConnectionState <> JS ConnectionState (union)
|
|
42
|
+
template <>
|
|
43
|
+
struct JSIConverter<margelo::nitro::nitrolocationtracking::ConnectionState> final {
|
|
44
|
+
static inline margelo::nitro::nitrolocationtracking::ConnectionState 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("connected"): return margelo::nitro::nitrolocationtracking::ConnectionState::CONNECTED;
|
|
48
|
+
case hashString("disconnected"): return margelo::nitro::nitrolocationtracking::ConnectionState::DISCONNECTED;
|
|
49
|
+
case hashString("reconnecting"): return margelo::nitro::nitrolocationtracking::ConnectionState::RECONNECTING;
|
|
50
|
+
default: [[unlikely]]
|
|
51
|
+
throw std::invalid_argument("Cannot convert \"" + unionValue + "\" to enum ConnectionState - invalid value!");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, margelo::nitro::nitrolocationtracking::ConnectionState arg) {
|
|
55
|
+
switch (arg) {
|
|
56
|
+
case margelo::nitro::nitrolocationtracking::ConnectionState::CONNECTED: return JSIConverter<std::string>::toJSI(runtime, "connected");
|
|
57
|
+
case margelo::nitro::nitrolocationtracking::ConnectionState::DISCONNECTED: return JSIConverter<std::string>::toJSI(runtime, "disconnected");
|
|
58
|
+
case margelo::nitro::nitrolocationtracking::ConnectionState::RECONNECTING: return JSIConverter<std::string>::toJSI(runtime, "reconnecting");
|
|
59
|
+
default: [[unlikely]]
|
|
60
|
+
throw std::invalid_argument("Cannot convert ConnectionState 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("connected"):
|
|
71
|
+
case hashString("disconnected"):
|
|
72
|
+
case hashString("reconnecting"):
|
|
73
|
+
return true;
|
|
74
|
+
default:
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNitroLocationTrackingSpec.cpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#include "HybridNitroLocationTrackingSpec.hpp"
|
|
9
|
+
|
|
10
|
+
namespace margelo::nitro::nitrolocationtracking {
|
|
11
|
+
|
|
12
|
+
void HybridNitroLocationTrackingSpec::loadHybridMethods() {
|
|
13
|
+
// load base methods/properties
|
|
14
|
+
HybridObject::loadHybridMethods();
|
|
15
|
+
// load custom methods/properties
|
|
16
|
+
registerHybrids(this, [](Prototype& prototype) {
|
|
17
|
+
prototype.registerHybridMethod("configure", &HybridNitroLocationTrackingSpec::configure);
|
|
18
|
+
prototype.registerHybridMethod("startTracking", &HybridNitroLocationTrackingSpec::startTracking);
|
|
19
|
+
prototype.registerHybridMethod("stopTracking", &HybridNitroLocationTrackingSpec::stopTracking);
|
|
20
|
+
prototype.registerHybridMethod("getCurrentLocation", &HybridNitroLocationTrackingSpec::getCurrentLocation);
|
|
21
|
+
prototype.registerHybridMethod("isTracking", &HybridNitroLocationTrackingSpec::isTracking);
|
|
22
|
+
prototype.registerHybridMethod("onLocation", &HybridNitroLocationTrackingSpec::onLocation);
|
|
23
|
+
prototype.registerHybridMethod("onMotionChange", &HybridNitroLocationTrackingSpec::onMotionChange);
|
|
24
|
+
prototype.registerHybridMethod("configureConnection", &HybridNitroLocationTrackingSpec::configureConnection);
|
|
25
|
+
prototype.registerHybridMethod("connectWebSocket", &HybridNitroLocationTrackingSpec::connectWebSocket);
|
|
26
|
+
prototype.registerHybridMethod("disconnectWebSocket", &HybridNitroLocationTrackingSpec::disconnectWebSocket);
|
|
27
|
+
prototype.registerHybridMethod("sendMessage", &HybridNitroLocationTrackingSpec::sendMessage);
|
|
28
|
+
prototype.registerHybridMethod("getConnectionState", &HybridNitroLocationTrackingSpec::getConnectionState);
|
|
29
|
+
prototype.registerHybridMethod("onConnectionStateChange", &HybridNitroLocationTrackingSpec::onConnectionStateChange);
|
|
30
|
+
prototype.registerHybridMethod("onMessage", &HybridNitroLocationTrackingSpec::onMessage);
|
|
31
|
+
prototype.registerHybridMethod("forceSync", &HybridNitroLocationTrackingSpec::forceSync);
|
|
32
|
+
prototype.registerHybridMethod("showLocalNotification", &HybridNitroLocationTrackingSpec::showLocalNotification);
|
|
33
|
+
prototype.registerHybridMethod("updateForegroundNotification", &HybridNitroLocationTrackingSpec::updateForegroundNotification);
|
|
34
|
+
prototype.registerHybridMethod("destroy", &HybridNitroLocationTrackingSpec::destroy);
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
} // namespace margelo::nitro::nitrolocationtracking
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// HybridNitroLocationTrackingSpec.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/HybridObject.hpp>)
|
|
11
|
+
#include <NitroModules/HybridObject.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
|
|
16
|
+
// Forward declaration of `LocationConfig` to properly resolve imports.
|
|
17
|
+
namespace margelo::nitro::nitrolocationtracking { struct LocationConfig; }
|
|
18
|
+
// Forward declaration of `LocationData` to properly resolve imports.
|
|
19
|
+
namespace margelo::nitro::nitrolocationtracking { struct LocationData; }
|
|
20
|
+
// Forward declaration of `ConnectionConfig` to properly resolve imports.
|
|
21
|
+
namespace margelo::nitro::nitrolocationtracking { struct ConnectionConfig; }
|
|
22
|
+
// Forward declaration of `ConnectionState` to properly resolve imports.
|
|
23
|
+
namespace margelo::nitro::nitrolocationtracking { enum class ConnectionState; }
|
|
24
|
+
|
|
25
|
+
#include "LocationConfig.hpp"
|
|
26
|
+
#include "LocationData.hpp"
|
|
27
|
+
#include <NitroModules/Promise.hpp>
|
|
28
|
+
#include <functional>
|
|
29
|
+
#include "ConnectionConfig.hpp"
|
|
30
|
+
#include <string>
|
|
31
|
+
#include "ConnectionState.hpp"
|
|
32
|
+
|
|
33
|
+
namespace margelo::nitro::nitrolocationtracking {
|
|
34
|
+
|
|
35
|
+
using namespace margelo::nitro;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* An abstract base class for `NitroLocationTracking`
|
|
39
|
+
* Inherit this class to create instances of `HybridNitroLocationTrackingSpec` in C++.
|
|
40
|
+
* You must explicitly call `HybridObject`'s constructor yourself, because it is virtual.
|
|
41
|
+
* @example
|
|
42
|
+
* ```cpp
|
|
43
|
+
* class HybridNitroLocationTracking: public HybridNitroLocationTrackingSpec {
|
|
44
|
+
* public:
|
|
45
|
+
* HybridNitroLocationTracking(...): HybridObject(TAG) { ... }
|
|
46
|
+
* // ...
|
|
47
|
+
* };
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
class HybridNitroLocationTrackingSpec: public virtual HybridObject {
|
|
51
|
+
public:
|
|
52
|
+
// Constructor
|
|
53
|
+
explicit HybridNitroLocationTrackingSpec(): HybridObject(TAG) { }
|
|
54
|
+
|
|
55
|
+
// Destructor
|
|
56
|
+
~HybridNitroLocationTrackingSpec() override = default;
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
// Properties
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
public:
|
|
63
|
+
// Methods
|
|
64
|
+
virtual void configure(const LocationConfig& config) = 0;
|
|
65
|
+
virtual void startTracking() = 0;
|
|
66
|
+
virtual void stopTracking() = 0;
|
|
67
|
+
virtual std::shared_ptr<Promise<LocationData>> getCurrentLocation() = 0;
|
|
68
|
+
virtual bool isTracking() = 0;
|
|
69
|
+
virtual void onLocation(const std::function<void(const LocationData& /* location */)>& callback) = 0;
|
|
70
|
+
virtual void onMotionChange(const std::function<void(bool /* isMoving */)>& callback) = 0;
|
|
71
|
+
virtual void configureConnection(const ConnectionConfig& config) = 0;
|
|
72
|
+
virtual void connectWebSocket() = 0;
|
|
73
|
+
virtual void disconnectWebSocket() = 0;
|
|
74
|
+
virtual void sendMessage(const std::string& message) = 0;
|
|
75
|
+
virtual ConnectionState getConnectionState() = 0;
|
|
76
|
+
virtual void onConnectionStateChange(const std::function<void(ConnectionState /* state */)>& callback) = 0;
|
|
77
|
+
virtual void onMessage(const std::function<void(const std::string& /* message */)>& callback) = 0;
|
|
78
|
+
virtual std::shared_ptr<Promise<bool>> forceSync() = 0;
|
|
79
|
+
virtual void showLocalNotification(const std::string& title, const std::string& body) = 0;
|
|
80
|
+
virtual void updateForegroundNotification(const std::string& title, const std::string& body) = 0;
|
|
81
|
+
virtual void destroy() = 0;
|
|
82
|
+
|
|
83
|
+
protected:
|
|
84
|
+
// Hybrid Setup
|
|
85
|
+
void loadHybridMethods() override;
|
|
86
|
+
|
|
87
|
+
protected:
|
|
88
|
+
// Tag for logging
|
|
89
|
+
static constexpr auto TAG = "NitroLocationTracking";
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
} // namespace margelo::nitro::nitrolocationtracking
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// LocationConfig.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
// Forward declaration of `AccuracyLevel` to properly resolve imports.
|
|
32
|
+
namespace margelo::nitro::nitrolocationtracking { enum class AccuracyLevel; }
|
|
33
|
+
|
|
34
|
+
#include "AccuracyLevel.hpp"
|
|
35
|
+
#include <string>
|
|
36
|
+
|
|
37
|
+
namespace margelo::nitro::nitrolocationtracking {
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* A struct which can be represented as a JavaScript object (LocationConfig).
|
|
41
|
+
*/
|
|
42
|
+
struct LocationConfig final {
|
|
43
|
+
public:
|
|
44
|
+
AccuracyLevel desiredAccuracy SWIFT_PRIVATE;
|
|
45
|
+
double distanceFilter SWIFT_PRIVATE;
|
|
46
|
+
double intervalMs SWIFT_PRIVATE;
|
|
47
|
+
double fastestIntervalMs SWIFT_PRIVATE;
|
|
48
|
+
double stopTimeout SWIFT_PRIVATE;
|
|
49
|
+
bool stopOnTerminate SWIFT_PRIVATE;
|
|
50
|
+
bool startOnBoot SWIFT_PRIVATE;
|
|
51
|
+
std::string foregroundNotificationTitle SWIFT_PRIVATE;
|
|
52
|
+
std::string foregroundNotificationText SWIFT_PRIVATE;
|
|
53
|
+
|
|
54
|
+
public:
|
|
55
|
+
LocationConfig() = default;
|
|
56
|
+
explicit LocationConfig(AccuracyLevel desiredAccuracy, double distanceFilter, double intervalMs, double fastestIntervalMs, double stopTimeout, bool stopOnTerminate, bool startOnBoot, std::string foregroundNotificationTitle, std::string foregroundNotificationText): desiredAccuracy(desiredAccuracy), distanceFilter(distanceFilter), intervalMs(intervalMs), fastestIntervalMs(fastestIntervalMs), stopTimeout(stopTimeout), stopOnTerminate(stopOnTerminate), startOnBoot(startOnBoot), foregroundNotificationTitle(foregroundNotificationTitle), foregroundNotificationText(foregroundNotificationText) {}
|
|
57
|
+
|
|
58
|
+
public:
|
|
59
|
+
friend bool operator==(const LocationConfig& lhs, const LocationConfig& rhs) = default;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
} // namespace margelo::nitro::nitrolocationtracking
|
|
63
|
+
|
|
64
|
+
namespace margelo::nitro {
|
|
65
|
+
|
|
66
|
+
// C++ LocationConfig <> JS LocationConfig (object)
|
|
67
|
+
template <>
|
|
68
|
+
struct JSIConverter<margelo::nitro::nitrolocationtracking::LocationConfig> final {
|
|
69
|
+
static inline margelo::nitro::nitrolocationtracking::LocationConfig fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
70
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
71
|
+
return margelo::nitro::nitrolocationtracking::LocationConfig(
|
|
72
|
+
JSIConverter<margelo::nitro::nitrolocationtracking::AccuracyLevel>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "desiredAccuracy"))),
|
|
73
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "distanceFilter"))),
|
|
74
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "intervalMs"))),
|
|
75
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "fastestIntervalMs"))),
|
|
76
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "stopTimeout"))),
|
|
77
|
+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "stopOnTerminate"))),
|
|
78
|
+
JSIConverter<bool>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startOnBoot"))),
|
|
79
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "foregroundNotificationTitle"))),
|
|
80
|
+
JSIConverter<std::string>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "foregroundNotificationText")))
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrolocationtracking::LocationConfig& arg) {
|
|
84
|
+
jsi::Object obj(runtime);
|
|
85
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "desiredAccuracy"), JSIConverter<margelo::nitro::nitrolocationtracking::AccuracyLevel>::toJSI(runtime, arg.desiredAccuracy));
|
|
86
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "distanceFilter"), JSIConverter<double>::toJSI(runtime, arg.distanceFilter));
|
|
87
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "intervalMs"), JSIConverter<double>::toJSI(runtime, arg.intervalMs));
|
|
88
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "fastestIntervalMs"), JSIConverter<double>::toJSI(runtime, arg.fastestIntervalMs));
|
|
89
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "stopTimeout"), JSIConverter<double>::toJSI(runtime, arg.stopTimeout));
|
|
90
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "stopOnTerminate"), JSIConverter<bool>::toJSI(runtime, arg.stopOnTerminate));
|
|
91
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "startOnBoot"), JSIConverter<bool>::toJSI(runtime, arg.startOnBoot));
|
|
92
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "foregroundNotificationTitle"), JSIConverter<std::string>::toJSI(runtime, arg.foregroundNotificationTitle));
|
|
93
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "foregroundNotificationText"), JSIConverter<std::string>::toJSI(runtime, arg.foregroundNotificationText));
|
|
94
|
+
return obj;
|
|
95
|
+
}
|
|
96
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
97
|
+
if (!value.isObject()) {
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
jsi::Object obj = value.getObject(runtime);
|
|
101
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
if (!JSIConverter<margelo::nitro::nitrolocationtracking::AccuracyLevel>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "desiredAccuracy")))) return false;
|
|
105
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "distanceFilter")))) return false;
|
|
106
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "intervalMs")))) return false;
|
|
107
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "fastestIntervalMs")))) return false;
|
|
108
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "stopTimeout")))) return false;
|
|
109
|
+
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "stopOnTerminate")))) return false;
|
|
110
|
+
if (!JSIConverter<bool>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startOnBoot")))) return false;
|
|
111
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "foregroundNotificationTitle")))) return false;
|
|
112
|
+
if (!JSIConverter<std::string>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "foregroundNotificationText")))) return false;
|
|
113
|
+
return true;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
|
|
117
|
+
} // namespace margelo::nitro
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
///
|
|
2
|
+
/// LocationData.hpp
|
|
3
|
+
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
|
|
4
|
+
/// https://github.com/mrousavy/nitro
|
|
5
|
+
/// Copyright © Marc Rousavy @ Margelo
|
|
6
|
+
///
|
|
7
|
+
|
|
8
|
+
#pragma once
|
|
9
|
+
|
|
10
|
+
#if __has_include(<NitroModules/JSIConverter.hpp>)
|
|
11
|
+
#include <NitroModules/JSIConverter.hpp>
|
|
12
|
+
#else
|
|
13
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
14
|
+
#endif
|
|
15
|
+
#if __has_include(<NitroModules/NitroDefines.hpp>)
|
|
16
|
+
#include <NitroModules/NitroDefines.hpp>
|
|
17
|
+
#else
|
|
18
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
19
|
+
#endif
|
|
20
|
+
#if __has_include(<NitroModules/JSIHelpers.hpp>)
|
|
21
|
+
#include <NitroModules/JSIHelpers.hpp>
|
|
22
|
+
#else
|
|
23
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
24
|
+
#endif
|
|
25
|
+
#if __has_include(<NitroModules/PropNameIDCache.hpp>)
|
|
26
|
+
#include <NitroModules/PropNameIDCache.hpp>
|
|
27
|
+
#else
|
|
28
|
+
#error NitroModules cannot be found! Are you sure you installed NitroModules properly?
|
|
29
|
+
#endif
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
namespace margelo::nitro::nitrolocationtracking {
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A struct which can be represented as a JavaScript object (LocationData).
|
|
39
|
+
*/
|
|
40
|
+
struct LocationData final {
|
|
41
|
+
public:
|
|
42
|
+
double latitude SWIFT_PRIVATE;
|
|
43
|
+
double longitude SWIFT_PRIVATE;
|
|
44
|
+
double altitude SWIFT_PRIVATE;
|
|
45
|
+
double speed SWIFT_PRIVATE;
|
|
46
|
+
double bearing SWIFT_PRIVATE;
|
|
47
|
+
double accuracy SWIFT_PRIVATE;
|
|
48
|
+
double timestamp SWIFT_PRIVATE;
|
|
49
|
+
|
|
50
|
+
public:
|
|
51
|
+
LocationData() = default;
|
|
52
|
+
explicit LocationData(double latitude, double longitude, double altitude, double speed, double bearing, double accuracy, double timestamp): latitude(latitude), longitude(longitude), altitude(altitude), speed(speed), bearing(bearing), accuracy(accuracy), timestamp(timestamp) {}
|
|
53
|
+
|
|
54
|
+
public:
|
|
55
|
+
friend bool operator==(const LocationData& lhs, const LocationData& rhs) = default;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
} // namespace margelo::nitro::nitrolocationtracking
|
|
59
|
+
|
|
60
|
+
namespace margelo::nitro {
|
|
61
|
+
|
|
62
|
+
// C++ LocationData <> JS LocationData (object)
|
|
63
|
+
template <>
|
|
64
|
+
struct JSIConverter<margelo::nitro::nitrolocationtracking::LocationData> final {
|
|
65
|
+
static inline margelo::nitro::nitrolocationtracking::LocationData fromJSI(jsi::Runtime& runtime, const jsi::Value& arg) {
|
|
66
|
+
jsi::Object obj = arg.asObject(runtime);
|
|
67
|
+
return margelo::nitro::nitrolocationtracking::LocationData(
|
|
68
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "latitude"))),
|
|
69
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "longitude"))),
|
|
70
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "altitude"))),
|
|
71
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speed"))),
|
|
72
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bearing"))),
|
|
73
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "accuracy"))),
|
|
74
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "timestamp")))
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::nitrolocationtracking::LocationData& arg) {
|
|
78
|
+
jsi::Object obj(runtime);
|
|
79
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "latitude"), JSIConverter<double>::toJSI(runtime, arg.latitude));
|
|
80
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "longitude"), JSIConverter<double>::toJSI(runtime, arg.longitude));
|
|
81
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "altitude"), JSIConverter<double>::toJSI(runtime, arg.altitude));
|
|
82
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "speed"), JSIConverter<double>::toJSI(runtime, arg.speed));
|
|
83
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "bearing"), JSIConverter<double>::toJSI(runtime, arg.bearing));
|
|
84
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "accuracy"), JSIConverter<double>::toJSI(runtime, arg.accuracy));
|
|
85
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "timestamp"), JSIConverter<double>::toJSI(runtime, arg.timestamp));
|
|
86
|
+
return obj;
|
|
87
|
+
}
|
|
88
|
+
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
89
|
+
if (!value.isObject()) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
jsi::Object obj = value.getObject(runtime);
|
|
93
|
+
if (!nitro::isPlainObject(runtime, obj)) {
|
|
94
|
+
return false;
|
|
95
|
+
}
|
|
96
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "latitude")))) return false;
|
|
97
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "longitude")))) return false;
|
|
98
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "altitude")))) return false;
|
|
99
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "speed")))) return false;
|
|
100
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "bearing")))) return false;
|
|
101
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "accuracy")))) return false;
|
|
102
|
+
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "timestamp")))) return false;
|
|
103
|
+
return true;
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
} // namespace margelo::nitro
|
package/package.json
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "react-native-nitro-location-tracking",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "A React Native Nitro module for location tracking",
|
|
5
|
+
"main": "./lib/module/index.js",
|
|
6
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"source": "./src/index.tsx",
|
|
10
|
+
"types": "./lib/typescript/src/index.d.ts",
|
|
11
|
+
"default": "./lib/module/index.js"
|
|
12
|
+
},
|
|
13
|
+
"./package.json": "./package.json"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src",
|
|
17
|
+
"lib",
|
|
18
|
+
"android",
|
|
19
|
+
"ios",
|
|
20
|
+
"cpp",
|
|
21
|
+
"nitrogen",
|
|
22
|
+
"nitro.json",
|
|
23
|
+
"*.podspec",
|
|
24
|
+
"react-native.config.js",
|
|
25
|
+
"!ios/build",
|
|
26
|
+
"!android/build",
|
|
27
|
+
"!android/gradle",
|
|
28
|
+
"!android/gradlew",
|
|
29
|
+
"!android/gradlew.bat",
|
|
30
|
+
"!android/local.properties",
|
|
31
|
+
"!**/__tests__",
|
|
32
|
+
"!**/__fixtures__",
|
|
33
|
+
"!**/__mocks__",
|
|
34
|
+
"!**/.*"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"example": "yarn workspace react-native-nitro-location-tracking-example",
|
|
38
|
+
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
|
|
39
|
+
"prepare": "bob build",
|
|
40
|
+
"nitrogen": "nitrogen",
|
|
41
|
+
"typecheck": "tsc",
|
|
42
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
43
|
+
"test": "jest",
|
|
44
|
+
"release": "release-it --only-version"
|
|
45
|
+
},
|
|
46
|
+
"keywords": [
|
|
47
|
+
"react-native",
|
|
48
|
+
"ios",
|
|
49
|
+
"android"
|
|
50
|
+
],
|
|
51
|
+
"repository": {
|
|
52
|
+
"type": "git",
|
|
53
|
+
"url": "git+https://github.com/alisherrahimov/react-native-nitro-location-tracking.git"
|
|
54
|
+
},
|
|
55
|
+
"author": "alisherrahimov <alisher.raximov97@gmail.com> (https://github.com/alisherrahimov)",
|
|
56
|
+
"license": "MIT",
|
|
57
|
+
"bugs": {
|
|
58
|
+
"url": "https://github.com/alisherrahimov/react-native-nitro-location-tracking/issues"
|
|
59
|
+
},
|
|
60
|
+
"homepage": "https://github.com/alisherrahimov/react-native-nitro-location-tracking#readme",
|
|
61
|
+
"publishConfig": {
|
|
62
|
+
"registry": "https://registry.npmjs.org/"
|
|
63
|
+
},
|
|
64
|
+
"devDependencies": {
|
|
65
|
+
"@commitlint/config-conventional": "^19.8.1",
|
|
66
|
+
"@eslint/compat": "^1.3.2",
|
|
67
|
+
"@eslint/eslintrc": "^3.3.1",
|
|
68
|
+
"@eslint/js": "^9.35.0",
|
|
69
|
+
"@react-native/babel-preset": "0.83.0",
|
|
70
|
+
"@react-native/eslint-config": "0.83.0",
|
|
71
|
+
"@release-it/conventional-changelog": "^10.0.1",
|
|
72
|
+
"@types/jest": "^29.5.14",
|
|
73
|
+
"@types/react": "^19.2.0",
|
|
74
|
+
"commitlint": "^19.8.1",
|
|
75
|
+
"del-cli": "^6.0.0",
|
|
76
|
+
"eslint": "^9.35.0",
|
|
77
|
+
"eslint-config-prettier": "^10.1.8",
|
|
78
|
+
"eslint-plugin-prettier": "^5.5.4",
|
|
79
|
+
"jest": "^29.7.0",
|
|
80
|
+
"lefthook": "^2.0.3",
|
|
81
|
+
"nitrogen": "^0.33.9",
|
|
82
|
+
"prettier": "^2.8.8",
|
|
83
|
+
"react": "19.2.0",
|
|
84
|
+
"react-native": "0.83.0",
|
|
85
|
+
"react-native-builder-bob": "^0.40.18",
|
|
86
|
+
"react-native-nitro-modules": "^0.33.9",
|
|
87
|
+
"release-it": "^19.0.4",
|
|
88
|
+
"turbo": "^2.5.6",
|
|
89
|
+
"typescript": "^5.9.2"
|
|
90
|
+
},
|
|
91
|
+
"peerDependencies": {
|
|
92
|
+
"react": "*",
|
|
93
|
+
"react-native": "*",
|
|
94
|
+
"react-native-nitro-modules": "^0.33.9"
|
|
95
|
+
},
|
|
96
|
+
"workspaces": [
|
|
97
|
+
"example"
|
|
98
|
+
],
|
|
99
|
+
"packageManager": "yarn@4.11.0",
|
|
100
|
+
"react-native-builder-bob": {
|
|
101
|
+
"source": "src",
|
|
102
|
+
"output": "lib",
|
|
103
|
+
"targets": [
|
|
104
|
+
[
|
|
105
|
+
"custom",
|
|
106
|
+
{
|
|
107
|
+
"script": "nitrogen",
|
|
108
|
+
"clean": "nitrogen/"
|
|
109
|
+
}
|
|
110
|
+
],
|
|
111
|
+
[
|
|
112
|
+
"module",
|
|
113
|
+
{
|
|
114
|
+
"esm": true
|
|
115
|
+
}
|
|
116
|
+
],
|
|
117
|
+
[
|
|
118
|
+
"typescript",
|
|
119
|
+
{
|
|
120
|
+
"project": "tsconfig.build.json"
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
]
|
|
124
|
+
},
|
|
125
|
+
"prettier": {
|
|
126
|
+
"quoteProps": "consistent",
|
|
127
|
+
"singleQuote": true,
|
|
128
|
+
"tabWidth": 2,
|
|
129
|
+
"trailingComma": "es5",
|
|
130
|
+
"useTabs": false
|
|
131
|
+
},
|
|
132
|
+
"jest": {
|
|
133
|
+
"preset": "react-native",
|
|
134
|
+
"modulePathIgnorePatterns": [
|
|
135
|
+
"<rootDir>/example/node_modules",
|
|
136
|
+
"<rootDir>/lib/"
|
|
137
|
+
]
|
|
138
|
+
},
|
|
139
|
+
"commitlint": {
|
|
140
|
+
"extends": [
|
|
141
|
+
"@commitlint/config-conventional"
|
|
142
|
+
]
|
|
143
|
+
},
|
|
144
|
+
"release-it": {
|
|
145
|
+
"git": {
|
|
146
|
+
"commitMessage": "chore: release ${version}",
|
|
147
|
+
"tagName": "v${version}"
|
|
148
|
+
},
|
|
149
|
+
"npm": {
|
|
150
|
+
"publish": true
|
|
151
|
+
},
|
|
152
|
+
"github": {
|
|
153
|
+
"release": true
|
|
154
|
+
},
|
|
155
|
+
"plugins": {
|
|
156
|
+
"@release-it/conventional-changelog": {
|
|
157
|
+
"preset": {
|
|
158
|
+
"name": "angular"
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
},
|
|
163
|
+
"create-react-native-library": {
|
|
164
|
+
"type": "nitro-module",
|
|
165
|
+
"languages": "kotlin-swift",
|
|
166
|
+
"tools": [
|
|
167
|
+
"eslint",
|
|
168
|
+
"jest",
|
|
169
|
+
"lefthook",
|
|
170
|
+
"release-it"
|
|
171
|
+
],
|
|
172
|
+
"version": "0.57.2"
|
|
173
|
+
}
|
|
174
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { LocationData } from './NitroLocationTracking.nitro';
|
|
2
|
+
|
|
3
|
+
const sleep = (ms: number) => new Promise<void>((r) => setTimeout(r, ms));
|
|
4
|
+
|
|
5
|
+
export interface MarkerRef {
|
|
6
|
+
animateMarkerToCoordinate(
|
|
7
|
+
coordinate: { latitude: number; longitude: number },
|
|
8
|
+
duration: number
|
|
9
|
+
): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export class LocationSmoother {
|
|
13
|
+
private queue: LocationData[] = [];
|
|
14
|
+
private isAnimating = false;
|
|
15
|
+
private markerRef: { current: MarkerRef | null };
|
|
16
|
+
|
|
17
|
+
constructor(markerRef: { current: MarkerRef | null }) {
|
|
18
|
+
this.markerRef = markerRef;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
feed(location: LocationData) {
|
|
22
|
+
this.queue.push(location);
|
|
23
|
+
if (this.queue.length > 10) this.queue = this.queue.slice(-3);
|
|
24
|
+
if (!this.isAnimating) this.drain();
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
private async drain() {
|
|
28
|
+
this.isAnimating = true;
|
|
29
|
+
while (this.queue.length > 0) {
|
|
30
|
+
const next = this.queue.shift()!;
|
|
31
|
+
const dur =
|
|
32
|
+
this.queue.length > 3 ? 500 : this.queue.length > 1 ? 1000 : 2000;
|
|
33
|
+
this.markerRef.current?.animateMarkerToCoordinate(
|
|
34
|
+
{ latitude: next.latitude, longitude: next.longitude },
|
|
35
|
+
dur
|
|
36
|
+
);
|
|
37
|
+
await sleep(dur * 0.9);
|
|
38
|
+
}
|
|
39
|
+
this.isAnimating = false;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
clear() {
|
|
43
|
+
this.queue = [];
|
|
44
|
+
this.isAnimating = false;
|
|
45
|
+
}
|
|
46
|
+
}
|