@kingstinct/react-native-healthkit 7.3.0 → 7.3.2
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/ios/ReactNativeHealthkit.swift +34 -31
- package/lib/commonjs/hooks/useHealthkitAuthorization.js +5 -0
- package/lib/commonjs/hooks/useHealthkitAuthorization.js.map +1 -1
- package/lib/commonjs/hooks/useMostRecentCategorySample.js +3 -0
- package/lib/commonjs/hooks/useMostRecentCategorySample.js.map +1 -1
- package/lib/commonjs/hooks/useMostRecentQuantitySample.js +3 -0
- package/lib/commonjs/hooks/useMostRecentQuantitySample.js.map +1 -1
- package/lib/commonjs/hooks/useMostRecentWorkout.js +3 -0
- package/lib/commonjs/hooks/useMostRecentWorkout.js.map +1 -1
- package/lib/commonjs/index.ios.js +284 -3
- package/lib/commonjs/index.ios.js.map +1 -1
- package/lib/commonjs/index.js +7 -87
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.native.js +251 -0
- package/lib/commonjs/index.native.js.map +1 -0
- package/lib/commonjs/index.web.js +24 -0
- package/lib/commonjs/index.web.js.map +1 -0
- package/lib/commonjs/utils/saveCategorySample.js +4 -0
- package/lib/commonjs/utils/saveCategorySample.js.map +1 -1
- package/lib/module/hooks/useHealthkitAuthorization.js +5 -0
- package/lib/module/hooks/useHealthkitAuthorization.js.map +1 -1
- package/lib/module/hooks/useMostRecentCategorySample.js +3 -0
- package/lib/module/hooks/useMostRecentCategorySample.js.map +1 -1
- package/lib/module/hooks/useMostRecentQuantitySample.js +3 -0
- package/lib/module/hooks/useMostRecentQuantitySample.js.map +1 -1
- package/lib/module/hooks/useMostRecentWorkout.js +3 -0
- package/lib/module/hooks/useMostRecentWorkout.js.map +1 -1
- package/lib/module/index.ios.js +7 -1
- package/lib/module/index.ios.js.map +1 -1
- package/lib/module/index.js +2 -83
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.native.js +136 -0
- package/lib/module/index.native.js.map +1 -0
- package/lib/module/index.web.js +4 -0
- package/lib/module/index.web.js.map +1 -0
- package/lib/module/utils/saveCategorySample.js +4 -0
- package/lib/module/utils/saveCategorySample.js.map +1 -1
- package/lib/typescript/src/hooks/useHealthkitAuthorization.d.ts +5 -0
- package/lib/typescript/src/hooks/useMostRecentCategorySample.d.ts +3 -0
- package/lib/typescript/src/hooks/useMostRecentQuantitySample.d.ts +3 -0
- package/lib/typescript/src/hooks/useMostRecentWorkout.d.ts +3 -0
- package/lib/typescript/src/index.d.ts +3 -53
- package/lib/typescript/src/index.ios.d.ts +37 -0
- package/lib/typescript/src/index.native.d.ts +29 -0
- package/lib/typescript/src/index.web.d.ts +3 -0
- package/lib/typescript/src/utils/saveCategorySample.d.ts +4 -0
- package/package.json +1 -1
- package/src/hooks/useHealthkitAuthorization.ts +5 -0
- package/src/hooks/useMostRecentCategorySample.ts +3 -0
- package/src/hooks/useMostRecentQuantitySample.ts +3 -0
- package/src/hooks/useMostRecentWorkout.ts +3 -0
- package/src/index.ios.tsx +57 -0
- package/src/index.native.tsx +201 -0
- package/src/index.tsx +3 -97
- package/src/index.web.tsx +5 -0
- package/src/utils/saveCategorySample.ts +4 -0
|
@@ -1,4 +1,8 @@
|
|
|
1
1
|
import type { HKCategoryTypeIdentifier, HKCategoryValueForIdentifier, MetadataMapperForCategoryIdentifier } from '../native-types';
|
|
2
|
+
/**
|
|
3
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614168-savecategorysample save(_:withCompletion:) (Apple Docs)}
|
|
4
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/saving_data_to_healthkit Saving data to HealthKit (Apple Docs)}
|
|
5
|
+
*/
|
|
2
6
|
declare function saveCategorySample<T extends HKCategoryTypeIdentifier>(identifier: T, value: HKCategoryValueForIdentifier<T>, options?: {
|
|
3
7
|
readonly start?: Date;
|
|
4
8
|
readonly end?: Date;
|
package/package.json
CHANGED
|
@@ -7,6 +7,11 @@ import requestAuthorization from '../utils/requestAuthorization'
|
|
|
7
7
|
|
|
8
8
|
import type { HealthkitReadAuthorization, HealthkitWriteAuthorization, HKAuthorizationRequestStatus } from '../native-types'
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @description Hook to retrieve the current authorization status for the given types, and request authorization if needed.
|
|
12
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614152-requestauthorization Apple Docs - requestAuthorization}
|
|
13
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/authorizing_access_to_health_data Apple Docs - Authorizing access to health data}
|
|
14
|
+
*/
|
|
10
15
|
const useHealthkitAuthorization = (read: readonly HealthkitReadAuthorization[], write?: readonly HealthkitWriteAuthorization[]) => {
|
|
11
16
|
const [status, setStatus] = useState<HKAuthorizationRequestStatus | null>(null)
|
|
12
17
|
|
|
@@ -6,6 +6,9 @@ import getMostRecentCategorySample from '../utils/getMostRecentCategorySample'
|
|
|
6
6
|
import type { HKCategoryTypeIdentifier } from '../native-types'
|
|
7
7
|
import type { HKCategorySample } from '../types'
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @returns the most recent sample for the given category type.
|
|
11
|
+
*/
|
|
9
12
|
function useMostRecentCategorySample<
|
|
10
13
|
TCategory extends HKCategoryTypeIdentifier
|
|
11
14
|
>(identifier: TCategory) {
|
|
@@ -7,6 +7,9 @@ import subscribeToChanges from '../utils/subscribeToChanges'
|
|
|
7
7
|
import type { HKQuantityTypeIdentifier, UnitForIdentifier } from '../native-types'
|
|
8
8
|
import type { HKQuantitySample } from '../types'
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* @returns the most recent sample for the given quantity type.
|
|
12
|
+
*/
|
|
10
13
|
function useMostRecentQuantitySample<
|
|
11
14
|
TIdentifier extends HKQuantityTypeIdentifier,
|
|
12
15
|
TUnit extends UnitForIdentifier<TIdentifier>
|
|
@@ -9,6 +9,9 @@ import subscribeToChanges from '../utils/subscribeToChanges'
|
|
|
9
9
|
import type { EnergyUnit, LengthUnit } from '../native-types'
|
|
10
10
|
import type { HKWorkout } from '../types'
|
|
11
11
|
|
|
12
|
+
/**
|
|
13
|
+
* @returns the most recent workout sample.
|
|
14
|
+
*/
|
|
12
15
|
function useMostRecentWorkout<
|
|
13
16
|
TEnergy extends EnergyUnit,
|
|
14
17
|
TDistance extends LengthUnit
|
package/src/index.ios.tsx
CHANGED
|
@@ -5,6 +5,8 @@ import useIsHealthDataAvailable from './hooks/useIsHealthDataAvailable'
|
|
|
5
5
|
import useMostRecentCategorySample from './hooks/useMostRecentCategorySample'
|
|
6
6
|
import useMostRecentQuantitySample from './hooks/useMostRecentQuantitySample'
|
|
7
7
|
import useMostRecentWorkout from './hooks/useMostRecentWorkout'
|
|
8
|
+
import useSources from './hooks/useSources'
|
|
9
|
+
import useStatisticsForQuantity from './hooks/useStatisticsForQuantity'
|
|
8
10
|
import useSubscribeToChanges from './hooks/useSubscribeToChanges'
|
|
9
11
|
import Native, { HKQuantityTypeIdentifier } from './native-types'
|
|
10
12
|
import deleteQuantitySample from './utils/deleteQuantitySample'
|
|
@@ -214,6 +216,61 @@ export default {
|
|
|
214
216
|
* @see {@link https://developer.apple.com/documentation/healthkit/authorizing_access_to_health_data Apple Docs - Authorizing access to health data}
|
|
215
217
|
*/
|
|
216
218
|
useHealthkitAuthorization,
|
|
219
|
+
useSources,
|
|
220
|
+
useStatisticsForQuantity,
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
const isProtectedDataAvailable = canAccessProtectedData
|
|
224
|
+
|
|
225
|
+
export {
|
|
226
|
+
authorizationStatusFor,
|
|
227
|
+
availableQuantityTypes,
|
|
228
|
+
disableAllBackgroundDelivery,
|
|
229
|
+
disableBackgroundDelivery,
|
|
230
|
+
enableBackgroundDelivery,
|
|
231
|
+
getBiologicalSex,
|
|
232
|
+
getBloodType,
|
|
233
|
+
getDateOfBirth,
|
|
234
|
+
getFitzpatrickSkinType,
|
|
235
|
+
getMostRecentCategorySample,
|
|
236
|
+
getMostRecentQuantitySample,
|
|
237
|
+
getMostRecentWorkout,
|
|
238
|
+
getPreferredUnit,
|
|
239
|
+
getPreferredUnits,
|
|
240
|
+
getRequestStatusForAuthorization,
|
|
241
|
+
getWheelchairUse,
|
|
242
|
+
getWorkoutRoutes,
|
|
243
|
+
isHealthDataAvailable,
|
|
244
|
+
queryCategorySamples,
|
|
245
|
+
queryCategorySamplesWithAnchor,
|
|
246
|
+
queryCorrelationSamples,
|
|
247
|
+
queryHeartbeatSeriesSamples,
|
|
248
|
+
queryHeartbeatSeriesSamplesWithAnchor,
|
|
249
|
+
queryQuantitySamples,
|
|
250
|
+
queryQuantitySamplesWithAnchor,
|
|
251
|
+
queryStatisticsForQuantity,
|
|
252
|
+
queryWorkouts,
|
|
253
|
+
querySources,
|
|
254
|
+
requestAuthorization,
|
|
255
|
+
deleteQuantitySample,
|
|
256
|
+
deleteSamples,
|
|
257
|
+
getWorkoutPlanById,
|
|
258
|
+
saveCategorySample,
|
|
259
|
+
saveCorrelationSample,
|
|
260
|
+
saveQuantitySample,
|
|
261
|
+
saveWorkoutSample,
|
|
262
|
+
saveWorkoutRoute,
|
|
263
|
+
subscribeToChanges,
|
|
264
|
+
useMostRecentCategorySample,
|
|
265
|
+
useMostRecentQuantitySample,
|
|
266
|
+
useMostRecentWorkout,
|
|
267
|
+
useSubscribeToChanges,
|
|
268
|
+
useHealthkitAuthorization,
|
|
269
|
+
useIsHealthDataAvailable,
|
|
270
|
+
useSources,
|
|
271
|
+
useStatisticsForQuantity,
|
|
272
|
+
canAccessProtectedData,
|
|
273
|
+
isProtectedDataAvailable,
|
|
217
274
|
}
|
|
218
275
|
|
|
219
276
|
export * from './types'
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { Platform } from 'react-native'
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
HKAuthorizationRequestStatus, HKAuthorizationStatus, HKBiologicalSex, HKBloodType, HKFitzpatrickSkinType, HKUnits, HKWheelchairUse,
|
|
5
|
+
} from './native-types'
|
|
6
|
+
|
|
7
|
+
import type ReactNativeHealthkit from './index.ios'
|
|
8
|
+
import type { QueryCategorySamplesFn } from './utils/queryCategorySamples'
|
|
9
|
+
import type { QueryQuantitySamplesFn } from './utils/queryQuantitySamples'
|
|
10
|
+
|
|
11
|
+
const notAvailableError = `[@kingstinct/react-native-healthkit] Platform "${
|
|
12
|
+
Platform.OS
|
|
13
|
+
}" not supported`
|
|
14
|
+
|
|
15
|
+
let hasWarned = false
|
|
16
|
+
|
|
17
|
+
function UnavailableFn<T = unknown>(retVal: T) {
|
|
18
|
+
return () => {
|
|
19
|
+
if (!hasWarned) {
|
|
20
|
+
// eslint-disable-next-line no-console
|
|
21
|
+
console.warn(notAvailableError)
|
|
22
|
+
hasWarned = true
|
|
23
|
+
}
|
|
24
|
+
return retVal
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const authorizationStatusFor = UnavailableFn(Promise.resolve(HKAuthorizationStatus.notDetermined)),
|
|
29
|
+
availableQuantityTypes = UnavailableFn([]),
|
|
30
|
+
disableAllBackgroundDelivery = UnavailableFn(Promise.resolve(false)),
|
|
31
|
+
disableBackgroundDelivery = UnavailableFn(Promise.resolve(false)),
|
|
32
|
+
enableBackgroundDelivery = UnavailableFn(Promise.resolve(false)),
|
|
33
|
+
getBiologicalSex = UnavailableFn(Promise.resolve(HKBiologicalSex.notSet)),
|
|
34
|
+
getBloodType = UnavailableFn(Promise.resolve(HKBloodType.notSet)),
|
|
35
|
+
getDateOfBirth = UnavailableFn(Promise.resolve(new Date(0))),
|
|
36
|
+
getFitzpatrickSkinType = UnavailableFn(Promise.resolve(HKFitzpatrickSkinType.notSet)),
|
|
37
|
+
getMostRecentCategorySample = UnavailableFn(Promise.resolve(null)),
|
|
38
|
+
getMostRecentQuantitySample = UnavailableFn(Promise.resolve(null)),
|
|
39
|
+
getMostRecentWorkout = UnavailableFn(Promise.resolve(null)),
|
|
40
|
+
getPreferredUnit = UnavailableFn(Promise.resolve(HKUnits.Count)),
|
|
41
|
+
getPreferredUnits = UnavailableFn(Promise.resolve([])),
|
|
42
|
+
getRequestStatusForAuthorization = UnavailableFn(Promise.resolve(HKAuthorizationRequestStatus.unknown)),
|
|
43
|
+
getWheelchairUse = UnavailableFn(Promise.resolve(HKWheelchairUse.notSet)),
|
|
44
|
+
getWorkoutRoutes = UnavailableFn(Promise.resolve([])),
|
|
45
|
+
isHealthDataAvailable = async () => Promise.resolve(false),
|
|
46
|
+
useSources = UnavailableFn(null),
|
|
47
|
+
useStatisticsForQuantity = UnavailableFn(null),
|
|
48
|
+
queryCategorySamples = UnavailableFn(Promise.resolve([])) as unknown as QueryCategorySamplesFn,
|
|
49
|
+
queryCategorySamplesWithAnchor = UnavailableFn(Promise.resolve({
|
|
50
|
+
samples: [],
|
|
51
|
+
deletedSamples: [],
|
|
52
|
+
newAnchor: '',
|
|
53
|
+
})),
|
|
54
|
+
queryCorrelationSamples = UnavailableFn(Promise.resolve([])),
|
|
55
|
+
queryHeartbeatSeriesSamples = UnavailableFn(Promise.resolve([])),
|
|
56
|
+
queryHeartbeatSeriesSamplesWithAnchor = UnavailableFn(Promise.resolve({
|
|
57
|
+
samples: [],
|
|
58
|
+
deletedSamples: [],
|
|
59
|
+
newAnchor: '',
|
|
60
|
+
})),
|
|
61
|
+
queryQuantitySamples = UnavailableFn(Promise.resolve([])) as unknown as QueryQuantitySamplesFn,
|
|
62
|
+
queryQuantitySamplesWithAnchor = UnavailableFn(Promise.resolve({
|
|
63
|
+
samples: [],
|
|
64
|
+
deletedSamples: [],
|
|
65
|
+
newAnchor: '',
|
|
66
|
+
})),
|
|
67
|
+
queryStatisticsForQuantity = UnavailableFn(Promise.resolve({
|
|
68
|
+
averageQuantity: undefined,
|
|
69
|
+
maximumQuantity: undefined,
|
|
70
|
+
minimumQuantity: undefined,
|
|
71
|
+
sumQuantity: undefined,
|
|
72
|
+
mostRecentQuantity: undefined,
|
|
73
|
+
mostRecentQuantityDateInterval: undefined,
|
|
74
|
+
duration: undefined,
|
|
75
|
+
})),
|
|
76
|
+
queryWorkouts = UnavailableFn(Promise.resolve([])),
|
|
77
|
+
querySources = UnavailableFn(Promise.resolve([])),
|
|
78
|
+
requestAuthorization = UnavailableFn(Promise.resolve(false)),
|
|
79
|
+
deleteQuantitySample = UnavailableFn(Promise.resolve(false)),
|
|
80
|
+
deleteSamples = UnavailableFn(Promise.resolve(false)),
|
|
81
|
+
getWorkoutPlanById = UnavailableFn(Promise.resolve(null)),
|
|
82
|
+
saveCategorySample = UnavailableFn(Promise.resolve(false)),
|
|
83
|
+
saveCorrelationSample = UnavailableFn(Promise.resolve(false)),
|
|
84
|
+
saveQuantitySample = UnavailableFn(Promise.resolve(false)),
|
|
85
|
+
saveWorkoutSample = UnavailableFn(Promise.resolve(null)),
|
|
86
|
+
saveWorkoutRoute = UnavailableFn(Promise.resolve(false)),
|
|
87
|
+
subscribeToChanges = UnavailableFn(Promise.resolve(async () => Promise.resolve(false))),
|
|
88
|
+
useMostRecentCategorySample = UnavailableFn(null),
|
|
89
|
+
useMostRecentQuantitySample = UnavailableFn(null),
|
|
90
|
+
useMostRecentWorkout = UnavailableFn(null),
|
|
91
|
+
useSubscribeToChanges = UnavailableFn([null, () => null]),
|
|
92
|
+
useHealthkitAuthorization = UnavailableFn([null, async () => Promise.resolve(HKAuthorizationRequestStatus.unknown)] as const),
|
|
93
|
+
useIsHealthDataAvailable = () => false,
|
|
94
|
+
canAccessProtectedData = async () => Promise.resolve(false),
|
|
95
|
+
isProtectedDataAvailable = async () => Promise.resolve(false)
|
|
96
|
+
|
|
97
|
+
const Healthkit: typeof ReactNativeHealthkit = {
|
|
98
|
+
authorizationStatusFor,
|
|
99
|
+
availableQuantityTypes,
|
|
100
|
+
useSources,
|
|
101
|
+
useStatisticsForQuantity,
|
|
102
|
+
disableAllBackgroundDelivery,
|
|
103
|
+
disableBackgroundDelivery,
|
|
104
|
+
enableBackgroundDelivery,
|
|
105
|
+
getBiologicalSex,
|
|
106
|
+
getBloodType,
|
|
107
|
+
getDateOfBirth,
|
|
108
|
+
getFitzpatrickSkinType,
|
|
109
|
+
getMostRecentCategorySample,
|
|
110
|
+
getMostRecentQuantitySample,
|
|
111
|
+
getMostRecentWorkout,
|
|
112
|
+
getPreferredUnit,
|
|
113
|
+
getPreferredUnits,
|
|
114
|
+
getRequestStatusForAuthorization,
|
|
115
|
+
getWheelchairUse,
|
|
116
|
+
getWorkoutRoutes,
|
|
117
|
+
isHealthDataAvailable,
|
|
118
|
+
queryCategorySamples,
|
|
119
|
+
queryCategorySamplesWithAnchor,
|
|
120
|
+
queryCorrelationSamples,
|
|
121
|
+
queryHeartbeatSeriesSamples,
|
|
122
|
+
queryHeartbeatSeriesSamplesWithAnchor,
|
|
123
|
+
queryQuantitySamples,
|
|
124
|
+
queryQuantitySamplesWithAnchor,
|
|
125
|
+
queryStatisticsForQuantity,
|
|
126
|
+
queryWorkouts,
|
|
127
|
+
querySources,
|
|
128
|
+
requestAuthorization,
|
|
129
|
+
deleteQuantitySample,
|
|
130
|
+
deleteSamples,
|
|
131
|
+
getWorkoutPlanById,
|
|
132
|
+
saveCategorySample,
|
|
133
|
+
saveCorrelationSample,
|
|
134
|
+
saveQuantitySample,
|
|
135
|
+
saveWorkoutSample,
|
|
136
|
+
saveWorkoutRoute,
|
|
137
|
+
subscribeToChanges,
|
|
138
|
+
useMostRecentCategorySample,
|
|
139
|
+
useMostRecentQuantitySample,
|
|
140
|
+
useMostRecentWorkout,
|
|
141
|
+
useSubscribeToChanges,
|
|
142
|
+
useHealthkitAuthorization,
|
|
143
|
+
useIsHealthDataAvailable,
|
|
144
|
+
canAccessProtectedData,
|
|
145
|
+
isProtectedDataAvailable,
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export {
|
|
149
|
+
authorizationStatusFor,
|
|
150
|
+
availableQuantityTypes,
|
|
151
|
+
disableAllBackgroundDelivery,
|
|
152
|
+
disableBackgroundDelivery,
|
|
153
|
+
enableBackgroundDelivery,
|
|
154
|
+
useSources,
|
|
155
|
+
useStatisticsForQuantity,
|
|
156
|
+
getBiologicalSex,
|
|
157
|
+
getBloodType,
|
|
158
|
+
getDateOfBirth,
|
|
159
|
+
getFitzpatrickSkinType,
|
|
160
|
+
getMostRecentCategorySample,
|
|
161
|
+
getMostRecentQuantitySample,
|
|
162
|
+
getMostRecentWorkout,
|
|
163
|
+
getPreferredUnit,
|
|
164
|
+
getPreferredUnits,
|
|
165
|
+
getRequestStatusForAuthorization,
|
|
166
|
+
getWheelchairUse,
|
|
167
|
+
getWorkoutRoutes,
|
|
168
|
+
isHealthDataAvailable,
|
|
169
|
+
queryCategorySamples,
|
|
170
|
+
queryCategorySamplesWithAnchor,
|
|
171
|
+
queryCorrelationSamples,
|
|
172
|
+
queryHeartbeatSeriesSamples,
|
|
173
|
+
queryHeartbeatSeriesSamplesWithAnchor,
|
|
174
|
+
queryQuantitySamples,
|
|
175
|
+
queryQuantitySamplesWithAnchor,
|
|
176
|
+
queryStatisticsForQuantity,
|
|
177
|
+
queryWorkouts,
|
|
178
|
+
querySources,
|
|
179
|
+
requestAuthorization,
|
|
180
|
+
deleteQuantitySample,
|
|
181
|
+
deleteSamples,
|
|
182
|
+
getWorkoutPlanById,
|
|
183
|
+
saveCategorySample,
|
|
184
|
+
saveCorrelationSample,
|
|
185
|
+
saveQuantitySample,
|
|
186
|
+
saveWorkoutSample,
|
|
187
|
+
saveWorkoutRoute,
|
|
188
|
+
subscribeToChanges,
|
|
189
|
+
useMostRecentCategorySample,
|
|
190
|
+
useMostRecentQuantitySample,
|
|
191
|
+
useMostRecentWorkout,
|
|
192
|
+
useSubscribeToChanges,
|
|
193
|
+
useHealthkitAuthorization,
|
|
194
|
+
useIsHealthDataAvailable,
|
|
195
|
+
canAccessProtectedData,
|
|
196
|
+
isProtectedDataAvailable,
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export * from './types'
|
|
200
|
+
|
|
201
|
+
export default Healthkit
|
package/src/index.tsx
CHANGED
|
@@ -1,99 +1,5 @@
|
|
|
1
|
-
import
|
|
1
|
+
import Healthkit from './index.ios'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
HKAuthorizationRequestStatus, HKAuthorizationStatus, HKBiologicalSex, HKBloodType, HKFitzpatrickSkinType, HKUnits, HKWheelchairUse,
|
|
5
|
-
} from './native-types'
|
|
3
|
+
export * from './index.ios'
|
|
6
4
|
|
|
7
|
-
|
|
8
|
-
import type { QueryCategorySamplesFn } from './utils/queryCategorySamples'
|
|
9
|
-
import type { QueryQuantitySamplesFn } from './utils/queryQuantitySamples'
|
|
10
|
-
|
|
11
|
-
const notAvailableError = `[@kingstinct/react-native-healthkit] Platform "${
|
|
12
|
-
Platform.OS
|
|
13
|
-
}" not supported`
|
|
14
|
-
|
|
15
|
-
let hasWarned = false
|
|
16
|
-
|
|
17
|
-
function UnavailableFn<T = unknown>(retVal: T) {
|
|
18
|
-
return () => {
|
|
19
|
-
if (!hasWarned) {
|
|
20
|
-
// eslint-disable-next-line no-console
|
|
21
|
-
console.warn(notAvailableError)
|
|
22
|
-
hasWarned = true
|
|
23
|
-
}
|
|
24
|
-
return retVal
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const Healthkit = {
|
|
29
|
-
authorizationStatusFor: UnavailableFn(Promise.resolve(HKAuthorizationStatus.notDetermined)),
|
|
30
|
-
availableQuantityTypes: UnavailableFn([]),
|
|
31
|
-
disableAllBackgroundDelivery: UnavailableFn(Promise.resolve(false)),
|
|
32
|
-
disableBackgroundDelivery: UnavailableFn(Promise.resolve(false)),
|
|
33
|
-
enableBackgroundDelivery: UnavailableFn(Promise.resolve(false)),
|
|
34
|
-
getBiologicalSex: UnavailableFn(Promise.resolve(HKBiologicalSex.notSet)),
|
|
35
|
-
getBloodType: UnavailableFn(Promise.resolve(HKBloodType.notSet)),
|
|
36
|
-
getDateOfBirth: UnavailableFn(Promise.resolve(new Date(0))),
|
|
37
|
-
getFitzpatrickSkinType: UnavailableFn(Promise.resolve(HKFitzpatrickSkinType.notSet)),
|
|
38
|
-
getMostRecentCategorySample: UnavailableFn(Promise.resolve(null)),
|
|
39
|
-
getMostRecentQuantitySample: UnavailableFn(Promise.resolve(null)),
|
|
40
|
-
getMostRecentWorkout: UnavailableFn(Promise.resolve(null)),
|
|
41
|
-
getPreferredUnit: UnavailableFn(Promise.resolve(HKUnits.Count)),
|
|
42
|
-
getPreferredUnits: UnavailableFn(Promise.resolve([])),
|
|
43
|
-
getRequestStatusForAuthorization: UnavailableFn(Promise.resolve(HKAuthorizationRequestStatus.unknown)),
|
|
44
|
-
getWheelchairUse: UnavailableFn(Promise.resolve(HKWheelchairUse.notSet)),
|
|
45
|
-
getWorkoutRoutes: UnavailableFn(Promise.resolve([])),
|
|
46
|
-
isHealthDataAvailable: async () => Promise.resolve(false),
|
|
47
|
-
queryCategorySamples: UnavailableFn(Promise.resolve([])) as unknown as QueryCategorySamplesFn,
|
|
48
|
-
queryCategorySamplesWithAnchor: UnavailableFn(Promise.resolve({
|
|
49
|
-
samples: [],
|
|
50
|
-
deletedSamples: [],
|
|
51
|
-
newAnchor: '',
|
|
52
|
-
})),
|
|
53
|
-
queryCorrelationSamples: UnavailableFn(Promise.resolve([])),
|
|
54
|
-
queryHeartbeatSeriesSamples: UnavailableFn(Promise.resolve([])),
|
|
55
|
-
queryHeartbeatSeriesSamplesWithAnchor: UnavailableFn(Promise.resolve({
|
|
56
|
-
samples: [],
|
|
57
|
-
deletedSamples: [],
|
|
58
|
-
newAnchor: '',
|
|
59
|
-
})),
|
|
60
|
-
queryQuantitySamples: UnavailableFn(Promise.resolve([])) as unknown as QueryQuantitySamplesFn,
|
|
61
|
-
queryQuantitySamplesWithAnchor: UnavailableFn(Promise.resolve({
|
|
62
|
-
samples: [],
|
|
63
|
-
deletedSamples: [],
|
|
64
|
-
newAnchor: '',
|
|
65
|
-
})),
|
|
66
|
-
queryStatisticsForQuantity: UnavailableFn(Promise.resolve({
|
|
67
|
-
averageQuantity: undefined,
|
|
68
|
-
maximumQuantity: undefined,
|
|
69
|
-
minimumQuantity: undefined,
|
|
70
|
-
sumQuantity: undefined,
|
|
71
|
-
mostRecentQuantity: undefined,
|
|
72
|
-
mostRecentQuantityDateInterval: undefined,
|
|
73
|
-
duration: undefined,
|
|
74
|
-
})),
|
|
75
|
-
queryWorkouts: UnavailableFn(Promise.resolve([])),
|
|
76
|
-
querySources: UnavailableFn(Promise.resolve([])),
|
|
77
|
-
requestAuthorization: UnavailableFn(Promise.resolve(false)),
|
|
78
|
-
deleteQuantitySample: UnavailableFn(Promise.resolve(false)),
|
|
79
|
-
deleteSamples: UnavailableFn(Promise.resolve(false)),
|
|
80
|
-
getWorkoutPlanById: UnavailableFn(Promise.resolve(null)),
|
|
81
|
-
saveCategorySample: UnavailableFn(Promise.resolve(false)),
|
|
82
|
-
saveCorrelationSample: UnavailableFn(Promise.resolve(false)),
|
|
83
|
-
saveQuantitySample: UnavailableFn(Promise.resolve(false)),
|
|
84
|
-
saveWorkoutSample: UnavailableFn(Promise.resolve(null)),
|
|
85
|
-
saveWorkoutRoute: UnavailableFn(Promise.resolve(false)),
|
|
86
|
-
subscribeToChanges: UnavailableFn(Promise.resolve(async () => Promise.resolve(false))),
|
|
87
|
-
useMostRecentCategorySample: UnavailableFn(null),
|
|
88
|
-
useMostRecentQuantitySample: UnavailableFn(null),
|
|
89
|
-
useMostRecentWorkout: UnavailableFn(null),
|
|
90
|
-
useSubscribeToChanges: UnavailableFn([null, () => null]),
|
|
91
|
-
useHealthkitAuthorization: UnavailableFn([null, async () => Promise.resolve(HKAuthorizationRequestStatus.unknown)] as const),
|
|
92
|
-
useIsHealthDataAvailable: () => false,
|
|
93
|
-
canAccessProtectedData: async () => Promise.resolve(false),
|
|
94
|
-
isProtectedDataAvailable: async () => Promise.resolve(false),
|
|
95
|
-
} as typeof ReactNativeHealthkit
|
|
96
|
-
|
|
97
|
-
export * from './types'
|
|
98
|
-
|
|
99
|
-
export default Healthkit as typeof ReactNativeHealthkit
|
|
5
|
+
export default Healthkit
|
|
@@ -2,6 +2,10 @@ import Native from '../native-types'
|
|
|
2
2
|
|
|
3
3
|
import type { HKCategoryTypeIdentifier, HKCategoryValueForIdentifier, MetadataMapperForCategoryIdentifier } from '../native-types'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614168-savecategorysample save(_:withCompletion:) (Apple Docs)}
|
|
7
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/saving_data_to_healthkit Saving data to HealthKit (Apple Docs)}
|
|
8
|
+
*/
|
|
5
9
|
async function saveCategorySample<T extends HKCategoryTypeIdentifier>(
|
|
6
10
|
identifier: T,
|
|
7
11
|
value: HKCategoryValueForIdentifier<T>,
|