@gromozeqa/react-native-apple-health-kit 0.1.3

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 (41) hide show
  1. package/AppleHealthKit.podspec +42 -0
  2. package/LICENSE +20 -0
  3. package/README.md +22 -0
  4. package/android/generated/java/com/applehealthkit/NativeAppleHealthKitSpec.java +50 -0
  5. package/android/generated/jni/CMakeLists.txt +36 -0
  6. package/android/generated/jni/RNAppleHealthKitSpec-generated.cpp +50 -0
  7. package/android/generated/jni/RNAppleHealthKitSpec.h +31 -0
  8. package/android/generated/jni/react/renderer/components/RNAppleHealthKitSpec/RNAppleHealthKitSpecJSI-generated.cpp +46 -0
  9. package/android/generated/jni/react/renderer/components/RNAppleHealthKitSpec/RNAppleHealthKitSpecJSI.h +255 -0
  10. package/ios/AppleHealthKit.h +6 -0
  11. package/ios/AppleHealthKit.mm +61 -0
  12. package/ios/AppleHealthKitManager.swift +48 -0
  13. package/ios/AppleHealthKitPermissions.swift +26 -0
  14. package/ios/AppleHealthKitQueries.swift +200 -0
  15. package/ios/HealthKitUtils.swift +61 -0
  16. package/ios/generated/RNAppleHealthKitSpec/RNAppleHealthKitSpec-generated.mm +60 -0
  17. package/ios/generated/RNAppleHealthKitSpec/RNAppleHealthKitSpec.h +71 -0
  18. package/ios/generated/RNAppleHealthKitSpecJSI-generated.cpp +46 -0
  19. package/ios/generated/RNAppleHealthKitSpecJSI.h +255 -0
  20. package/lib/commonjs/NativeAppleHealthKit.js +23 -0
  21. package/lib/commonjs/NativeAppleHealthKit.js.map +1 -0
  22. package/lib/commonjs/index.js +19 -0
  23. package/lib/commonjs/index.js.map +1 -0
  24. package/lib/module/NativeAppleHealthKit.js +19 -0
  25. package/lib/module/NativeAppleHealthKit.js.map +1 -0
  26. package/lib/module/index.js +10 -0
  27. package/lib/module/index.js.map +1 -0
  28. package/lib/typescript/commonjs/package.json +1 -0
  29. package/lib/typescript/commonjs/src/NativeAppleHealthKit.d.ts +27 -0
  30. package/lib/typescript/commonjs/src/NativeAppleHealthKit.d.ts.map +1 -0
  31. package/lib/typescript/commonjs/src/index.d.ts +2 -0
  32. package/lib/typescript/commonjs/src/index.d.ts.map +1 -0
  33. package/lib/typescript/module/package.json +1 -0
  34. package/lib/typescript/module/src/NativeAppleHealthKit.d.ts +27 -0
  35. package/lib/typescript/module/src/NativeAppleHealthKit.d.ts.map +1 -0
  36. package/lib/typescript/module/src/index.d.ts +2 -0
  37. package/lib/typescript/module/src/index.d.ts.map +1 -0
  38. package/package.json +203 -0
  39. package/react-native.config.js +11 -0
  40. package/src/NativeAppleHealthKit.ts +48 -0
  41. package/src/index.tsx +8 -0
@@ -0,0 +1,42 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1 -Wno-comma -Wno-shorten-64-to-32'
5
+
6
+ Pod::Spec.new do |s|
7
+ s.name = "AppleHealthKit"
8
+ s.version = package["version"]
9
+ s.summary = package["description"]
10
+ s.homepage = package["homepage"]
11
+ s.license = package["license"]
12
+ s.authors = package["author"]
13
+
14
+ s.platforms = { :ios => min_ios_version_supported }
15
+ s.source = { :git => "https://github.com/Luxlorys/react-native-apple-health-kit.git", :tag => "#{s.version}" }
16
+
17
+ s.source_files = "ios/**/*.{h,m,mm,cpp,swift}"
18
+ s.private_header_files = "ios/**/*.h"
19
+
20
+ # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
21
+ # See https://github.com/facebook/react-native/blob/febf6b7f33fdb4904669f99d795eba4c0f95d7bf/scripts/cocoapods/new_architecture.rb#L79.
22
+ if respond_to?(:install_modules_dependencies, true)
23
+ install_modules_dependencies(s)
24
+ else
25
+ s.dependency "React-Core"
26
+
27
+ # Don't install the dependencies when we run `pod install` in the old architecture.
28
+ if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
29
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
30
+ s.pod_target_xcconfig = {
31
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
32
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
33
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17"
34
+ }
35
+ s.dependency "React-Codegen"
36
+ s.dependency "RCT-Folly"
37
+ s.dependency "RCTRequired"
38
+ s.dependency "RCTTypeSafety"
39
+ s.dependency "ReactCommon/turbomodule/core"
40
+ end
41
+ end
42
+ end
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 gromozeqa
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,22 @@
1
+ # react-native-apple-health-kit
2
+
3
+ IOS module for Apple Healhkit
4
+
5
+ ## Installation
6
+
7
+ ```sh
8
+ npm install react-native-apple-health-kit
9
+ ```
10
+
11
+
12
+ ## Contributing
13
+
14
+ See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
15
+
16
+ ## License
17
+
18
+ MIT
19
+
20
+ ---
21
+
22
+ Made with [create-react-native-library](https://github.com/callstack/react-native-builder-bob)
@@ -0,0 +1,50 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateModuleJavaSpec.js
9
+ *
10
+ * @nolint
11
+ */
12
+
13
+ package com.applehealthkit;
14
+
15
+ import com.facebook.proguard.annotations.DoNotStrip;
16
+ import com.facebook.react.bridge.Promise;
17
+ import com.facebook.react.bridge.ReactApplicationContext;
18
+ import com.facebook.react.bridge.ReactContextBaseJavaModule;
19
+ import com.facebook.react.bridge.ReactMethod;
20
+ import com.facebook.react.turbomodule.core.interfaces.TurboModule;
21
+ import javax.annotation.Nonnull;
22
+
23
+ public abstract class NativeAppleHealthKitSpec extends ReactContextBaseJavaModule implements TurboModule {
24
+ public static final String NAME = "AppleHealthKit";
25
+
26
+ public NativeAppleHealthKitSpec(ReactApplicationContext reactContext) {
27
+ super(reactContext);
28
+ }
29
+
30
+ @Override
31
+ public @Nonnull String getName() {
32
+ return NAME;
33
+ }
34
+
35
+ @ReactMethod
36
+ @DoNotStrip
37
+ public abstract void requestHealthKitPermissions(Promise promise);
38
+
39
+ @ReactMethod
40
+ @DoNotStrip
41
+ public abstract void getSteps(double daysBefore, Promise promise);
42
+
43
+ @ReactMethod
44
+ @DoNotStrip
45
+ public abstract void getHeartRate(double daysBefore, Promise promise);
46
+
47
+ @ReactMethod
48
+ @DoNotStrip
49
+ public abstract void getMeasurement(Promise promise);
50
+ }
@@ -0,0 +1,36 @@
1
+ # Copyright (c) Meta Platforms, Inc. and affiliates.
2
+ #
3
+ # This source code is licensed under the MIT license found in the
4
+ # LICENSE file in the root directory of this source tree.
5
+
6
+ cmake_minimum_required(VERSION 3.13)
7
+ set(CMAKE_VERBOSE_MAKEFILE on)
8
+
9
+ file(GLOB react_codegen_SRCS CONFIGURE_DEPENDS *.cpp react/renderer/components/RNAppleHealthKitSpec/*.cpp)
10
+
11
+ add_library(
12
+ react_codegen_RNAppleHealthKitSpec
13
+ OBJECT
14
+ ${react_codegen_SRCS}
15
+ )
16
+
17
+ target_include_directories(react_codegen_RNAppleHealthKitSpec PUBLIC . react/renderer/components/RNAppleHealthKitSpec)
18
+
19
+ target_link_libraries(
20
+ react_codegen_RNAppleHealthKitSpec
21
+ fbjni
22
+ jsi
23
+ # We need to link different libraries based on whether we are building rncore or not, that's necessary
24
+ # because we want to break a circular dependency between react_codegen_rncore and reactnative
25
+ reactnative
26
+ )
27
+
28
+ target_compile_options(
29
+ react_codegen_RNAppleHealthKitSpec
30
+ PRIVATE
31
+ -DLOG_TAG=\"ReactNative\"
32
+ -fexceptions
33
+ -frtti
34
+ -std=c++20
35
+ -Wall
36
+ )
@@ -0,0 +1,50 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateModuleJniCpp.js
9
+ */
10
+
11
+ #include "RNAppleHealthKitSpec.h"
12
+
13
+ namespace facebook::react {
14
+
15
+ static facebook::jsi::Value __hostFunction_NativeAppleHealthKitSpecJSI_requestHealthKitPermissions(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
16
+ static jmethodID cachedMethodId = nullptr;
17
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, PromiseKind, "requestHealthKitPermissions", "(Lcom/facebook/react/bridge/Promise;)V", args, count, cachedMethodId);
18
+ }
19
+
20
+ static facebook::jsi::Value __hostFunction_NativeAppleHealthKitSpecJSI_getSteps(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
21
+ static jmethodID cachedMethodId = nullptr;
22
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, PromiseKind, "getSteps", "(DLcom/facebook/react/bridge/Promise;)V", args, count, cachedMethodId);
23
+ }
24
+
25
+ static facebook::jsi::Value __hostFunction_NativeAppleHealthKitSpecJSI_getHeartRate(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
26
+ static jmethodID cachedMethodId = nullptr;
27
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, PromiseKind, "getHeartRate", "(DLcom/facebook/react/bridge/Promise;)V", args, count, cachedMethodId);
28
+ }
29
+
30
+ static facebook::jsi::Value __hostFunction_NativeAppleHealthKitSpecJSI_getMeasurement(facebook::jsi::Runtime& rt, TurboModule &turboModule, const facebook::jsi::Value* args, size_t count) {
31
+ static jmethodID cachedMethodId = nullptr;
32
+ return static_cast<JavaTurboModule &>(turboModule).invokeJavaMethod(rt, PromiseKind, "getMeasurement", "(Lcom/facebook/react/bridge/Promise;)V", args, count, cachedMethodId);
33
+ }
34
+
35
+ NativeAppleHealthKitSpecJSI::NativeAppleHealthKitSpecJSI(const JavaTurboModule::InitParams &params)
36
+ : JavaTurboModule(params) {
37
+ methodMap_["requestHealthKitPermissions"] = MethodMetadata {0, __hostFunction_NativeAppleHealthKitSpecJSI_requestHealthKitPermissions};
38
+ methodMap_["getSteps"] = MethodMetadata {1, __hostFunction_NativeAppleHealthKitSpecJSI_getSteps};
39
+ methodMap_["getHeartRate"] = MethodMetadata {1, __hostFunction_NativeAppleHealthKitSpecJSI_getHeartRate};
40
+ methodMap_["getMeasurement"] = MethodMetadata {0, __hostFunction_NativeAppleHealthKitSpecJSI_getMeasurement};
41
+ }
42
+
43
+ std::shared_ptr<TurboModule> RNAppleHealthKitSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params) {
44
+ if (moduleName == "AppleHealthKit") {
45
+ return std::make_shared<NativeAppleHealthKitSpecJSI>(params);
46
+ }
47
+ return nullptr;
48
+ }
49
+
50
+ } // namespace facebook::react
@@ -0,0 +1,31 @@
1
+
2
+ /**
3
+ * This code was generated by [react-native-codegen](https://www.npmjs.com/package/react-native-codegen).
4
+ *
5
+ * Do not edit this file as changes may cause incorrect behavior and will be lost
6
+ * once the code is regenerated.
7
+ *
8
+ * @generated by codegen project: GenerateModuleJniH.js
9
+ */
10
+
11
+ #pragma once
12
+
13
+ #include <ReactCommon/JavaTurboModule.h>
14
+ #include <ReactCommon/TurboModule.h>
15
+ #include <jsi/jsi.h>
16
+
17
+ namespace facebook::react {
18
+
19
+ /**
20
+ * JNI C++ class for module 'NativeAppleHealthKit'
21
+ */
22
+ class JSI_EXPORT NativeAppleHealthKitSpecJSI : public JavaTurboModule {
23
+ public:
24
+ NativeAppleHealthKitSpecJSI(const JavaTurboModule::InitParams &params);
25
+ };
26
+
27
+
28
+ JSI_EXPORT
29
+ std::shared_ptr<TurboModule> RNAppleHealthKitSpec_ModuleProvider(const std::string &moduleName, const JavaTurboModule::InitParams &params);
30
+
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 "RNAppleHealthKitSpecJSI.h"
11
+
12
+ namespace facebook::react {
13
+
14
+ static jsi::Value __hostFunction_NativeAppleHealthKitCxxSpecJSI_requestHealthKitPermissions(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
15
+ return static_cast<NativeAppleHealthKitCxxSpecJSI *>(&turboModule)->requestHealthKitPermissions(
16
+ rt
17
+ );
18
+ }
19
+ static jsi::Value __hostFunction_NativeAppleHealthKitCxxSpecJSI_getSteps(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
20
+ return static_cast<NativeAppleHealthKitCxxSpecJSI *>(&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_NativeAppleHealthKitCxxSpecJSI_getHeartRate(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
26
+ return static_cast<NativeAppleHealthKitCxxSpecJSI *>(&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_NativeAppleHealthKitCxxSpecJSI_getMeasurement(jsi::Runtime &rt, TurboModule &turboModule, const jsi::Value* args, size_t count) {
32
+ return static_cast<NativeAppleHealthKitCxxSpecJSI *>(&turboModule)->getMeasurement(
33
+ rt
34
+ );
35
+ }
36
+
37
+ NativeAppleHealthKitCxxSpecJSI::NativeAppleHealthKitCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker)
38
+ : TurboModule("AppleHealthKit", jsInvoker) {
39
+ methodMap_["requestHealthKitPermissions"] = MethodMetadata {0, __hostFunction_NativeAppleHealthKitCxxSpecJSI_requestHealthKitPermissions};
40
+ methodMap_["getSteps"] = MethodMetadata {1, __hostFunction_NativeAppleHealthKitCxxSpecJSI_getSteps};
41
+ methodMap_["getHeartRate"] = MethodMetadata {1, __hostFunction_NativeAppleHealthKitCxxSpecJSI_getHeartRate};
42
+ methodMap_["getMeasurement"] = MethodMetadata {0, __hostFunction_NativeAppleHealthKitCxxSpecJSI_getMeasurement};
43
+ }
44
+
45
+
46
+ } // namespace facebook::react
@@ -0,0 +1,255 @@
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 - NativeAppleHealthKitHeartRate
20
+
21
+ template <typename P0, typename P1>
22
+ struct NativeAppleHealthKitHeartRate {
23
+ P0 date;
24
+ P1 value;
25
+ bool operator==(const NativeAppleHealthKitHeartRate &other) const {
26
+ return date == other.date && value == other.value;
27
+ }
28
+ };
29
+
30
+ template <typename T>
31
+ struct NativeAppleHealthKitHeartRateBridging {
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 - NativeAppleHealthKitMeasurement
68
+
69
+ template <typename P0, typename P1, typename P2, typename P3>
70
+ struct NativeAppleHealthKitMeasurement {
71
+ P0 bodyMass;
72
+ P1 height;
73
+ P2 biologicalSex;
74
+ P3 dateOfBirth;
75
+ bool operator==(const NativeAppleHealthKitMeasurement &other) const {
76
+ return bodyMass == other.bodyMass && height == other.height && biologicalSex == other.biologicalSex && dateOfBirth == other.dateOfBirth;
77
+ }
78
+ };
79
+
80
+ template <typename T>
81
+ struct NativeAppleHealthKitMeasurementBridging {
82
+ static T types;
83
+
84
+ static T fromJs(
85
+ jsi::Runtime &rt,
86
+ const jsi::Object &value,
87
+ const std::shared_ptr<CallInvoker> &jsInvoker) {
88
+ T result{
89
+ bridging::fromJs<decltype(types.bodyMass)>(rt, value.getProperty(rt, "bodyMass"), jsInvoker),
90
+ bridging::fromJs<decltype(types.height)>(rt, value.getProperty(rt, "height"), jsInvoker),
91
+ bridging::fromJs<decltype(types.biologicalSex)>(rt, value.getProperty(rt, "biologicalSex"), jsInvoker),
92
+ bridging::fromJs<decltype(types.dateOfBirth)>(rt, value.getProperty(rt, "dateOfBirth"), jsInvoker)};
93
+ return result;
94
+ }
95
+
96
+ #ifdef DEBUG
97
+ static std::optional<double> bodyMassToJs(jsi::Runtime &rt, decltype(types.bodyMass) value) {
98
+ return bridging::toJs(rt, value);
99
+ }
100
+
101
+ static std::optional<double> heightToJs(jsi::Runtime &rt, decltype(types.height) value) {
102
+ return bridging::toJs(rt, value);
103
+ }
104
+
105
+ static std::optional<jsi::String> biologicalSexToJs(jsi::Runtime &rt, decltype(types.biologicalSex) value) {
106
+ return bridging::toJs(rt, value);
107
+ }
108
+
109
+ static std::optional<jsi::String> dateOfBirthToJs(jsi::Runtime &rt, decltype(types.dateOfBirth) value) {
110
+ return bridging::toJs(rt, value);
111
+ }
112
+ #endif
113
+
114
+ static jsi::Object toJs(
115
+ jsi::Runtime &rt,
116
+ const T &value,
117
+ const std::shared_ptr<CallInvoker> &jsInvoker) {
118
+ auto result = facebook::jsi::Object(rt);
119
+ result.setProperty(rt, "bodyMass", bridging::toJs(rt, value.bodyMass, jsInvoker));
120
+ result.setProperty(rt, "height", bridging::toJs(rt, value.height, jsInvoker));
121
+ result.setProperty(rt, "biologicalSex", bridging::toJs(rt, value.biologicalSex, jsInvoker));
122
+ result.setProperty(rt, "dateOfBirth", bridging::toJs(rt, value.dateOfBirth, jsInvoker));
123
+ return result;
124
+ }
125
+ };
126
+
127
+
128
+
129
+ #pragma mark - NativeAppleHealthKitStep
130
+
131
+ template <typename P0, typename P1>
132
+ struct NativeAppleHealthKitStep {
133
+ P0 dateString;
134
+ P1 stepCount;
135
+ bool operator==(const NativeAppleHealthKitStep &other) const {
136
+ return dateString == other.dateString && stepCount == other.stepCount;
137
+ }
138
+ };
139
+
140
+ template <typename T>
141
+ struct NativeAppleHealthKitStepBridging {
142
+ static T types;
143
+
144
+ static T fromJs(
145
+ jsi::Runtime &rt,
146
+ const jsi::Object &value,
147
+ const std::shared_ptr<CallInvoker> &jsInvoker) {
148
+ T result{
149
+ bridging::fromJs<decltype(types.dateString)>(rt, value.getProperty(rt, "dateString"), jsInvoker),
150
+ bridging::fromJs<decltype(types.stepCount)>(rt, value.getProperty(rt, "stepCount"), jsInvoker)};
151
+ return result;
152
+ }
153
+
154
+ #ifdef DEBUG
155
+ static jsi::String dateStringToJs(jsi::Runtime &rt, decltype(types.dateString) value) {
156
+ return bridging::toJs(rt, value);
157
+ }
158
+
159
+ static double stepCountToJs(jsi::Runtime &rt, decltype(types.stepCount) value) {
160
+ return bridging::toJs(rt, value);
161
+ }
162
+ #endif
163
+
164
+ static jsi::Object toJs(
165
+ jsi::Runtime &rt,
166
+ const T &value,
167
+ const std::shared_ptr<CallInvoker> &jsInvoker) {
168
+ auto result = facebook::jsi::Object(rt);
169
+ result.setProperty(rt, "dateString", bridging::toJs(rt, value.dateString, jsInvoker));
170
+ result.setProperty(rt, "stepCount", bridging::toJs(rt, value.stepCount, jsInvoker));
171
+ return result;
172
+ }
173
+ };
174
+
175
+ class JSI_EXPORT NativeAppleHealthKitCxxSpecJSI : public TurboModule {
176
+ protected:
177
+ NativeAppleHealthKitCxxSpecJSI(std::shared_ptr<CallInvoker> jsInvoker);
178
+
179
+ public:
180
+ virtual jsi::Value requestHealthKitPermissions(jsi::Runtime &rt) = 0;
181
+ virtual jsi::Value getSteps(jsi::Runtime &rt, double daysBefore) = 0;
182
+ virtual jsi::Value getHeartRate(jsi::Runtime &rt, double daysBefore) = 0;
183
+ virtual jsi::Value getMeasurement(jsi::Runtime &rt) = 0;
184
+
185
+ };
186
+
187
+ template <typename T>
188
+ class JSI_EXPORT NativeAppleHealthKitCxxSpec : public TurboModule {
189
+ public:
190
+ jsi::Value create(jsi::Runtime &rt, const jsi::PropNameID &propName) override {
191
+ return delegate_.create(rt, propName);
192
+ }
193
+
194
+ std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime& runtime) override {
195
+ return delegate_.getPropertyNames(runtime);
196
+ }
197
+
198
+ static constexpr std::string_view kModuleName = "AppleHealthKit";
199
+
200
+ protected:
201
+ NativeAppleHealthKitCxxSpec(std::shared_ptr<CallInvoker> jsInvoker)
202
+ : TurboModule(std::string{NativeAppleHealthKitCxxSpec::kModuleName}, jsInvoker),
203
+ delegate_(reinterpret_cast<T*>(this), jsInvoker) {}
204
+
205
+
206
+ private:
207
+ class Delegate : public NativeAppleHealthKitCxxSpecJSI {
208
+ public:
209
+ Delegate(T *instance, std::shared_ptr<CallInvoker> jsInvoker) :
210
+ NativeAppleHealthKitCxxSpecJSI(std::move(jsInvoker)), instance_(instance) {
211
+
212
+ }
213
+
214
+ jsi::Value requestHealthKitPermissions(jsi::Runtime &rt) override {
215
+ static_assert(
216
+ bridging::getParameterCount(&T::requestHealthKitPermissions) == 1,
217
+ "Expected requestHealthKitPermissions(...) to have 1 parameters");
218
+
219
+ return bridging::callFromJs<jsi::Value>(
220
+ rt, &T::requestHealthKitPermissions, jsInvoker_, instance_);
221
+ }
222
+ jsi::Value getSteps(jsi::Runtime &rt, double daysBefore) override {
223
+ static_assert(
224
+ bridging::getParameterCount(&T::getSteps) == 2,
225
+ "Expected getSteps(...) to have 2 parameters");
226
+
227
+ return bridging::callFromJs<jsi::Value>(
228
+ rt, &T::getSteps, jsInvoker_, instance_, std::move(daysBefore));
229
+ }
230
+ jsi::Value getHeartRate(jsi::Runtime &rt, double daysBefore) override {
231
+ static_assert(
232
+ bridging::getParameterCount(&T::getHeartRate) == 2,
233
+ "Expected getHeartRate(...) to have 2 parameters");
234
+
235
+ return bridging::callFromJs<jsi::Value>(
236
+ rt, &T::getHeartRate, jsInvoker_, instance_, std::move(daysBefore));
237
+ }
238
+ jsi::Value getMeasurement(jsi::Runtime &rt) override {
239
+ static_assert(
240
+ bridging::getParameterCount(&T::getMeasurement) == 1,
241
+ "Expected getMeasurement(...) to have 1 parameters");
242
+
243
+ return bridging::callFromJs<jsi::Value>(
244
+ rt, &T::getMeasurement, jsInvoker_, instance_);
245
+ }
246
+
247
+ private:
248
+ friend class NativeAppleHealthKitCxxSpec;
249
+ T *instance_;
250
+ };
251
+
252
+ Delegate delegate_;
253
+ };
254
+
255
+ } // namespace facebook::react
@@ -0,0 +1,6 @@
1
+
2
+ #import "generated/RNAppleHealthKitSpec/RNAppleHealthKitSpec.h"
3
+
4
+ @interface AppleHealthKit : NSObject <NativeAppleHealthKitSpec>
5
+
6
+ @end
@@ -0,0 +1,61 @@
1
+ #import "AppleHealthKit.h"
2
+ #import "AppleHealthKit-Swift.h"
3
+
4
+ @implementation AppleHealthKit {
5
+ AppleHealthKitManager *moduleImpl;
6
+ }
7
+
8
+ - (instancetype)init {
9
+ self = [super init];
10
+ if (self) {
11
+ moduleImpl = [[AppleHealthKitManager alloc] init];
12
+ }
13
+ return self;
14
+ }
15
+
16
+ RCT_EXPORT_MODULE()
17
+
18
+ - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
19
+ (const facebook::react::ObjCTurboModule::InitParams &)params
20
+ {
21
+ return std::make_shared<facebook::react::NativeAppleHealthKitSpecJSI>(params);
22
+ }
23
+
24
+ RCT_EXPORT_METHOD(requestHealthKitPermissions:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
25
+ [moduleImpl requestHealthKitPermissionsWithCompletion:^(BOOL success, NSError * _Nullable error) {
26
+ if (success) {
27
+ resolve(@"Access granted");
28
+ } else {
29
+ reject(@"permission_error", error.localizedDescription, error);
30
+ }
31
+ }];
32
+ }
33
+
34
+ RCT_EXPORT_METHOD(getSteps:(double)daysBefore resolve:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRejectBlock)reject) {
35
+ [moduleImpl getStepsWithDaysBefore:@(daysBefore) completion:^(NSArray * _Nullable steps, NSError * _Nullable error) {
36
+ if (error) {
37
+ reject(@"steps_error", error.localizedDescription, error);
38
+ } else {
39
+ resolve(steps);
40
+ }
41
+ }];
42
+ }
43
+
44
+ - (void)getHeartRate:(double)daysBefore resolve:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
45
+ [moduleImpl getHeartRateWithDaysBefore:@(daysBefore) completion:^(NSArray * _Nullable steps, NSError * _Nullable error) {
46
+ if (error) {
47
+ reject(@"heart_rate_error", error.localizedDescription, error);
48
+ } else {
49
+ resolve(steps);
50
+ }
51
+ }];
52
+ }
53
+
54
+
55
+ - (void)getMeasurement:(nonnull RCTPromiseResolveBlock)resolve reject:(nonnull RCTPromiseRejectBlock)reject {
56
+ [moduleImpl getMeasurementsWithCompletion:^(NSDictionary<NSString *, id> * _Nullable data) {
57
+ resolve(data);
58
+ }];
59
+ }
60
+
61
+ @end
@@ -0,0 +1,48 @@
1
+ import Foundation
2
+ import HealthKit
3
+
4
+ @objc public class AppleHealthKitManager: NSObject {
5
+
6
+ private let healthStore = HKHealthStore()
7
+ private let permissions = HealthKitPermissions()
8
+ private let queries = HealthKitQueries()
9
+
10
+ @objc public func requestHealthKitPermissions(completion: @escaping (Bool, Error?) -> Void) {
11
+ permissions.requestPermissions(completion: completion)
12
+ }
13
+
14
+ @objc public func getSteps(daysBefore: NSNumber, completion: @escaping (NSArray?, Error?) -> Void) {
15
+ queries.getStepsQuery(daysBefore: daysBefore.intValue) { result, error in
16
+ if let error = error {
17
+ completion(nil, error)
18
+ return
19
+ }
20
+
21
+ guard let stepsData = result else {
22
+ completion(nil, NSError(domain: "HealthKit", code: -2, userInfo: [NSLocalizedDescriptionKey: "Invalid steps data"]))
23
+ return
24
+ }
25
+ completion(stepsData as NSArray, nil)
26
+ }
27
+ }
28
+
29
+ @objc public func getHeartRate(daysBefore: NSNumber, completion: @escaping (NSArray?, Error?) -> Void) {
30
+ queries.getHeartRateQuery(daysBefore: daysBefore.intValue) { result, error in
31
+ if let error = error {
32
+ completion(nil, error)
33
+ return
34
+ }
35
+
36
+ guard let heartRateData = result else {
37
+ completion(nil, NSError(domain: "HealthKit", code: -2, userInfo: [NSLocalizedDescriptionKey: "Invalid heart rate data"]))
38
+ return
39
+ }
40
+ completion(heartRateData as NSArray, nil)
41
+ }
42
+ }
43
+
44
+
45
+ @objc public func getMeasurements(completion: @escaping ([String: AnyObject]?) -> Void) {
46
+ queries.getMeasurementsQuery(completion: completion)
47
+ }
48
+ }