@gromozeqa/react-native-apple-health-kit 0.1.5 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -3
- package/{AppleHealthKit.podspec → ReactNativeAppleHealthKit.podspec} +1 -1
- package/android/generated/java/com/{applehealthkit/NativeAppleHealthKitSpec.java → gromozeqa/reactnativeapplehealthkit/NativeReactNativeAppleHealthKitSpec.java} +4 -4
- package/android/generated/jni/CMakeLists.txt +22 -9
- package/android/generated/jni/{RNAppleHealthKitSpec-generated.cpp → RNReactNativeAppleHealthKitSpec-generated.cpp} +13 -13
- package/android/generated/jni/{RNAppleHealthKitSpec.h → RNReactNativeAppleHealthKitSpec.h} +4 -4
- package/android/generated/jni/react/renderer/components/RNReactNativeAppleHealthKitSpec/RNReactNativeAppleHealthKitSpecJSI-generated.cpp +46 -0
- package/android/generated/jni/react/renderer/components/RNReactNativeAppleHealthKitSpec/RNReactNativeAppleHealthKitSpecJSI.h +299 -0
- package/ios/{AppleHealthKitManager.swift → HealthKitManager.swift} +8 -1
- package/ios/{AppleHealthKitPermissions.swift → HealthKitPermissions.swift} +8 -1
- package/ios/{AppleHealthKitQueries.swift → HealthKitQueries.swift} +8 -0
- package/ios/ReactNativeAppleHealthKit.h +6 -0
- package/ios/{AppleHealthKit.mm → ReactNativeAppleHealthKit.mm} +8 -8
- package/ios/{HealthKitUtils.swift → Utils.swift} +2 -2
- package/ios/generated/{RNAppleHealthKitSpec/RNAppleHealthKitSpec-generated.mm → RNReactNativeAppleHealthKitSpec/RNReactNativeAppleHealthKitSpec-generated.mm} +10 -20
- package/ios/generated/{RNAppleHealthKitSpec/RNAppleHealthKitSpec.h → RNReactNativeAppleHealthKitSpec/RNReactNativeAppleHealthKitSpec.h} +8 -21
- package/ios/generated/RNReactNativeAppleHealthKitSpecJSI-generated.cpp +46 -0
- package/ios/generated/RNReactNativeAppleHealthKitSpecJSI.h +299 -0
- package/lib/commonjs/{NativeAppleHealthKit.js → NativeReactNativeAppleHealthKit.js} +2 -2
- package/lib/commonjs/NativeReactNativeAppleHealthKit.js.map +1 -0
- package/lib/commonjs/index.js +16 -35
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/{NativeAppleHealthKit.js → NativeReactNativeAppleHealthKit.js} +2 -2
- package/lib/module/NativeReactNativeAppleHealthKit.js.map +1 -0
- package/lib/module/index.js +13 -14
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/commonjs/src/NativeReactNativeAppleHealthKit.d.ts +28 -0
- package/lib/typescript/commonjs/src/NativeReactNativeAppleHealthKit.d.ts.map +1 -0
- package/lib/typescript/commonjs/src/index.d.ts +5 -5
- package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
- package/lib/typescript/module/src/NativeReactNativeAppleHealthKit.d.ts +28 -0
- package/lib/typescript/module/src/NativeReactNativeAppleHealthKit.d.ts.map +1 -0
- package/lib/typescript/module/src/index.d.ts +5 -5
- package/lib/typescript/module/src/index.d.ts.map +1 -1
- package/package.json +14 -12
- package/react-native.config.js +3 -2
- package/src/{NativeAppleHealthKit.ts → NativeReactNativeAppleHealthKit.ts} +23 -2
- package/src/index.tsx +19 -14
- package/android/generated/jni/react/renderer/components/RNAppleHealthKitSpec/RNAppleHealthKitSpecJSI-generated.cpp +0 -46
- package/android/generated/jni/react/renderer/components/RNAppleHealthKitSpec/RNAppleHealthKitSpecJSI.h +0 -98
- package/ios/AppleHealthKit.h +0 -6
- package/ios/generated/RNAppleHealthKitSpecJSI-generated.cpp +0 -46
- package/ios/generated/RNAppleHealthKitSpecJSI.h +0 -98
- package/lib/commonjs/NativeAppleHealthKit.js.map +0 -1
- package/lib/commonjs/types.js +0 -2
- package/lib/commonjs/types.js.map +0 -1
- package/lib/module/NativeAppleHealthKit.js.map +0 -1
- package/lib/module/types.js +0 -2
- package/lib/module/types.js.map +0 -1
- package/lib/typescript/commonjs/src/NativeAppleHealthKit.d.ts +0 -11
- package/lib/typescript/commonjs/src/NativeAppleHealthKit.d.ts.map +0 -1
- package/lib/typescript/commonjs/src/types.d.ts +0 -19
- package/lib/typescript/commonjs/src/types.d.ts.map +0 -1
- package/lib/typescript/module/src/NativeAppleHealthKit.d.ts +0 -11
- package/lib/typescript/module/src/NativeAppleHealthKit.d.ts.map +0 -1
- package/lib/typescript/module/src/types.d.ts +0 -19
- package/lib/typescript/module/src/types.d.ts.map +0 -1
- package/src/types.ts +0 -21
package/README.md
CHANGED
@@ -1,11 +1,22 @@
|
|
1
|
-
# react-native-apple-health-kit
|
1
|
+
# @gromozeqa/react-native-apple-health-kit
|
2
2
|
|
3
|
-
IOS module for
|
3
|
+
IOS module for react native to enable health kit
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
7
|
```sh
|
8
|
-
npm install react-native-apple-health-kit
|
8
|
+
npm install @gromozeqa/react-native-apple-health-kit
|
9
|
+
```
|
10
|
+
|
11
|
+
## Usage
|
12
|
+
|
13
|
+
|
14
|
+
```js
|
15
|
+
import { multiply } from '@gromozeqa/react-native-apple-health-kit';
|
16
|
+
|
17
|
+
// ...
|
18
|
+
|
19
|
+
const result = multiply(3, 7);
|
9
20
|
```
|
10
21
|
|
11
22
|
|
@@ -4,7 +4,7 @@ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
4
|
folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
|
5
5
|
|
6
6
|
Pod::Spec.new do |s|
|
7
|
-
s.name = "
|
7
|
+
s.name = "ReactNativeAppleHealthKit"
|
8
8
|
s.version = package["version"]
|
9
9
|
s.summary = package["description"]
|
10
10
|
s.homepage = package["homepage"]
|
@@ -10,7 +10,7 @@
|
|
10
10
|
* @nolint
|
11
11
|
*/
|
12
12
|
|
13
|
-
package com.
|
13
|
+
package com.gromozeqa.reactnativeapplehealthkit;
|
14
14
|
|
15
15
|
import com.facebook.proguard.annotations.DoNotStrip;
|
16
16
|
import com.facebook.react.bridge.Promise;
|
@@ -20,10 +20,10 @@ import com.facebook.react.bridge.ReactMethod;
|
|
20
20
|
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
|
21
21
|
import javax.annotation.Nonnull;
|
22
22
|
|
23
|
-
public abstract class
|
24
|
-
public static final String NAME = "
|
23
|
+
public abstract class NativeReactNativeAppleHealthKitSpec extends ReactContextBaseJavaModule implements TurboModule {
|
24
|
+
public static final String NAME = "ReactNativeAppleHealthKit";
|
25
25
|
|
26
|
-
public
|
26
|
+
public NativeReactNativeAppleHealthKitSpec(ReactApplicationContext reactContext) {
|
27
27
|
super(reactContext);
|
28
28
|
}
|
29
29
|
|
@@ -6,27 +6,40 @@
|
|
6
6
|
cmake_minimum_required(VERSION 3.13)
|
7
7
|
set(CMAKE_VERBOSE_MAKEFILE on)
|
8
8
|
|
9
|
-
file(GLOB react_codegen_SRCS CONFIGURE_DEPENDS *.cpp react/renderer/components/
|
9
|
+
file(GLOB react_codegen_SRCS CONFIGURE_DEPENDS *.cpp react/renderer/components/RNReactNativeAppleHealthKitSpec/*.cpp)
|
10
10
|
|
11
11
|
add_library(
|
12
|
-
|
13
|
-
|
12
|
+
react_codegen_RNReactNativeAppleHealthKitSpec
|
13
|
+
SHARED
|
14
14
|
${react_codegen_SRCS}
|
15
15
|
)
|
16
16
|
|
17
|
-
target_include_directories(
|
17
|
+
target_include_directories(react_codegen_RNReactNativeAppleHealthKitSpec PUBLIC . react/renderer/components/RNReactNativeAppleHealthKitSpec)
|
18
18
|
|
19
19
|
target_link_libraries(
|
20
|
-
|
20
|
+
react_codegen_RNReactNativeAppleHealthKitSpec
|
21
21
|
fbjni
|
22
|
+
folly_runtime
|
23
|
+
glog
|
22
24
|
jsi
|
23
|
-
|
24
|
-
|
25
|
-
|
25
|
+
react_codegen_rncore
|
26
|
+
react_debug
|
27
|
+
react_nativemodule_core
|
28
|
+
react_render_componentregistry
|
29
|
+
react_render_core
|
30
|
+
react_render_debug
|
31
|
+
react_render_graphics
|
32
|
+
react_render_imagemanager
|
33
|
+
react_render_mapbuffer
|
34
|
+
react_utils
|
35
|
+
rrc_image
|
36
|
+
rrc_view
|
37
|
+
turbomodulejsijni
|
38
|
+
yoga
|
26
39
|
)
|
27
40
|
|
28
41
|
target_compile_options(
|
29
|
-
|
42
|
+
react_codegen_RNReactNativeAppleHealthKitSpec
|
30
43
|
PRIVATE
|
31
44
|
-DLOG_TAG=\"ReactNative\"
|
32
45
|
-fexceptions
|
@@ -8,41 +8,41 @@
|
|
8
8
|
* @generated by codegen project: GenerateModuleJniCpp.js
|
9
9
|
*/
|
10
10
|
|
11
|
-
#include "
|
11
|
+
#include "RNReactNativeAppleHealthKitSpec.h"
|
12
12
|
|
13
13
|
namespace facebook::react {
|
14
14
|
|
15
|
-
static facebook::jsi::Value
|
15
|
+
static facebook::jsi::Value __hostFunction_NativeReactNativeAppleHealthKitSpecJSI_requestHealthKitPermissions(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
16
16
|
static jmethodID cachedMethodId = nullptr;
|
17
17
|
return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, PromiseKind, "requestHealthKitPermissions", "(Lcom/facebook/react/bridge/Promise;)V", args, count, cachedMethodId);
|
18
18
|
}
|
19
19
|
|
20
|
-
static facebook::jsi::Value
|
20
|
+
static facebook::jsi::Value __hostFunction_NativeReactNativeAppleHealthKitSpecJSI_getSteps(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
21
21
|
static jmethodID cachedMethodId = nullptr;
|
22
22
|
return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, PromiseKind, "getSteps", "(DLcom/facebook/react/bridge/Promise;)V", args, count, cachedMethodId);
|
23
23
|
}
|
24
24
|
|
25
|
-
static facebook::jsi::Value
|
25
|
+
static facebook::jsi::Value __hostFunction_NativeReactNativeAppleHealthKitSpecJSI_getHeartRate(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
26
26
|
static jmethodID cachedMethodId = nullptr;
|
27
27
|
return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, PromiseKind, "getHeartRate", "(DLcom/facebook/react/bridge/Promise;)V", args, count, cachedMethodId);
|
28
28
|
}
|
29
29
|
|
30
|
-
static facebook::jsi::Value
|
30
|
+
static facebook::jsi::Value __hostFunction_NativeReactNativeAppleHealthKitSpecJSI_getMeasurement(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
|
31
31
|
static jmethodID cachedMethodId = nullptr;
|
32
32
|
return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, PromiseKind, "getMeasurement", "(Lcom/facebook/react/bridge/Promise;)V", args, count, cachedMethodId);
|
33
33
|
}
|
34
34
|
|
35
|
-
|
35
|
+
NativeReactNativeAppleHealthKitSpecJSI::NativeReactNativeAppleHealthKitSpecJSI(const JavaTurboModule::InitParams ¶ms)
|
36
36
|
: JavaTurboModule(params) {
|
37
|
-
methodMap_["requestHealthKitPermissions"] = MethodMetadata {0,
|
38
|
-
methodMap_["getSteps"] = MethodMetadata {1,
|
39
|
-
methodMap_["getHeartRate"] = MethodMetadata {1,
|
40
|
-
methodMap_["getMeasurement"] = MethodMetadata {0,
|
37
|
+
methodMap_["requestHealthKitPermissions"] = MethodMetadata {0, __hostFunction_NativeReactNativeAppleHealthKitSpecJSI_requestHealthKitPermissions};
|
38
|
+
methodMap_["getSteps"] = MethodMetadata {1, __hostFunction_NativeReactNativeAppleHealthKitSpecJSI_getSteps};
|
39
|
+
methodMap_["getHeartRate"] = MethodMetadata {1, __hostFunction_NativeReactNativeAppleHealthKitSpecJSI_getHeartRate};
|
40
|
+
methodMap_["getMeasurement"] = MethodMetadata {0, __hostFunction_NativeReactNativeAppleHealthKitSpecJSI_getMeasurement};
|
41
41
|
}
|
42
42
|
|
43
|
-
std::shared_ptr<TurboModule>
|
44
|
-
if (moduleName == "
|
45
|
-
return std::make_shared<
|
43
|
+
std::shared_ptr<TurboModule> RNReactNativeAppleHealthKitSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms) {
|
44
|
+
if (moduleName == "ReactNativeAppleHealthKit") {
|
45
|
+
return std::make_shared<NativeReactNativeAppleHealthKitSpecJSI>(params);
|
46
46
|
}
|
47
47
|
return nullptr;
|
48
48
|
}
|
@@ -17,15 +17,15 @@
|
|
17
17
|
namespace facebook::react {
|
18
18
|
|
19
19
|
/**
|
20
|
-
* JNI C++ class for module '
|
20
|
+
* JNI C++ class for module 'NativeReactNativeAppleHealthKit'
|
21
21
|
*/
|
22
|
-
class JSI_EXPORT
|
22
|
+
class JSI_EXPORT NativeReactNativeAppleHealthKitSpecJSI : public JavaTurboModule {
|
23
23
|
public:
|
24
|
-
|
24
|
+
NativeReactNativeAppleHealthKitSpecJSI(const JavaTurboModule::InitParams ¶ms);
|
25
25
|
};
|
26
26
|
|
27
27
|
|
28
28
|
JSI_EXPORT
|
29
|
-
std::shared_ptr<TurboModule>
|
29
|
+
std::shared_ptr<TurboModule> RNReactNativeAppleHealthKitSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams ¶ms);
|
30
30
|
|
31
31
|
} // namespace facebook::react
|
@@ -0,0 +1,46 @@
|
|
1
|
+
/**
|
2
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
3
|
+
*
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
5
|
+
* once the code is regenerated.
|
6
|
+
*
|
7
|
+
* @generated by codegen project: GenerateModuleCpp.js
|
8
|
+
*/
|
9
|
+
|
10
|
+
#include "RNReactNativeAppleHealthKitSpecJSI.h"
|
11
|
+
|
12
|
+
namespace facebook::react {
|
13
|
+
|
14
|
+
static jsi::Value __hostFunction_NativeReactNativeAppleHealthKitCxxSpecJSI_requestHealthKitPermissions(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
15
|
+
return static_cast<NativeReactNativeAppleHealthKitCxxSpecJSI *>(&turboModule)->requestHealthKitPermissions(
|
16
|
+
rt
|
17
|
+
);
|
18
|
+
}
|
19
|
+
static jsi::Value __hostFunction_NativeReactNativeAppleHealthKitCxxSpecJSI_getSteps(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
20
|
+
return static_cast<NativeReactNativeAppleHealthKitCxxSpecJSI *>(&turboModule)->getSteps(
|
21
|
+
rt,
|
22
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asNumber()
|
23
|
+
);
|
24
|
+
}
|
25
|
+
static jsi::Value __hostFunction_NativeReactNativeAppleHealthKitCxxSpecJSI_getHeartRate(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
26
|
+
return static_cast<NativeReactNativeAppleHealthKitCxxSpecJSI *>(&turboModule)->getHeartRate(
|
27
|
+
rt,
|
28
|
+
count <= 0 ? throw jsi::JSError(rt, "Expected argument in position 0 to be passed") : args[0].asNumber()
|
29
|
+
);
|
30
|
+
}
|
31
|
+
static jsi::Value __hostFunction_NativeReactNativeAppleHealthKitCxxSpecJSI_getMeasurement(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
|
32
|
+
return static_cast<NativeReactNativeAppleHealthKitCxxSpecJSI *>(&turboModule)->getMeasurement(
|
33
|
+
rt
|
34
|
+
);
|
35
|
+
}
|
36
|
+
|
37
|
+
NativeReactNativeAppleHealthKitCxxSpecJSI::NativeReactNativeAppleHealthKitCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
|
38
|
+
: TurboModule("ReactNativeAppleHealthKit", jsInvoker) {
|
39
|
+
methodMap_["requestHealthKitPermissions"] = MethodMetadata {0, __hostFunction_NativeReactNativeAppleHealthKitCxxSpecJSI_requestHealthKitPermissions};
|
40
|
+
methodMap_["getSteps"] = MethodMetadata {1, __hostFunction_NativeReactNativeAppleHealthKitCxxSpecJSI_getSteps};
|
41
|
+
methodMap_["getHeartRate"] = MethodMetadata {1, __hostFunction_NativeReactNativeAppleHealthKitCxxSpecJSI_getHeartRate};
|
42
|
+
methodMap_["getMeasurement"] = MethodMetadata {0, __hostFunction_NativeReactNativeAppleHealthKitCxxSpecJSI_getMeasurement};
|
43
|
+
}
|
44
|
+
|
45
|
+
|
46
|
+
} // namespace facebook::react
|
@@ -0,0 +1,299 @@
|
|
1
|
+
/**
|
2
|
+
* This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
|
3
|
+
*
|
4
|
+
* Do not edit this file as changes may cause incorrect behavior and will be lost
|
5
|
+
* once the code is regenerated.
|
6
|
+
*
|
7
|
+
* @generated by codegen project: GenerateModuleH.js
|
8
|
+
*/
|
9
|
+
|
10
|
+
#pragma once
|
11
|
+
|
12
|
+
#include <ReactCommon/TurboModule.h>
|
13
|
+
#include <react/bridging/Bridging.h>
|
14
|
+
|
15
|
+
namespace facebook::react {
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
#pragma mark - NativeReactNativeAppleHealthKitHeartRate
|
20
|
+
|
21
|
+
template <typename P0, typename P1>
|
22
|
+
struct NativeReactNativeAppleHealthKitHeartRate {
|
23
|
+
P0 date;
|
24
|
+
P1 value;
|
25
|
+
bool operator==(const NativeReactNativeAppleHealthKitHeartRate &other) const {
|
26
|
+
return date == other.date && value == other.value;
|
27
|
+
}
|
28
|
+
};
|
29
|
+
|
30
|
+
template <typename T>
|
31
|
+
struct NativeReactNativeAppleHealthKitHeartRateBridging {
|
32
|
+
static T types;
|
33
|
+
|
34
|
+
static T fromJs(
|
35
|
+
jsi::Runtime &rt,
|
36
|
+
const jsi::Object &value,
|
37
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
38
|
+
T result{
|
39
|
+
bridging::fromJs<decltype(types.date)>(rt, value.getProperty(rt, "date"), jsInvoker),
|
40
|
+
bridging::fromJs<decltype(types.value)>(rt, value.getProperty(rt, "value"), jsInvoker)};
|
41
|
+
return result;
|
42
|
+
}
|
43
|
+
|
44
|
+
#ifdef DEBUG
|
45
|
+
static jsi::String dateToJs(jsi::Runtime &rt, decltype(types.date) value) {
|
46
|
+
return bridging::toJs(rt, value);
|
47
|
+
}
|
48
|
+
|
49
|
+
static jsi::Array valueToJs(jsi::Runtime &rt, decltype(types.value) value) {
|
50
|
+
return bridging::toJs(rt, value);
|
51
|
+
}
|
52
|
+
#endif
|
53
|
+
|
54
|
+
static jsi::Object toJs(
|
55
|
+
jsi::Runtime &rt,
|
56
|
+
const T &value,
|
57
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
58
|
+
auto result = facebook::jsi::Object(rt);
|
59
|
+
result.setProperty(rt, "date", bridging::toJs(rt, value.date, jsInvoker));
|
60
|
+
result.setProperty(rt, "value", bridging::toJs(rt, value.value, jsInvoker));
|
61
|
+
return result;
|
62
|
+
}
|
63
|
+
};
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
#pragma mark - NativeReactNativeAppleHealthKitHeartRateValue
|
68
|
+
|
69
|
+
template <typename P0, typename P1>
|
70
|
+
struct NativeReactNativeAppleHealthKitHeartRateValue {
|
71
|
+
P0 time;
|
72
|
+
P1 heartRate;
|
73
|
+
bool operator==(const NativeReactNativeAppleHealthKitHeartRateValue &other) const {
|
74
|
+
return time == other.time && heartRate == other.heartRate;
|
75
|
+
}
|
76
|
+
};
|
77
|
+
|
78
|
+
template <typename T>
|
79
|
+
struct NativeReactNativeAppleHealthKitHeartRateValueBridging {
|
80
|
+
static T types;
|
81
|
+
|
82
|
+
static T fromJs(
|
83
|
+
jsi::Runtime &rt,
|
84
|
+
const jsi::Object &value,
|
85
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
86
|
+
T result{
|
87
|
+
bridging::fromJs<decltype(types.time)>(rt, value.getProperty(rt, "time"), jsInvoker),
|
88
|
+
bridging::fromJs<decltype(types.heartRate)>(rt, value.getProperty(rt, "heartRate"), jsInvoker)};
|
89
|
+
return result;
|
90
|
+
}
|
91
|
+
|
92
|
+
#ifdef DEBUG
|
93
|
+
static jsi::String timeToJs(jsi::Runtime &rt, decltype(types.time) value) {
|
94
|
+
return bridging::toJs(rt, value);
|
95
|
+
}
|
96
|
+
|
97
|
+
static double heartRateToJs(jsi::Runtime &rt, decltype(types.heartRate) value) {
|
98
|
+
return bridging::toJs(rt, value);
|
99
|
+
}
|
100
|
+
#endif
|
101
|
+
|
102
|
+
static jsi::Object toJs(
|
103
|
+
jsi::Runtime &rt,
|
104
|
+
const T &value,
|
105
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
106
|
+
auto result = facebook::jsi::Object(rt);
|
107
|
+
result.setProperty(rt, "time", bridging::toJs(rt, value.time, jsInvoker));
|
108
|
+
result.setProperty(rt, "heartRate", bridging::toJs(rt, value.heartRate, jsInvoker));
|
109
|
+
return result;
|
110
|
+
}
|
111
|
+
};
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
#pragma mark - NativeReactNativeAppleHealthKitMeasurement
|
116
|
+
|
117
|
+
template <typename P0, typename P1, typename P2, typename P3>
|
118
|
+
struct NativeReactNativeAppleHealthKitMeasurement {
|
119
|
+
P0 bodyMass;
|
120
|
+
P1 height;
|
121
|
+
P2 biologicalSex;
|
122
|
+
P3 dateOfBirth;
|
123
|
+
bool operator==(const NativeReactNativeAppleHealthKitMeasurement &other) const {
|
124
|
+
return bodyMass == other.bodyMass && height == other.height && biologicalSex == other.biologicalSex && dateOfBirth == other.dateOfBirth;
|
125
|
+
}
|
126
|
+
};
|
127
|
+
|
128
|
+
template <typename T>
|
129
|
+
struct NativeReactNativeAppleHealthKitMeasurementBridging {
|
130
|
+
static T types;
|
131
|
+
|
132
|
+
static T fromJs(
|
133
|
+
jsi::Runtime &rt,
|
134
|
+
const jsi::Object &value,
|
135
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
136
|
+
T result{
|
137
|
+
bridging::fromJs<decltype(types.bodyMass)>(rt, value.getProperty(rt, "bodyMass"), jsInvoker),
|
138
|
+
bridging::fromJs<decltype(types.height)>(rt, value.getProperty(rt, "height"), jsInvoker),
|
139
|
+
bridging::fromJs<decltype(types.biologicalSex)>(rt, value.getProperty(rt, "biologicalSex"), jsInvoker),
|
140
|
+
bridging::fromJs<decltype(types.dateOfBirth)>(rt, value.getProperty(rt, "dateOfBirth"), jsInvoker)};
|
141
|
+
return result;
|
142
|
+
}
|
143
|
+
|
144
|
+
#ifdef DEBUG
|
145
|
+
static std::optional<double> bodyMassToJs(jsi::Runtime &rt, decltype(types.bodyMass) value) {
|
146
|
+
return bridging::toJs(rt, value);
|
147
|
+
}
|
148
|
+
|
149
|
+
static std::optional<double> heightToJs(jsi::Runtime &rt, decltype(types.height) value) {
|
150
|
+
return bridging::toJs(rt, value);
|
151
|
+
}
|
152
|
+
|
153
|
+
static std::optional<jsi::String> biologicalSexToJs(jsi::Runtime &rt, decltype(types.biologicalSex) value) {
|
154
|
+
return bridging::toJs(rt, value);
|
155
|
+
}
|
156
|
+
|
157
|
+
static std::optional<jsi::String> dateOfBirthToJs(jsi::Runtime &rt, decltype(types.dateOfBirth) value) {
|
158
|
+
return bridging::toJs(rt, value);
|
159
|
+
}
|
160
|
+
#endif
|
161
|
+
|
162
|
+
static jsi::Object toJs(
|
163
|
+
jsi::Runtime &rt,
|
164
|
+
const T &value,
|
165
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
166
|
+
auto result = facebook::jsi::Object(rt);
|
167
|
+
result.setProperty(rt, "bodyMass", bridging::toJs(rt, value.bodyMass, jsInvoker));
|
168
|
+
result.setProperty(rt, "height", bridging::toJs(rt, value.height, jsInvoker));
|
169
|
+
result.setProperty(rt, "biologicalSex", bridging::toJs(rt, value.biologicalSex, jsInvoker));
|
170
|
+
result.setProperty(rt, "dateOfBirth", bridging::toJs(rt, value.dateOfBirth, jsInvoker));
|
171
|
+
return result;
|
172
|
+
}
|
173
|
+
};
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
#pragma mark - NativeReactNativeAppleHealthKitStep
|
178
|
+
|
179
|
+
template <typename P0, typename P1>
|
180
|
+
struct NativeReactNativeAppleHealthKitStep {
|
181
|
+
P0 dateString;
|
182
|
+
P1 stepCount;
|
183
|
+
bool operator==(const NativeReactNativeAppleHealthKitStep &other) const {
|
184
|
+
return dateString == other.dateString && stepCount == other.stepCount;
|
185
|
+
}
|
186
|
+
};
|
187
|
+
|
188
|
+
template <typename T>
|
189
|
+
struct NativeReactNativeAppleHealthKitStepBridging {
|
190
|
+
static T types;
|
191
|
+
|
192
|
+
static T fromJs(
|
193
|
+
jsi::Runtime &rt,
|
194
|
+
const jsi::Object &value,
|
195
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
196
|
+
T result{
|
197
|
+
bridging::fromJs<decltype(types.dateString)>(rt, value.getProperty(rt, "dateString"), jsInvoker),
|
198
|
+
bridging::fromJs<decltype(types.stepCount)>(rt, value.getProperty(rt, "stepCount"), jsInvoker)};
|
199
|
+
return result;
|
200
|
+
}
|
201
|
+
|
202
|
+
#ifdef DEBUG
|
203
|
+
static jsi::String dateStringToJs(jsi::Runtime &rt, decltype(types.dateString) value) {
|
204
|
+
return bridging::toJs(rt, value);
|
205
|
+
}
|
206
|
+
|
207
|
+
static double stepCountToJs(jsi::Runtime &rt, decltype(types.stepCount) value) {
|
208
|
+
return bridging::toJs(rt, value);
|
209
|
+
}
|
210
|
+
#endif
|
211
|
+
|
212
|
+
static jsi::Object toJs(
|
213
|
+
jsi::Runtime &rt,
|
214
|
+
const T &value,
|
215
|
+
const std::shared_ptr<CallInvoker> &jsInvoker) {
|
216
|
+
auto result = facebook::jsi::Object(rt);
|
217
|
+
result.setProperty(rt, "dateString", bridging::toJs(rt, value.dateString, jsInvoker));
|
218
|
+
result.setProperty(rt, "stepCount", bridging::toJs(rt, value.stepCount, jsInvoker));
|
219
|
+
return result;
|
220
|
+
}
|
221
|
+
};
|
222
|
+
|
223
|
+
class JSI_EXPORT NativeReactNativeAppleHealthKitCxxSpecJSI : public TurboModule {
|
224
|
+
protected:
|
225
|
+
NativeReactNativeAppleHealthKitCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
|
226
|
+
|
227
|
+
public:
|
228
|
+
virtual jsi::Value requestHealthKitPermissions(jsi::Runtime &rt) = 0;
|
229
|
+
virtual jsi::Value getSteps(jsi::Runtime &rt, double daysBefore) = 0;
|
230
|
+
virtual jsi::Value getHeartRate(jsi::Runtime &rt, double daysBefore) = 0;
|
231
|
+
virtual jsi::Value getMeasurement(jsi::Runtime &rt) = 0;
|
232
|
+
|
233
|
+
};
|
234
|
+
|
235
|
+
template <typename T>
|
236
|
+
class JSI_EXPORT NativeReactNativeAppleHealthKitCxxSpec : public TurboModule {
|
237
|
+
public:
|
238
|
+
jsi::Value get(jsi::Runtime &rt, const jsi::PropNameID &propName) override {
|
239
|
+
return delegate_.get(rt, propName);
|
240
|
+
}
|
241
|
+
|
242
|
+
static constexpr std::string_view kModuleName = "ReactNativeAppleHealthKit";
|
243
|
+
|
244
|
+
protected:
|
245
|
+
NativeReactNativeAppleHealthKitCxxSpec(std::shared_ptr<CallInvoker> jsInvoker)
|
246
|
+
: TurboModule(std::string{NativeReactNativeAppleHealthKitCxxSpec::kModuleName}, jsInvoker),
|
247
|
+
delegate_(reinterpret_cast<T*>(this), jsInvoker) {}
|
248
|
+
|
249
|
+
|
250
|
+
private:
|
251
|
+
class Delegate : public NativeReactNativeAppleHealthKitCxxSpecJSI {
|
252
|
+
public:
|
253
|
+
Delegate(T *instance, std::shared_ptr<CallInvoker> jsInvoker) :
|
254
|
+
NativeReactNativeAppleHealthKitCxxSpecJSI(std::move(jsInvoker)), instance_(instance) {
|
255
|
+
|
256
|
+
}
|
257
|
+
|
258
|
+
jsi::Value requestHealthKitPermissions(jsi::Runtime &rt) override {
|
259
|
+
static_assert(
|
260
|
+
bridging::getParameterCount(&T::requestHealthKitPermissions) == 1,
|
261
|
+
"Expected requestHealthKitPermissions(...) to have 1 parameters");
|
262
|
+
|
263
|
+
return bridging::callFromJs<jsi::Value>(
|
264
|
+
rt, &T::requestHealthKitPermissions, jsInvoker_, instance_);
|
265
|
+
}
|
266
|
+
jsi::Value getSteps(jsi::Runtime &rt, double daysBefore) override {
|
267
|
+
static_assert(
|
268
|
+
bridging::getParameterCount(&T::getSteps) == 2,
|
269
|
+
"Expected getSteps(...) to have 2 parameters");
|
270
|
+
|
271
|
+
return bridging::callFromJs<jsi::Value>(
|
272
|
+
rt, &T::getSteps, jsInvoker_, instance_, std::move(daysBefore));
|
273
|
+
}
|
274
|
+
jsi::Value getHeartRate(jsi::Runtime &rt, double daysBefore) override {
|
275
|
+
static_assert(
|
276
|
+
bridging::getParameterCount(&T::getHeartRate) == 2,
|
277
|
+
"Expected getHeartRate(...) to have 2 parameters");
|
278
|
+
|
279
|
+
return bridging::callFromJs<jsi::Value>(
|
280
|
+
rt, &T::getHeartRate, jsInvoker_, instance_, std::move(daysBefore));
|
281
|
+
}
|
282
|
+
jsi::Value getMeasurement(jsi::Runtime &rt) override {
|
283
|
+
static_assert(
|
284
|
+
bridging::getParameterCount(&T::getMeasurement) == 1,
|
285
|
+
"Expected getMeasurement(...) to have 1 parameters");
|
286
|
+
|
287
|
+
return bridging::callFromJs<jsi::Value>(
|
288
|
+
rt, &T::getMeasurement, jsInvoker_, instance_);
|
289
|
+
}
|
290
|
+
|
291
|
+
private:
|
292
|
+
friend class NativeReactNativeAppleHealthKitCxxSpec;
|
293
|
+
T *instance_;
|
294
|
+
};
|
295
|
+
|
296
|
+
Delegate delegate_;
|
297
|
+
};
|
298
|
+
|
299
|
+
} // namespace facebook::react
|
@@ -1,7 +1,14 @@
|
|
1
|
+
//
|
2
|
+
// HealthKitManager.swift
|
3
|
+
// ReactNativeAppleHealthKit
|
4
|
+
//
|
5
|
+
// Created by Andrei on 24.02.2025.
|
6
|
+
//
|
7
|
+
|
1
8
|
import Foundation
|
2
9
|
import HealthKit
|
3
10
|
|
4
|
-
@objc public class
|
11
|
+
@objc public class HealthKitManager: NSObject {
|
5
12
|
|
6
13
|
private let healthStore = HKHealthStore()
|
7
14
|
private let permissions = HealthKitPermissions()
|
@@ -1,6 +1,13 @@
|
|
1
|
+
//
|
2
|
+
// HealthKitPermissions.swift
|
3
|
+
// ReactNativeAppleHealthKit
|
4
|
+
//
|
5
|
+
// Created by Andrei on 24.02.2025.
|
6
|
+
//
|
7
|
+
|
1
8
|
import HealthKit
|
2
9
|
|
3
|
-
class HealthKitPermissions {
|
10
|
+
class HealthKitPermissions {
|
4
11
|
let healthStore = HKHealthStore()
|
5
12
|
|
6
13
|
func requestPermissions(completion: @escaping (Bool, Error?) -> Void) {
|
@@ -1,14 +1,14 @@
|
|
1
|
-
#import "
|
2
|
-
#import "
|
1
|
+
#import "ReactNativeAppleHealthKit.h"
|
2
|
+
#import "ReactNativeAppleHealthKit-Swift.h"
|
3
3
|
|
4
|
-
@implementation
|
5
|
-
|
4
|
+
@implementation ReactNativeAppleHealthKit {
|
5
|
+
HealthKitManager *moduleImpl;
|
6
6
|
}
|
7
7
|
|
8
8
|
- (instancetype)init {
|
9
9
|
self = [super init];
|
10
10
|
if (self) {
|
11
|
-
moduleImpl = [[
|
11
|
+
moduleImpl = [[HealthKitManager alloc] init];
|
12
12
|
}
|
13
13
|
return self;
|
14
14
|
}
|
@@ -18,7 +18,7 @@ RCT_EXPORT_MODULE()
|
|
18
18
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
19
19
|
(const facebook::react::ObjCTurboModule::InitParams &)params
|
20
20
|
{
|
21
|
-
return std::make_shared<facebook::react::
|
21
|
+
return std::make_shared<facebook::react::NativeReactNativeAppleHealthKitSpecJSI>(params);
|
22
22
|
}
|
23
23
|
|
24
24
|
RCT_EXPORT_METHOD(requestHealthKitPermissions:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
|
@@ -41,7 +41,7 @@ RCT_EXPORT_METHOD(getSteps:(double)daysBefore resolve:(RCTPromiseResolveBlock)re
|
|
41
41
|
}];
|
42
42
|
}
|
43
43
|
|
44
|
-
- (void)getHeartRate:(double)daysBefore resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
44
|
+
- (void)getHeartRate:(double)daysBefore resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
45
45
|
[moduleImpl getHeartRateWithDaysBefore:@(daysBefore) completion:^(NSArray * _Nullable steps, NSError * _Nullable error) {
|
46
46
|
if (error) {
|
47
47
|
reject(@"heart_rate_error", error.localizedDescription, error);
|
@@ -52,7 +52,7 @@ RCT_EXPORT_METHOD(getSteps:(double)daysBefore resolve:(RCTPromiseResolveBlock)re
|
|
52
52
|
}
|
53
53
|
|
54
54
|
|
55
|
-
- (void)getMeasurement:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
55
|
+
- (void)getMeasurement:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
|
56
56
|
[moduleImpl getMeasurementsWithCompletion:^(NSDictionary<NSString *, id> * _Nullable data) {
|
57
57
|
resolve(data);
|
58
58
|
}];
|