@kingstinct/react-native-healthkit 7.0.4 → 7.0.6
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 +7 -31
- package/ios/ReactNativeHealthkit.swift +3 -2
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js +5 -0
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js.map +1 -1
- package/lib/commonjs/index.ios.js +121 -15
- package/lib/commonjs/index.ios.js.map +1 -1
- package/lib/commonjs/index.js +3 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/jest.setup.js +1 -0
- package/lib/commonjs/jest.setup.js.map +1 -1
- package/lib/commonjs/native-types.js +36 -27
- package/lib/commonjs/native-types.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/getMostRecentCategorySample.js +1 -1
- package/lib/commonjs/utils/getMostRecentCategorySample.js.map +1 -1
- package/lib/commonjs/utils/getMostRecentQuantitySample.js +5 -1
- package/lib/commonjs/utils/getMostRecentQuantitySample.js.map +1 -1
- package/lib/module/hooks/useIsHealthDataAvailable.js +6 -0
- package/lib/module/hooks/useIsHealthDataAvailable.js.map +1 -1
- package/lib/module/index.ios.js +119 -15
- package/lib/module/index.ios.js.map +1 -1
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/jest.setup.js +1 -0
- package/lib/module/jest.setup.js.map +1 -1
- package/lib/module/native-types.js +36 -27
- package/lib/module/native-types.js.map +1 -1
- package/lib/module/types.js +59 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/getMostRecentCategorySample.js +1 -1
- package/lib/module/utils/getMostRecentCategorySample.js.map +1 -1
- package/lib/module/utils/getMostRecentQuantitySample.js +5 -1
- package/lib/module/utils/getMostRecentQuantitySample.js.map +1 -1
- package/lib/typescript/src/hooks/useIsHealthDataAvailable.d.ts +5 -0
- package/lib/typescript/src/index.d.ts +50 -3
- package/lib/typescript/src/index.ios.d.ts +84 -3
- package/lib/typescript/src/native-types.d.ts +515 -34
- package/lib/typescript/src/types.d.ts +49 -0
- package/lib/typescript/src/utils/getMostRecentCategorySample.d.ts +2 -1
- package/lib/typescript/src/utils/getMostRecentQuantitySample.d.ts +2 -1
- package/package.json +1 -1
- package/src/hooks/useIsHealthDataAvailable.ts +5 -0
- package/src/index.ios.tsx +132 -21
- package/src/index.tsx +6 -4
- package/src/jest.setup.ts +1 -0
- package/src/native-types.ts +615 -81
- package/src/types.ts +51 -2
- package/src/utils/getMostRecentCategorySample.ts +3 -2
- package/src/utils/getMostRecentQuantitySample.ts +9 -2
|
@@ -1,13 +1,27 @@
|
|
|
1
1
|
import type { EnergyUnit, HKCategorySampleRaw, HKCategoryTypeIdentifier, HKCorrelationRaw, HKCorrelationTypeIdentifier, HKDevice, HKHeartbeatSeriesSampleRaw, HKQuantityTypeIdentifier, HKSourceRevision, HKUnit, HKWorkoutRaw, LengthUnit, MetadataMapperForQuantityIdentifier, QueryStatisticsResponseRaw, UnitForIdentifier } from './native-types';
|
|
2
2
|
export * from './native-types';
|
|
3
|
+
/**
|
|
4
|
+
* Options for querying workouts.
|
|
5
|
+
* @template TEnergy The energy unit type.
|
|
6
|
+
* @template TDistance The distance unit type.
|
|
7
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkworkout Apple Docs HKWorkout}
|
|
8
|
+
*/
|
|
3
9
|
export interface QueryWorkoutsOptions<TEnergy extends HKUnit, TDistance extends HKUnit> extends GenericQueryOptions {
|
|
4
10
|
readonly energyUnit?: TEnergy;
|
|
5
11
|
readonly distanceUnit?: TDistance;
|
|
6
12
|
}
|
|
13
|
+
/**
|
|
14
|
+
* Represents a category sample.
|
|
15
|
+
* @template T The category type identifier.
|
|
16
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkcategorysample Apple Docs HKCategorySample}
|
|
17
|
+
*/
|
|
7
18
|
export interface HKCategorySample<T extends HKCategoryTypeIdentifier = HKCategoryTypeIdentifier> extends Omit<HKCategorySampleRaw<T>, 'endDate' | 'startDate'> {
|
|
8
19
|
readonly startDate: Date;
|
|
9
20
|
readonly endDate: Date;
|
|
10
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Generic options for querying.
|
|
24
|
+
*/
|
|
11
25
|
export type GenericQueryOptions = {
|
|
12
26
|
readonly from?: Date;
|
|
13
27
|
readonly to?: Date;
|
|
@@ -15,14 +29,30 @@ export type GenericQueryOptions = {
|
|
|
15
29
|
readonly ascending?: boolean;
|
|
16
30
|
readonly anchor?: string;
|
|
17
31
|
};
|
|
32
|
+
/**
|
|
33
|
+
* Represents a workout.
|
|
34
|
+
* @template TEnergy The energy unit type.
|
|
35
|
+
* @template TDistance The distance unit type.
|
|
36
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkworkout Apple Docs HKWorkout}
|
|
37
|
+
*/
|
|
18
38
|
export interface HKWorkout<TEnergy extends EnergyUnit = EnergyUnit, TDistance extends LengthUnit = LengthUnit> extends Omit<HKWorkoutRaw<TEnergy, TDistance>, 'endDate' | 'startDate'> {
|
|
19
39
|
readonly startDate: Date;
|
|
20
40
|
readonly endDate: Date;
|
|
21
41
|
}
|
|
42
|
+
/**
|
|
43
|
+
* Represents a heartbeat series sample.
|
|
44
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkheartbeatseriessample Apple Docs HKHeartbeatSeriesSample}
|
|
45
|
+
*/
|
|
22
46
|
export interface HKHeartbeatSeriesSample extends Omit<HKHeartbeatSeriesSampleRaw, 'endDate' | 'startDate'> {
|
|
23
47
|
readonly startDate: Date;
|
|
24
48
|
readonly endDate: Date;
|
|
25
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* Represents a quantity sample.
|
|
52
|
+
* @template TIdentifier The quantity type identifier.
|
|
53
|
+
* @template TUnit The unit for the identifier.
|
|
54
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkquantitysample Apple Docs HKQuantitySample}
|
|
55
|
+
*/
|
|
26
56
|
export interface HKQuantitySample<TIdentifier extends HKQuantityTypeIdentifier = HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier> = UnitForIdentifier<TIdentifier>> {
|
|
27
57
|
readonly uuid: string;
|
|
28
58
|
readonly device?: HKDevice;
|
|
@@ -34,14 +64,33 @@ export interface HKQuantitySample<TIdentifier extends HKQuantityTypeIdentifier =
|
|
|
34
64
|
readonly startDate: Date;
|
|
35
65
|
readonly endDate: Date;
|
|
36
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Represents a response from a statistics query.
|
|
69
|
+
* @template TIdentifier The quantity type identifier.
|
|
70
|
+
* @template TUnit The unit for the identifier.
|
|
71
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkstatisticsquery Apple Docs HKStatisticsQuery}
|
|
72
|
+
*/
|
|
37
73
|
export interface QueryStatisticsResponse<TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier> = UnitForIdentifier<TIdentifier>> extends Omit<QueryStatisticsResponseRaw<TIdentifier, TUnit>, 'mostRecentQuantityDateInterval'> {
|
|
38
74
|
readonly mostRecentQuantityDateInterval?: {
|
|
39
75
|
readonly from: Date;
|
|
40
76
|
readonly to: Date;
|
|
41
77
|
};
|
|
42
78
|
}
|
|
79
|
+
/**
|
|
80
|
+
* Represents a category sample for saving.
|
|
81
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkcategorysample Apple Docs HKCategorySample}
|
|
82
|
+
*/
|
|
43
83
|
export type HKCategorySampleForSaving = Omit<HKCategorySample, 'device' | 'endDate' | 'startDate' | 'uuid'>;
|
|
84
|
+
/**
|
|
85
|
+
* Represents a quantity sample for saving.
|
|
86
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkquantitysample Apple Docs HKQuantitySample}
|
|
87
|
+
*/
|
|
44
88
|
export type HKQuantitySampleForSaving = Omit<HKQuantitySample, 'device' | 'endDate' | 'startDate' | 'uuid'>;
|
|
89
|
+
/**
|
|
90
|
+
* Represents a correlation.
|
|
91
|
+
* @template TIdentifier The correlation type identifier.
|
|
92
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkcorrelation Apple Docs HKCorrelation}
|
|
93
|
+
*/
|
|
45
94
|
export interface HKCorrelation<TIdentifier extends HKCorrelationTypeIdentifier> extends Omit<HKCorrelationRaw<TIdentifier>, 'endDate' | 'objects' | 'startDate'> {
|
|
46
95
|
readonly objects: readonly (HKCategorySample | HKQuantitySample)[];
|
|
47
96
|
readonly startDate: Date;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { HKCategoryTypeIdentifier } from '../native-types';
|
|
2
|
-
|
|
2
|
+
import type { HKCategorySample } from '../types';
|
|
3
|
+
declare function getMostRecentCategorySample<T extends HKCategoryTypeIdentifier>(identifier: T): Promise<HKCategorySample<T> | null>;
|
|
3
4
|
export default getMostRecentCategorySample;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
import type { HKQuantityTypeIdentifier, UnitForIdentifier } from '../native-types';
|
|
2
|
-
|
|
2
|
+
import type { HKQuantitySample } from '../types';
|
|
3
|
+
declare function getMostRecentQuantitySample<TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier>>(identifier: TIdentifier, unit: TUnit): Promise<HKQuantitySample<TIdentifier, TUnit> | null>;
|
|
3
4
|
export default getMostRecentQuantitySample;
|
package/package.json
CHANGED
|
@@ -2,6 +2,11 @@ import { useEffect, useState } from 'react'
|
|
|
2
2
|
|
|
3
3
|
import Native from '../native-types'
|
|
4
4
|
|
|
5
|
+
/**
|
|
6
|
+
* @description By default, HealthKit data is available on iOS and watchOS. HealthKit data is also available on iPadOS 17 or later. However, devices running in an enterprise environment may restrict access to HealthKit data.
|
|
7
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614180-ishealthdataavailable Apple HealthKit isHealthDataAvailable}
|
|
8
|
+
* @returns {boolean | null} true if HealthKit is available; otherwise, false. null while initializing.
|
|
9
|
+
*/
|
|
5
10
|
const useIsHealthDataAvailable = () => {
|
|
6
11
|
const [isAvailable, setIsAvailable] = useState<boolean | null>(null)
|
|
7
12
|
|
package/src/index.ios.tsx
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
|
+
import { Platform } from 'react-native'
|
|
2
|
+
|
|
1
3
|
import useHealthkitAuthorization from './hooks/useHealthkitAuthorization'
|
|
2
4
|
import useIsHealthDataAvailable from './hooks/useIsHealthDataAvailable'
|
|
3
5
|
import useMostRecentCategorySample from './hooks/useMostRecentCategorySample'
|
|
4
6
|
import useMostRecentQuantitySample from './hooks/useMostRecentQuantitySample'
|
|
5
7
|
import useMostRecentWorkout from './hooks/useMostRecentWorkout'
|
|
6
8
|
import useSubscribeToChanges from './hooks/useSubscribeToChanges'
|
|
7
|
-
import Native from './native-types'
|
|
9
|
+
import Native, { HKQuantityTypeIdentifier } from './native-types'
|
|
8
10
|
import deleteQuantitySample from './utils/deleteQuantitySample'
|
|
9
11
|
import deleteSamples from './utils/deleteSamples'
|
|
10
12
|
import getDateOfBirth from './utils/getDateOfBirth'
|
|
@@ -31,31 +33,123 @@ import saveQuantitySample from './utils/saveQuantitySample'
|
|
|
31
33
|
import saveWorkoutSample from './utils/saveWorkoutSample'
|
|
32
34
|
import subscribeToChanges from './utils/subscribeToChanges'
|
|
33
35
|
|
|
34
|
-
const
|
|
35
|
-
authorizationStatusFor: Native.authorizationStatusFor.bind(Native),
|
|
36
|
+
const currentMajorVersionIOS = Platform.OS === 'ios' ? parseInt(Platform.Version, 10) : 0
|
|
36
37
|
|
|
37
|
-
|
|
38
|
-
canAccessProtectedData: Native.canAccessProtectedData.bind(Native),
|
|
38
|
+
const allQuantityTypesList = [...Object.values(HKQuantityTypeIdentifier)]
|
|
39
39
|
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
const availableQuantityTypes = (majorVersionIOS = currentMajorVersionIOS) => {
|
|
41
|
+
if (majorVersionIOS >= 17) {
|
|
42
|
+
return allQuantityTypesList
|
|
43
|
+
}
|
|
44
44
|
|
|
45
|
-
//
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
45
|
+
// remove types that are not available before iOS 17
|
|
46
|
+
return allQuantityTypesList.filter((type) => ![
|
|
47
|
+
HKQuantityTypeIdentifier.cyclingCadence,
|
|
48
|
+
HKQuantityTypeIdentifier.cyclingFunctionalThresholdPower,
|
|
49
|
+
HKQuantityTypeIdentifier.cyclingPower,
|
|
50
|
+
HKQuantityTypeIdentifier.cyclingSpeed,
|
|
51
|
+
HKQuantityTypeIdentifier.physicalEffort,
|
|
52
|
+
HKQuantityTypeIdentifier.timeInDaylight,
|
|
53
|
+
].includes(type))
|
|
54
|
+
}
|
|
50
55
|
|
|
51
|
-
|
|
56
|
+
const authorizationStatusFor = Native.authorizationStatusFor.bind(Native)
|
|
57
|
+
const isHealthDataAvailable = Native.isHealthDataAvailable.bind(Native)
|
|
58
|
+
// Todo [>8]: Rename to align with Apple function name (isProtectedDataAvailable)
|
|
59
|
+
const canAccessProtectedData = Native.canAccessProtectedData.bind(Native)
|
|
60
|
+
const disableBackgroundDelivery = Native.disableBackgroundDelivery.bind(Native)
|
|
61
|
+
const disableAllBackgroundDelivery = Native.disableAllBackgroundDelivery.bind(Native)
|
|
62
|
+
const enableBackgroundDelivery = Native.enableBackgroundDelivery.bind(Native)
|
|
63
|
+
const getBiologicalSex = Native.getBiologicalSex.bind(Native)
|
|
64
|
+
const getFitzpatrickSkinType = Native.getFitzpatrickSkinType.bind(Native)
|
|
65
|
+
const getWheelchairUse = Native.getWheelchairUse.bind(Native)
|
|
66
|
+
const getBloodType = Native.getBloodType.bind(Native)
|
|
67
|
+
const getWorkoutRoutes = Native.getWorkoutRoutes.bind(Native)
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/about_the_healthkit_framework About the HealthKit Framework (Apple Docs)}
|
|
71
|
+
*/
|
|
72
|
+
export default {
|
|
73
|
+
/**
|
|
74
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614154-authorizationstatus authorizationStatus(for:) (Apple Docs) }
|
|
75
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/authorizing_access_to_health_data Authorizing access to health data (Apple Docs) }
|
|
76
|
+
*/
|
|
77
|
+
authorizationStatusFor,
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
*
|
|
81
|
+
* @returns All available quantity types for the current iOS version (currently excluding types that are not available before iOS 17)
|
|
82
|
+
*/
|
|
83
|
+
availableQuantityTypes,
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* @description By default, HealthKit data is available on iOS and watchOS. HealthKit data is also available on iPadOS 17 or later. However, devices running in an enterprise environment may restrict access to HealthKit data.
|
|
87
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614180-ishealthdataavailable isHealthDataAvailable() (Apple Docs)}
|
|
88
|
+
* @returns {boolean} true if HealthKit is available; otherwise, false.
|
|
89
|
+
*/
|
|
90
|
+
isHealthDataAvailable,
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614181-isprotecteddataavailable isProtectedDataAvailable() (Apple Docs)}
|
|
94
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/protecting_user_privacy#3705074 Protecting User Privacy - Access encrypted data (Apple Docs)}
|
|
95
|
+
* @returns {boolean} A Boolean value that indicates whether content protection is active.
|
|
96
|
+
*/
|
|
97
|
+
isProtectedDataAvailable: canAccessProtectedData,
|
|
98
|
+
|
|
99
|
+
// Todo [>8]: Remove to align with Apple function name (isProtectedDataAvailable)
|
|
100
|
+
/**
|
|
101
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614181-isprotecteddataavailable isProtectedDataAvailable() (Apple Docs)}
|
|
102
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/protecting_user_privacy#3705074 Protecting User Privacy - Access encrypted data (Apple Docs)}
|
|
103
|
+
* @deprecated Use {@link isProtectedDataAvailable} instead. Will be removed in next major version.
|
|
104
|
+
* @returns {boolean} A Boolean value that indicates whether content protection is active.
|
|
105
|
+
*/
|
|
106
|
+
canAccessProtectedData,
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614158-disableallbackgrounddelivery disableAllBackgroundDelivery(completion:) (Apple Docs)}
|
|
110
|
+
*/
|
|
111
|
+
disableAllBackgroundDelivery,
|
|
112
|
+
/**
|
|
113
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614177-disablebackgrounddelivery disableBackgroundDelivery(for:withCompletion:) (Apple Docs)}
|
|
114
|
+
*/
|
|
115
|
+
disableBackgroundDelivery,
|
|
116
|
+
/**
|
|
117
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614175-enablebackgrounddelivery enableBackgroundDelivery(for:frequency:withCompletion:) (Apple Docs)}
|
|
118
|
+
*/
|
|
119
|
+
enableBackgroundDelivery,
|
|
52
120
|
|
|
121
|
+
// simple convenience getters
|
|
122
|
+
/**
|
|
123
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614171-biologicalsex biologicalSex() (Apple Docs)}
|
|
124
|
+
*/
|
|
125
|
+
getBiologicalSex,
|
|
126
|
+
/**
|
|
127
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614161-fitzpatrickskintype fitzpatrickSkinType() (Apple Docs)}
|
|
128
|
+
*/
|
|
129
|
+
getFitzpatrickSkinType,
|
|
130
|
+
/**
|
|
131
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1648356-wheelchairuse wheelchairUse() (Apple Docs)}
|
|
132
|
+
*/
|
|
133
|
+
getWheelchairUse,
|
|
134
|
+
/**
|
|
135
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614164-bloodtype bloodType() (Apple Docs)}
|
|
136
|
+
*/
|
|
137
|
+
getBloodType,
|
|
138
|
+
/**
|
|
139
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1648357-dateofbirthcomponents dateOfBirthComponents() (Apple Docs)}
|
|
140
|
+
*/
|
|
53
141
|
getDateOfBirth,
|
|
54
142
|
|
|
55
143
|
getMostRecentQuantitySample,
|
|
56
144
|
getMostRecentCategorySample,
|
|
57
145
|
getMostRecentWorkout,
|
|
58
146
|
|
|
147
|
+
/**
|
|
148
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/workouts_and_activity_rings/reading_route_data Reading route data (Apple Docs)}
|
|
149
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkworkoutroutequery HKWorkoutRouteQuery (Apple Docs)}
|
|
150
|
+
*/
|
|
151
|
+
getWorkoutRoutes,
|
|
152
|
+
|
|
59
153
|
getPreferredUnit,
|
|
60
154
|
getPreferredUnits,
|
|
61
155
|
getRequestStatusForAuthorization,
|
|
@@ -79,6 +173,10 @@ const Healthkit = {
|
|
|
79
173
|
deleteSamples,
|
|
80
174
|
|
|
81
175
|
// save methods
|
|
176
|
+
/**
|
|
177
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614168-savecategorysample save(_:withCompletion:) (Apple Docs)}
|
|
178
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/saving_data_to_healthkit Saving data to HealthKit (Apple Docs)}
|
|
179
|
+
*/
|
|
82
180
|
saveCategorySample,
|
|
83
181
|
saveCorrelationSample,
|
|
84
182
|
saveQuantitySample,
|
|
@@ -87,18 +185,31 @@ const Healthkit = {
|
|
|
87
185
|
// subscriptions
|
|
88
186
|
subscribeToChanges,
|
|
89
187
|
|
|
90
|
-
|
|
188
|
+
/**
|
|
189
|
+
* @returns the most recent sample for the given category type.
|
|
190
|
+
*/
|
|
91
191
|
useMostRecentCategorySample,
|
|
92
|
-
|
|
192
|
+
/**
|
|
193
|
+
* @returns the most recent sample for the given quantity type.
|
|
194
|
+
*/
|
|
93
195
|
useMostRecentQuantitySample,
|
|
196
|
+
/**
|
|
197
|
+
* @returns the most recent workout sample.
|
|
198
|
+
*/
|
|
94
199
|
useMostRecentWorkout,
|
|
95
|
-
|
|
96
200
|
useSubscribeToChanges,
|
|
97
|
-
|
|
201
|
+
/**
|
|
202
|
+
* @description By default, HealthKit data is available on iOS and watchOS. HealthKit data is also available on iPadOS 17 or later. However, devices running in an enterprise environment may restrict access to HealthKit data.
|
|
203
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614180-ishealthdataavailable Apple Docs}
|
|
204
|
+
* @returns {boolean | null} true if HealthKit is available; otherwise, false. null while initializing.
|
|
205
|
+
*/
|
|
98
206
|
useIsHealthDataAvailable,
|
|
207
|
+
/**
|
|
208
|
+
* @description Hook to retrieve the current authorization status for the given types, and request authorization if needed.
|
|
209
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614152-requestauthorization Apple Docs - requestAuthorization}
|
|
210
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/authorizing_access_to_health_data Apple Docs - Authorizing access to health data}
|
|
211
|
+
*/
|
|
99
212
|
useHealthkitAuthorization,
|
|
100
213
|
}
|
|
101
214
|
|
|
102
215
|
export * from './types'
|
|
103
|
-
|
|
104
|
-
export default Healthkit
|
package/src/index.tsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Platform } from 'react-native'
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
|
-
HKAuthorizationRequestStatus, HKAuthorizationStatus, HKBiologicalSex, HKBloodType, HKFitzpatrickSkinType, HKUnits, HKWheelchairUse,
|
|
4
|
+
HKAuthorizationRequestStatus, HKAuthorizationStatus, HKBiologicalSex, HKBloodType, HKFitzpatrickSkinType, HKUnits, HKWheelchairUse,
|
|
5
5
|
} from './native-types'
|
|
6
6
|
|
|
7
7
|
import type ReactNativeHealthkit from './index.ios'
|
|
@@ -25,8 +25,9 @@ function UnavailableFn<T = unknown>(retVal: T) {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
const Healthkit
|
|
28
|
+
const Healthkit = {
|
|
29
29
|
authorizationStatusFor: UnavailableFn(Promise.resolve(HKAuthorizationStatus.notDetermined)),
|
|
30
|
+
availableQuantityTypes: UnavailableFn([]),
|
|
30
31
|
disableAllBackgroundDelivery: UnavailableFn(Promise.resolve(false)),
|
|
31
32
|
disableBackgroundDelivery: UnavailableFn(Promise.resolve(false)),
|
|
32
33
|
enableBackgroundDelivery: UnavailableFn(Promise.resolve(false)),
|
|
@@ -88,8 +89,9 @@ const Healthkit: typeof ReactNativeHealthkit = {
|
|
|
88
89
|
useHealthkitAuthorization: UnavailableFn([null, async () => Promise.resolve(HKAuthorizationRequestStatus.unknown)] as const),
|
|
89
90
|
useIsHealthDataAvailable: () => false,
|
|
90
91
|
canAccessProtectedData: async () => Promise.resolve(false),
|
|
91
|
-
|
|
92
|
+
isProtectedDataAvailable: async () => Promise.resolve(false),
|
|
93
|
+
} as typeof ReactNativeHealthkit
|
|
92
94
|
|
|
93
95
|
export * from './types'
|
|
94
96
|
|
|
95
|
-
export default Healthkit
|
|
97
|
+
export default Healthkit as typeof ReactNativeHealthkit
|
package/src/jest.setup.ts
CHANGED
|
@@ -37,6 +37,7 @@ const mockModule: (NativeModule & typeof Native) = {
|
|
|
37
37
|
saveWorkoutSample: jest.fn(),
|
|
38
38
|
subscribeToObserverQuery: jest.fn(),
|
|
39
39
|
unsubscribeQuery: jest.fn(),
|
|
40
|
+
// Todo [>8]: Remove to align with Apple function name (isProtectedDataAvailable)
|
|
40
41
|
canAccessProtectedData: jest.fn(),
|
|
41
42
|
}
|
|
42
43
|
|