@kingstinct/react-native-healthkit 7.3.1 → 8.0.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 +1 -1
- package/ios/Constants.swift +1 -1
- package/ios/ReactNativeHealthkit.m +1 -1
- package/ios/ReactNativeHealthkit.swift +2 -2
- package/ios/Serializers.swift +12 -0
- package/lib/commonjs/hooks/useHealthkitAuthorization.js +2 -3
- package/lib/commonjs/hooks/useHealthkitAuthorization.js.map +1 -1
- package/lib/commonjs/hooks/useHealthkitAuthorization.test.js +42 -19
- package/lib/commonjs/hooks/useHealthkitAuthorization.test.js.map +1 -1
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js +2 -3
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js.map +1 -1
- package/lib/commonjs/hooks/useIsHealthDataAvailable.test.js +17 -8
- package/lib/commonjs/hooks/useIsHealthDataAvailable.test.js.map +1 -1
- package/lib/commonjs/hooks/useMostRecentCategorySample.js +2 -3
- package/lib/commonjs/hooks/useMostRecentCategorySample.js.map +1 -1
- package/lib/commonjs/hooks/useMostRecentQuantitySample.js +4 -3
- package/lib/commonjs/hooks/useMostRecentQuantitySample.js.map +1 -1
- package/lib/commonjs/hooks/useMostRecentWorkout.js +2 -3
- package/lib/commonjs/hooks/useMostRecentWorkout.js.map +1 -1
- package/lib/commonjs/hooks/useSources.js +2 -3
- package/lib/commonjs/hooks/useSources.js.map +1 -1
- package/lib/commonjs/hooks/useStatisticsForQuantity.js +2 -3
- package/lib/commonjs/hooks/useStatisticsForQuantity.js.map +1 -1
- package/lib/commonjs/hooks/useSubscribeToChanges.js +2 -3
- package/lib/commonjs/hooks/useSubscribeToChanges.js.map +1 -1
- package/lib/commonjs/index.ios.js +471 -0
- package/lib/commonjs/index.ios.js.map +1 -0
- package/lib/commonjs/index.js +9 -482
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.native.js +46 -95
- package/lib/commonjs/index.native.js.map +1 -1
- package/lib/commonjs/index.web.js +7 -1
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/native-types.js +65 -90
- package/lib/commonjs/native-types.js.map +1 -1
- package/lib/commonjs/test-setup.js +51 -0
- package/lib/commonjs/test-setup.js.map +1 -0
- package/lib/commonjs/test-utils.js +1 -2
- package/lib/commonjs/test-utils.js.map +1 -1
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/deleteQuantitySample.js +2 -3
- package/lib/commonjs/utils/deleteQuantitySample.js.map +1 -1
- package/lib/commonjs/utils/deleteSamples.js +2 -3
- package/lib/commonjs/utils/deleteSamples.js.map +1 -1
- package/lib/commonjs/utils/deserializeCategorySample.js +1 -2
- package/lib/commonjs/utils/deserializeCategorySample.js.map +1 -1
- package/lib/commonjs/utils/deserializeCategorySample.test.js +8 -4
- package/lib/commonjs/utils/deserializeCategorySample.test.js.map +1 -1
- package/lib/commonjs/utils/deserializeCorrelation.js +2 -3
- package/lib/commonjs/utils/deserializeCorrelation.js.map +1 -1
- package/lib/commonjs/utils/deserializeHeartbeatSeriesSample.js +1 -2
- package/lib/commonjs/utils/deserializeHeartbeatSeriesSample.js.map +1 -1
- package/lib/commonjs/utils/deserializeSample.js +1 -2
- package/lib/commonjs/utils/deserializeSample.js.map +1 -1
- package/lib/commonjs/utils/deserializeWorkout.js +1 -2
- package/lib/commonjs/utils/deserializeWorkout.js.map +1 -1
- package/lib/commonjs/utils/ensureMetadata.js +1 -2
- package/lib/commonjs/utils/ensureMetadata.js.map +1 -1
- package/lib/commonjs/utils/ensureTotals.js +1 -2
- package/lib/commonjs/utils/ensureTotals.js.map +1 -1
- package/lib/commonjs/utils/ensureUnit.js +2 -3
- package/lib/commonjs/utils/ensureUnit.js.map +1 -1
- package/lib/commonjs/utils/getDateOfBirth.js +2 -3
- package/lib/commonjs/utils/getDateOfBirth.js.map +1 -1
- package/lib/commonjs/utils/getMostRecentCategorySample.js +2 -3
- package/lib/commonjs/utils/getMostRecentCategorySample.js.map +1 -1
- package/lib/commonjs/utils/getMostRecentQuantitySample.js +2 -3
- package/lib/commonjs/utils/getMostRecentQuantitySample.js.map +1 -1
- package/lib/commonjs/utils/getMostRecentWorkout.js +2 -3
- package/lib/commonjs/utils/getMostRecentWorkout.js.map +1 -1
- package/lib/commonjs/utils/getPreferredUnit.js +2 -3
- package/lib/commonjs/utils/getPreferredUnit.js.map +1 -1
- package/lib/commonjs/utils/getPreferredUnits.js +2 -3
- package/lib/commonjs/utils/getPreferredUnits.js.map +1 -1
- package/lib/commonjs/utils/getPreferredUnitsTyped.js +3 -4
- package/lib/commonjs/utils/getPreferredUnitsTyped.js.map +1 -1
- package/lib/commonjs/utils/getRequestStatusForAuthorization.js +3 -5
- package/lib/commonjs/utils/getRequestStatusForAuthorization.js.map +1 -1
- package/lib/commonjs/utils/getWorkoutPlanById.js +2 -3
- package/lib/commonjs/utils/getWorkoutPlanById.js.map +1 -1
- package/lib/commonjs/utils/prepareOptions.js +3 -3
- package/lib/commonjs/utils/prepareOptions.js.map +1 -1
- package/lib/commonjs/utils/queryCategorySamples.js +2 -3
- package/lib/commonjs/utils/queryCategorySamples.js.map +1 -1
- package/lib/commonjs/utils/queryCategorySamplesWithAnchor.js +2 -3
- package/lib/commonjs/utils/queryCategorySamplesWithAnchor.js.map +1 -1
- package/lib/commonjs/utils/queryCorrelationSamples.js +2 -3
- package/lib/commonjs/utils/queryCorrelationSamples.js.map +1 -1
- package/lib/commonjs/utils/queryHeartbeatSeriesSamples.js +2 -3
- package/lib/commonjs/utils/queryHeartbeatSeriesSamples.js.map +1 -1
- package/lib/commonjs/utils/queryHeartbeatSeriesSamplesWithAnchor.js +2 -3
- package/lib/commonjs/utils/queryHeartbeatSeriesSamplesWithAnchor.js.map +1 -1
- package/lib/commonjs/utils/queryQuantitySamples.js +2 -3
- package/lib/commonjs/utils/queryQuantitySamples.js.map +1 -1
- package/lib/commonjs/utils/queryQuantitySamplesWithAnchor.js +2 -3
- package/lib/commonjs/utils/queryQuantitySamplesWithAnchor.js.map +1 -1
- package/lib/commonjs/utils/querySources.js +2 -3
- package/lib/commonjs/utils/querySources.js.map +1 -1
- package/lib/commonjs/utils/queryStatisticsForQuantity.js +2 -3
- package/lib/commonjs/utils/queryStatisticsForQuantity.js.map +1 -1
- package/lib/commonjs/utils/queryWorkouts.js +2 -3
- package/lib/commonjs/utils/queryWorkouts.js.map +1 -1
- package/lib/commonjs/utils/requestAuthorization.js +3 -5
- package/lib/commonjs/utils/requestAuthorization.js.map +1 -1
- package/lib/commonjs/utils/saveCategorySample.js +2 -3
- package/lib/commonjs/utils/saveCategorySample.js.map +1 -1
- package/lib/commonjs/utils/saveCorrelationSample.js +2 -3
- package/lib/commonjs/utils/saveCorrelationSample.js.map +1 -1
- package/lib/commonjs/utils/saveQuantitySample.js +2 -3
- package/lib/commonjs/utils/saveQuantitySample.js.map +1 -1
- package/lib/commonjs/utils/saveWorkoutRoute.js +2 -3
- package/lib/commonjs/utils/saveWorkoutRoute.js.map +1 -1
- package/lib/commonjs/utils/saveWorkoutSample.js +2 -3
- package/lib/commonjs/utils/saveWorkoutSample.js.map +1 -1
- package/lib/commonjs/utils/serializeDate.js +1 -2
- package/lib/commonjs/utils/serializeDate.js.map +1 -1
- package/lib/commonjs/utils/serializeDate.test.js +1 -1
- package/lib/commonjs/utils/serializeDate.test.js.map +1 -1
- package/lib/commonjs/utils/subscribeToChanges.js +6 -8
- package/lib/commonjs/utils/subscribeToChanges.js.map +1 -1
- package/lib/module/hooks/useHealthkitAuthorization.js.map +1 -1
- package/lib/module/hooks/useHealthkitAuthorization.test.js +26 -3
- package/lib/module/hooks/useHealthkitAuthorization.test.js.map +1 -1
- package/lib/module/hooks/useIsHealthDataAvailable.js.map +1 -1
- package/lib/module/hooks/useIsHealthDataAvailable.test.js +9 -2
- package/lib/module/hooks/useIsHealthDataAvailable.test.js.map +1 -1
- package/lib/module/hooks/useMostRecentCategorySample.js.map +1 -1
- package/lib/module/hooks/useMostRecentQuantitySample.js +2 -0
- package/lib/module/hooks/useMostRecentQuantitySample.js.map +1 -1
- package/lib/module/hooks/useMostRecentWorkout.js.map +1 -1
- package/lib/module/hooks/useSources.js.map +1 -1
- package/lib/module/hooks/useStatisticsForQuantity.js.map +1 -1
- package/lib/module/hooks/useSubscribeToChanges.js.map +1 -1
- package/lib/module/index.ios.js +188 -0
- package/lib/module/index.ios.js.map +1 -0
- package/lib/module/index.js +3 -198
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.native.js +1 -3
- package/lib/module/index.native.js.map +1 -1
- package/lib/module/index.web.js +2 -0
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/native-types.js +21 -2
- package/lib/module/native-types.js.map +1 -1
- package/lib/module/test-setup.js +48 -0
- package/lib/module/test-setup.js.map +1 -0
- package/lib/module/test-utils.js.map +1 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/deleteQuantitySample.js.map +1 -1
- package/lib/module/utils/deleteSamples.js.map +1 -1
- package/lib/module/utils/deserializeCategorySample.js.map +1 -1
- package/lib/module/utils/deserializeCategorySample.test.js +4 -2
- package/lib/module/utils/deserializeCategorySample.test.js.map +1 -1
- package/lib/module/utils/deserializeCorrelation.js.map +1 -1
- package/lib/module/utils/deserializeHeartbeatSeriesSample.js.map +1 -1
- package/lib/module/utils/deserializeSample.js.map +1 -1
- package/lib/module/utils/deserializeWorkout.js.map +1 -1
- package/lib/module/utils/ensureMetadata.js.map +1 -1
- package/lib/module/utils/ensureTotals.js.map +1 -1
- package/lib/module/utils/ensureUnit.js.map +1 -1
- package/lib/module/utils/getDateOfBirth.js.map +1 -1
- package/lib/module/utils/getMostRecentCategorySample.js.map +1 -1
- package/lib/module/utils/getMostRecentQuantitySample.js.map +1 -1
- package/lib/module/utils/getMostRecentWorkout.js.map +1 -1
- package/lib/module/utils/getPreferredUnit.js.map +1 -1
- package/lib/module/utils/getPreferredUnits.js.map +1 -1
- package/lib/module/utils/getPreferredUnitsTyped.js.map +1 -1
- package/lib/module/utils/getRequestStatusForAuthorization.js +1 -2
- package/lib/module/utils/getRequestStatusForAuthorization.js.map +1 -1
- package/lib/module/utils/getWorkoutPlanById.js.map +1 -1
- package/lib/module/utils/prepareOptions.js +1 -0
- package/lib/module/utils/prepareOptions.js.map +1 -1
- package/lib/module/utils/queryCategorySamples.js.map +1 -1
- package/lib/module/utils/queryCategorySamplesWithAnchor.js.map +1 -1
- package/lib/module/utils/queryCorrelationSamples.js.map +1 -1
- package/lib/module/utils/queryHeartbeatSeriesSamples.js.map +1 -1
- package/lib/module/utils/queryHeartbeatSeriesSamplesWithAnchor.js.map +1 -1
- package/lib/module/utils/queryQuantitySamples.js.map +1 -1
- package/lib/module/utils/queryQuantitySamplesWithAnchor.js.map +1 -1
- package/lib/module/utils/querySources.js.map +1 -1
- package/lib/module/utils/queryStatisticsForQuantity.js.map +1 -1
- package/lib/module/utils/queryWorkouts.js.map +1 -1
- package/lib/module/utils/requestAuthorization.js +1 -2
- package/lib/module/utils/requestAuthorization.js.map +1 -1
- package/lib/module/utils/saveCategorySample.js.map +1 -1
- package/lib/module/utils/saveCorrelationSample.js.map +1 -1
- package/lib/module/utils/saveQuantitySample.js.map +1 -1
- package/lib/module/utils/saveWorkoutRoute.js.map +1 -1
- package/lib/module/utils/saveWorkoutSample.js.map +1 -1
- package/lib/module/utils/serializeDate.js.map +1 -1
- package/lib/module/utils/serializeDate.test.js.map +1 -1
- package/lib/module/utils/subscribeToChanges.js +3 -4
- package/lib/module/utils/subscribeToChanges.js.map +1 -1
- package/lib/typescript/src/index.d.ts +3 -180
- package/lib/typescript/src/index.ios.d.ts +172 -0
- package/lib/typescript/src/index.native.d.ts +3 -3
- package/lib/typescript/src/index.web.d.ts +2 -0
- package/lib/typescript/src/native-types.d.ts +86 -8
- package/package.json +16 -11
- package/src/hooks/useHealthkitAuthorization.test.ts +18 -4
- package/src/hooks/useIsHealthDataAvailable.test.ts +5 -2
- package/src/hooks/useIsHealthDataAvailable.ts +1 -1
- package/src/hooks/useMostRecentQuantitySample.ts +3 -0
- package/src/index.ios.tsx +263 -0
- package/src/index.native.tsx +1 -4
- package/src/index.tsx +3 -274
- package/src/index.web.tsx +4 -0
- package/src/native-types.ts +97 -9
- package/src/test-setup.ts +51 -0
- package/src/utils/deserializeCategorySample.test.ts +5 -2
- package/src/utils/prepareOptions.ts +1 -0
- package/lib/commonjs/jest.setup.js +0 -45
- package/lib/commonjs/jest.setup.js.map +0 -1
- package/lib/module/jest.setup.js +0 -43
- package/lib/module/jest.setup.js.map +0 -1
- package/src/jest.setup.ts +0 -46
- /package/lib/typescript/src/{jest.setup.d.ts → test-setup.d.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kingstinct/react-native-healthkit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.0",
|
|
4
4
|
"description": "React Native bindings for HealthKit",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -20,15 +20,15 @@
|
|
|
20
20
|
"app.plugin.js"
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
|
-
"test-only": "
|
|
24
|
-
"test": "concurrently \"
|
|
23
|
+
"test-only": "bun test --preload ./src/test-setup.ts src",
|
|
24
|
+
"test": "concurrently \"bun test-only\" \"bun typecheck\" \"bun lint\"",
|
|
25
25
|
"typecheck": "tsc --noEmit",
|
|
26
26
|
"lint": "eslint \"**/*.{js,ts,tsx}\" --cache",
|
|
27
27
|
"prepare": "bob build && husky install",
|
|
28
28
|
"release": "release-it",
|
|
29
|
-
"example": "yarn --cwd example",
|
|
30
29
|
"pods": "cd example && pod-install --quiet",
|
|
31
|
-
"bootstrap": "
|
|
30
|
+
"bootstrap": "cd example && bun install && bun pods",
|
|
31
|
+
"upgrade-interactive": "bunx npm-check-updates --format group -i"
|
|
32
32
|
},
|
|
33
33
|
"lint-staged": {
|
|
34
34
|
"*.swift": "swiftlint ios --fix",
|
|
@@ -44,7 +44,15 @@
|
|
|
44
44
|
"react-hooks"
|
|
45
45
|
],
|
|
46
46
|
"repository": "https://github.com/kingstinct/react-native-healthkit",
|
|
47
|
-
"
|
|
47
|
+
"funding": [
|
|
48
|
+
"https://github.com/sponsors/kingstinct",
|
|
49
|
+
"https://github.com/sponsors/robertherber"
|
|
50
|
+
],
|
|
51
|
+
"author": {
|
|
52
|
+
"name": "Robert Herber",
|
|
53
|
+
"email": "robert@kingstinct.com",
|
|
54
|
+
"url": "https://github.com/robertherber"
|
|
55
|
+
},
|
|
48
56
|
"license": "MIT",
|
|
49
57
|
"bugs": {
|
|
50
58
|
"url": "https://github.com/kingstinct/react-native-healthkit/issues"
|
|
@@ -58,14 +66,14 @@
|
|
|
58
66
|
"@graphql-eslint/eslint-plugin": ">=3",
|
|
59
67
|
"@release-it/conventional-changelog": "2",
|
|
60
68
|
"@testing-library/react-native": "12",
|
|
61
|
-
"@types/
|
|
69
|
+
"@types/bun": "^1.1.3",
|
|
62
70
|
"@types/node": "^18.7.14",
|
|
63
71
|
"@types/react": "~18.0.27",
|
|
64
72
|
"@typescript-eslint/eslint-plugin": ">=5",
|
|
65
73
|
"@typescript-eslint/parser": ">=5",
|
|
66
74
|
"commitlint": "^17.1.1",
|
|
67
75
|
"concurrently": "8",
|
|
68
|
-
"eslint": "
|
|
76
|
+
"eslint": "8",
|
|
69
77
|
"eslint-config-airbnb": ">=19",
|
|
70
78
|
"eslint-config-airbnb-base": ">=15",
|
|
71
79
|
"eslint-config-kingstinct": "^5.1.1",
|
|
@@ -85,8 +93,6 @@
|
|
|
85
93
|
"expo": ">=45",
|
|
86
94
|
"graphql": ">=16",
|
|
87
95
|
"husky": "8",
|
|
88
|
-
"jest": ">=26",
|
|
89
|
-
"jest-environment-jsdom": "^29.0.2",
|
|
90
96
|
"lint-staged": "^13.2.2",
|
|
91
97
|
"metro-react-native-babel-preset": "^0.70.3",
|
|
92
98
|
"pod-install": "^0.1.0",
|
|
@@ -97,7 +103,6 @@
|
|
|
97
103
|
"release-it": "14",
|
|
98
104
|
"solidarity": "^3.0.4",
|
|
99
105
|
"solidarity-react-native": "^2.1.2",
|
|
100
|
-
"ts-node": "^10.9.1",
|
|
101
106
|
"typescript": "^4.9.4"
|
|
102
107
|
},
|
|
103
108
|
"peerDependencies": {
|
|
@@ -1,11 +1,18 @@
|
|
|
1
1
|
import { renderHook, act } from '@testing-library/react-native'
|
|
2
2
|
|
|
3
|
-
import useHealthkitAuthorization from './useHealthkitAuthorization'
|
|
4
|
-
import Native, { HKAuthorizationRequestStatus, HKCategoryTypeIdentifier } from '../native-types'
|
|
5
3
|
import waitForNextUpdate from '../test-utils'
|
|
6
4
|
|
|
7
5
|
describe('useHealthkitAuthorization', () => {
|
|
6
|
+
let NativeTypes: typeof import('../native-types')
|
|
7
|
+
let useHealthkitAuthorization: typeof import('./useHealthkitAuthorization').default
|
|
8
|
+
beforeAll(async () => {
|
|
9
|
+
NativeTypes = await import('../native-types')
|
|
10
|
+
useHealthkitAuthorization = (await import('./useHealthkitAuthorization')).default
|
|
11
|
+
})
|
|
12
|
+
|
|
8
13
|
test('should return shouldRequest', async () => {
|
|
14
|
+
const { HKAuthorizationRequestStatus, HKCategoryTypeIdentifier, default: Native } = NativeTypes
|
|
15
|
+
|
|
9
16
|
jest.spyOn(Native, 'getRequestStatusForAuthorization').mockReturnValue(Promise.resolve(HKAuthorizationRequestStatus.shouldRequest))
|
|
10
17
|
|
|
11
18
|
const { result } = renderHook(() => useHealthkitAuthorization([HKCategoryTypeIdentifier.abdominalCramps]))
|
|
@@ -16,6 +23,8 @@ describe('useHealthkitAuthorization', () => {
|
|
|
16
23
|
})
|
|
17
24
|
|
|
18
25
|
test('should request permissions', async () => {
|
|
26
|
+
const { HKAuthorizationRequestStatus, HKCategoryTypeIdentifier, default: Native } = NativeTypes
|
|
27
|
+
|
|
19
28
|
const spy = jest.spyOn(Native, 'getRequestStatusForAuthorization').mockReturnValue(Promise.resolve(HKAuthorizationRequestStatus.shouldRequest))
|
|
20
29
|
jest.spyOn(Native, 'requestAuthorization').mockReturnValue(Promise.resolve(true))
|
|
21
30
|
|
|
@@ -25,9 +34,10 @@ describe('useHealthkitAuthorization', () => {
|
|
|
25
34
|
|
|
26
35
|
spy.mockReturnValue(Promise.resolve(HKAuthorizationRequestStatus.unnecessary))
|
|
27
36
|
|
|
28
|
-
let retVal: HKAuthorizationRequestStatus | undefined
|
|
37
|
+
let retVal: typeof HKAuthorizationRequestStatus | undefined
|
|
29
38
|
await act(async () => {
|
|
30
|
-
|
|
39
|
+
const r = await result.current[1]() as unknown as typeof HKAuthorizationRequestStatus
|
|
40
|
+
retVal = r
|
|
31
41
|
})
|
|
32
42
|
|
|
33
43
|
expect(result.current[0]).toBe(HKAuthorizationRequestStatus.unnecessary)
|
|
@@ -35,6 +45,8 @@ describe('useHealthkitAuthorization', () => {
|
|
|
35
45
|
})
|
|
36
46
|
|
|
37
47
|
test('should return unnecessary', async () => {
|
|
48
|
+
const { HKAuthorizationRequestStatus, HKCategoryTypeIdentifier, default: Native } = NativeTypes
|
|
49
|
+
|
|
38
50
|
jest.spyOn(Native, 'getRequestStatusForAuthorization').mockReturnValue(Promise.resolve(HKAuthorizationRequestStatus.unnecessary))
|
|
39
51
|
|
|
40
52
|
const { result } = renderHook(() => useHealthkitAuthorization([HKCategoryTypeIdentifier.abdominalCramps]))
|
|
@@ -45,6 +57,8 @@ describe('useHealthkitAuthorization', () => {
|
|
|
45
57
|
})
|
|
46
58
|
|
|
47
59
|
test('should return null before initalizing', async () => {
|
|
60
|
+
const { HKCategoryTypeIdentifier } = NativeTypes
|
|
61
|
+
|
|
48
62
|
const { result } = renderHook(() => useHealthkitAuthorization([HKCategoryTypeIdentifier.abdominalCramps]))
|
|
49
63
|
|
|
50
64
|
expect(result.current[0]).toBe(null)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { renderHook } from '@testing-library/react-native'
|
|
2
2
|
|
|
3
|
-
import useIsHealthDataAvailable from './useIsHealthDataAvailable'
|
|
4
|
-
import Native from '../native-types'
|
|
5
3
|
import waitForNextUpdate from '../test-utils'
|
|
6
4
|
|
|
7
5
|
describe('useIsHealthDataAvailable', () => {
|
|
8
6
|
test('should return false', async () => {
|
|
7
|
+
const useIsHealthDataAvailable = (await import('./useIsHealthDataAvailable')).default
|
|
8
|
+
const { default: Native } = await import('../native-types')
|
|
9
9
|
jest.spyOn(Native, 'isHealthDataAvailable').mockReturnValue(Promise.resolve(false))
|
|
10
10
|
|
|
11
11
|
const { result } = renderHook(useIsHealthDataAvailable)
|
|
@@ -16,6 +16,8 @@ describe('useIsHealthDataAvailable', () => {
|
|
|
16
16
|
})
|
|
17
17
|
|
|
18
18
|
test('should return true', async () => {
|
|
19
|
+
const useIsHealthDataAvailable = (await import('./useIsHealthDataAvailable')).default
|
|
20
|
+
const { default: Native } = await import('../native-types')
|
|
19
21
|
jest.spyOn(Native, 'isHealthDataAvailable').mockReturnValue(Promise.resolve(true))
|
|
20
22
|
|
|
21
23
|
const { result } = renderHook(useIsHealthDataAvailable)
|
|
@@ -26,6 +28,7 @@ describe('useIsHealthDataAvailable', () => {
|
|
|
26
28
|
})
|
|
27
29
|
|
|
28
30
|
test('should return null before initalizing', async () => {
|
|
31
|
+
const useIsHealthDataAvailable = (await import('./useIsHealthDataAvailable')).default
|
|
29
32
|
const { result } = renderHook(useIsHealthDataAvailable)
|
|
30
33
|
|
|
31
34
|
expect(result.current).toBe(null)
|
|
@@ -7,7 +7,7 @@ import Native from '../native-types'
|
|
|
7
7
|
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614180-ishealthdataavailable Apple HealthKit isHealthDataAvailable}
|
|
8
8
|
* @returns {boolean | null} true if HealthKit is available; otherwise, false. null while initializing.
|
|
9
9
|
*/
|
|
10
|
-
const useIsHealthDataAvailable = () => {
|
|
10
|
+
const useIsHealthDataAvailable = (): boolean | null => {
|
|
11
11
|
const [isAvailable, setIsAvailable] = useState<boolean | null>(null)
|
|
12
12
|
|
|
13
13
|
useEffect(() => {
|
|
@@ -24,6 +24,9 @@ function useMostRecentQuantitySample<
|
|
|
24
24
|
const init = async () => {
|
|
25
25
|
const actualUnit = await ensureUnit(identifier, unit)
|
|
26
26
|
|
|
27
|
+
const value = await getMostRecentQuantitySample(identifier, actualUnit)
|
|
28
|
+
setLastSample(value)
|
|
29
|
+
|
|
27
30
|
cancelSubscription = await subscribeToChanges(identifier, async () => {
|
|
28
31
|
const value = await getMostRecentQuantitySample(identifier, actualUnit)
|
|
29
32
|
setLastSample(value)
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
import { Platform } from 'react-native'
|
|
2
|
+
|
|
3
|
+
import useHealthkitAuthorization from './hooks/useHealthkitAuthorization'
|
|
4
|
+
import useIsHealthDataAvailable from './hooks/useIsHealthDataAvailable'
|
|
5
|
+
import useMostRecentCategorySample from './hooks/useMostRecentCategorySample'
|
|
6
|
+
import useMostRecentQuantitySample from './hooks/useMostRecentQuantitySample'
|
|
7
|
+
import useMostRecentWorkout from './hooks/useMostRecentWorkout'
|
|
8
|
+
import useSources from './hooks/useSources'
|
|
9
|
+
import useStatisticsForQuantity from './hooks/useStatisticsForQuantity'
|
|
10
|
+
import useSubscribeToChanges from './hooks/useSubscribeToChanges'
|
|
11
|
+
import Native, { HKQuantityTypeIdentifier } from './native-types'
|
|
12
|
+
import deleteQuantitySample from './utils/deleteQuantitySample'
|
|
13
|
+
import deleteSamples from './utils/deleteSamples'
|
|
14
|
+
import getDateOfBirth from './utils/getDateOfBirth'
|
|
15
|
+
import getMostRecentCategorySample from './utils/getMostRecentCategorySample'
|
|
16
|
+
import getMostRecentQuantitySample from './utils/getMostRecentQuantitySample'
|
|
17
|
+
import getMostRecentWorkout from './utils/getMostRecentWorkout'
|
|
18
|
+
import getPreferredUnit from './utils/getPreferredUnit'
|
|
19
|
+
import getPreferredUnits from './utils/getPreferredUnits'
|
|
20
|
+
import getRequestStatusForAuthorization from './utils/getRequestStatusForAuthorization'
|
|
21
|
+
import getWorkoutPlanById from './utils/getWorkoutPlanById'
|
|
22
|
+
import queryCategorySamples from './utils/queryCategorySamples'
|
|
23
|
+
import queryCategorySamplesWithAnchor from './utils/queryCategorySamplesWithAnchor'
|
|
24
|
+
import queryCorrelationSamples from './utils/queryCorrelationSamples'
|
|
25
|
+
import queryHeartbeatSeriesSamples from './utils/queryHeartbeatSeriesSamples'
|
|
26
|
+
import queryHeartbeatSeriesSamplesWithAnchor from './utils/queryHeartbeatSeriesSamplesWithAnchor'
|
|
27
|
+
import queryQuantitySamples from './utils/queryQuantitySamples'
|
|
28
|
+
import queryQuantitySamplesWithAnchor from './utils/queryQuantitySamplesWithAnchor'
|
|
29
|
+
import querySources from './utils/querySources'
|
|
30
|
+
import queryStatisticsForQuantity from './utils/queryStatisticsForQuantity'
|
|
31
|
+
import queryWorkouts from './utils/queryWorkouts'
|
|
32
|
+
import requestAuthorization from './utils/requestAuthorization'
|
|
33
|
+
import saveCategorySample from './utils/saveCategorySample'
|
|
34
|
+
import saveCorrelationSample from './utils/saveCorrelationSample'
|
|
35
|
+
import saveQuantitySample from './utils/saveQuantitySample'
|
|
36
|
+
import saveWorkoutRoute from './utils/saveWorkoutRoute'
|
|
37
|
+
import saveWorkoutSample from './utils/saveWorkoutSample'
|
|
38
|
+
import subscribeToChanges from './utils/subscribeToChanges'
|
|
39
|
+
|
|
40
|
+
const currentMajorVersionIOS = Platform.OS === 'ios' ? parseInt(Platform.Version, 10) : 0
|
|
41
|
+
|
|
42
|
+
const allQuantityTypesList = [...Object.values(HKQuantityTypeIdentifier)]
|
|
43
|
+
|
|
44
|
+
const availableQuantityTypes = (majorVersionIOS = currentMajorVersionIOS) => {
|
|
45
|
+
if (majorVersionIOS >= 17) {
|
|
46
|
+
return allQuantityTypesList
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// remove types that are not available before iOS 17
|
|
50
|
+
return allQuantityTypesList.filter((type) => ![
|
|
51
|
+
HKQuantityTypeIdentifier.cyclingCadence,
|
|
52
|
+
HKQuantityTypeIdentifier.cyclingFunctionalThresholdPower,
|
|
53
|
+
HKQuantityTypeIdentifier.cyclingPower,
|
|
54
|
+
HKQuantityTypeIdentifier.cyclingSpeed,
|
|
55
|
+
HKQuantityTypeIdentifier.physicalEffort,
|
|
56
|
+
HKQuantityTypeIdentifier.timeInDaylight,
|
|
57
|
+
].includes(type))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const authorizationStatusFor = Native.authorizationStatusFor.bind(Native)
|
|
61
|
+
const isHealthDataAvailable = Native.isHealthDataAvailable.bind(Native)
|
|
62
|
+
const isProtectedDataAvailable = Native.isProtectedDataAvailable.bind(Native)
|
|
63
|
+
const disableBackgroundDelivery = Native.disableBackgroundDelivery.bind(Native)
|
|
64
|
+
const disableAllBackgroundDelivery = Native.disableAllBackgroundDelivery.bind(Native)
|
|
65
|
+
const enableBackgroundDelivery = Native.enableBackgroundDelivery.bind(Native)
|
|
66
|
+
const getBiologicalSex = Native.getBiologicalSex.bind(Native)
|
|
67
|
+
const getFitzpatrickSkinType = Native.getFitzpatrickSkinType.bind(Native)
|
|
68
|
+
const getWheelchairUse = Native.getWheelchairUse.bind(Native)
|
|
69
|
+
const getBloodType = Native.getBloodType.bind(Native)
|
|
70
|
+
const getWorkoutRoutes = Native.getWorkoutRoutes.bind(Native)
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/about_the_healthkit_framework About the HealthKit Framework (Apple Docs)}
|
|
74
|
+
*/
|
|
75
|
+
export default {
|
|
76
|
+
/**
|
|
77
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614154-authorizationstatus authorizationStatus(for:) (Apple Docs) }
|
|
78
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/authorizing_access_to_health_data Authorizing access to health data (Apple Docs) }
|
|
79
|
+
*/
|
|
80
|
+
authorizationStatusFor,
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
*
|
|
84
|
+
* @returns All available quantity types for the current iOS version (currently excluding types that are not available before iOS 17)
|
|
85
|
+
*/
|
|
86
|
+
availableQuantityTypes,
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* @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.
|
|
90
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614180-ishealthdataavailable isHealthDataAvailable() (Apple Docs)}
|
|
91
|
+
* @returns {boolean} true if HealthKit is available; otherwise, false.
|
|
92
|
+
*/
|
|
93
|
+
isHealthDataAvailable,
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614181-isprotecteddataavailable isProtectedDataAvailable() (Apple Docs)}
|
|
97
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/protecting_user_privacy#3705074 Protecting User Privacy - Access encrypted data (Apple Docs)}
|
|
98
|
+
* @returns {boolean} A Boolean value that indicates whether content protection is active.
|
|
99
|
+
*/
|
|
100
|
+
isProtectedDataAvailable,
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614158-disableallbackgrounddelivery disableAllBackgroundDelivery(completion:) (Apple Docs)}
|
|
104
|
+
*/
|
|
105
|
+
disableAllBackgroundDelivery,
|
|
106
|
+
/**
|
|
107
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614177-disablebackgrounddelivery disableBackgroundDelivery(for:withCompletion:) (Apple Docs)}
|
|
108
|
+
*/
|
|
109
|
+
disableBackgroundDelivery,
|
|
110
|
+
/**
|
|
111
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614175-enablebackgrounddelivery enableBackgroundDelivery(for:frequency:withCompletion:) (Apple Docs)}
|
|
112
|
+
*/
|
|
113
|
+
enableBackgroundDelivery,
|
|
114
|
+
|
|
115
|
+
// simple convenience getters
|
|
116
|
+
/**
|
|
117
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614171-biologicalsex biologicalSex() (Apple Docs)}
|
|
118
|
+
*/
|
|
119
|
+
getBiologicalSex,
|
|
120
|
+
/**
|
|
121
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614161-fitzpatrickskintype fitzpatrickSkinType() (Apple Docs)}
|
|
122
|
+
*/
|
|
123
|
+
getFitzpatrickSkinType,
|
|
124
|
+
/**
|
|
125
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1648356-wheelchairuse wheelchairUse() (Apple Docs)}
|
|
126
|
+
*/
|
|
127
|
+
getWheelchairUse,
|
|
128
|
+
/**
|
|
129
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614164-bloodtype bloodType() (Apple Docs)}
|
|
130
|
+
*/
|
|
131
|
+
getBloodType,
|
|
132
|
+
/**
|
|
133
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1648357-dateofbirthcomponents dateOfBirthComponents() (Apple Docs)}
|
|
134
|
+
*/
|
|
135
|
+
getDateOfBirth,
|
|
136
|
+
|
|
137
|
+
getMostRecentQuantitySample,
|
|
138
|
+
getMostRecentCategorySample,
|
|
139
|
+
getMostRecentWorkout,
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/workouts_and_activity_rings/reading_route_data Reading route data (Apple Docs)}
|
|
143
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkworkoutroutequery HKWorkoutRouteQuery (Apple Docs)}
|
|
144
|
+
*/
|
|
145
|
+
getWorkoutRoutes,
|
|
146
|
+
getWorkoutPlanById,
|
|
147
|
+
|
|
148
|
+
getPreferredUnit,
|
|
149
|
+
getPreferredUnits,
|
|
150
|
+
getRequestStatusForAuthorization,
|
|
151
|
+
|
|
152
|
+
// query methods
|
|
153
|
+
queryCategorySamples,
|
|
154
|
+
queryCategorySamplesWithAnchor,
|
|
155
|
+
queryCorrelationSamples,
|
|
156
|
+
queryHeartbeatSeriesSamples,
|
|
157
|
+
queryHeartbeatSeriesSamplesWithAnchor,
|
|
158
|
+
queryQuantitySamples,
|
|
159
|
+
queryQuantitySamplesWithAnchor,
|
|
160
|
+
queryStatisticsForQuantity,
|
|
161
|
+
queryWorkouts,
|
|
162
|
+
querySources,
|
|
163
|
+
|
|
164
|
+
requestAuthorization,
|
|
165
|
+
|
|
166
|
+
// delete methods
|
|
167
|
+
deleteQuantitySample,
|
|
168
|
+
deleteSamples,
|
|
169
|
+
|
|
170
|
+
// save methods
|
|
171
|
+
/**
|
|
172
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614168-savecategorysample save(_:withCompletion:) (Apple Docs)}
|
|
173
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/saving_data_to_healthkit Saving data to HealthKit (Apple Docs)}
|
|
174
|
+
*/
|
|
175
|
+
saveCategorySample,
|
|
176
|
+
saveCorrelationSample,
|
|
177
|
+
saveQuantitySample,
|
|
178
|
+
saveWorkoutSample,
|
|
179
|
+
saveWorkoutRoute,
|
|
180
|
+
|
|
181
|
+
// subscriptions
|
|
182
|
+
subscribeToChanges,
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* @returns the most recent sample for the given category type.
|
|
186
|
+
*/
|
|
187
|
+
useMostRecentCategorySample,
|
|
188
|
+
/**
|
|
189
|
+
* @returns the most recent sample for the given quantity type.
|
|
190
|
+
*/
|
|
191
|
+
useMostRecentQuantitySample,
|
|
192
|
+
/**
|
|
193
|
+
* @returns the most recent workout sample.
|
|
194
|
+
*/
|
|
195
|
+
useMostRecentWorkout,
|
|
196
|
+
useSubscribeToChanges,
|
|
197
|
+
/**
|
|
198
|
+
* @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.
|
|
199
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614180-ishealthdataavailable Apple Docs}
|
|
200
|
+
* @returns {boolean | null} true if HealthKit is available; otherwise, false. null while initializing.
|
|
201
|
+
*/
|
|
202
|
+
useIsHealthDataAvailable,
|
|
203
|
+
/**
|
|
204
|
+
* @description Hook to retrieve the current authorization status for the given types, and request authorization if needed.
|
|
205
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614152-requestauthorization Apple Docs - requestAuthorization}
|
|
206
|
+
* @see {@link https://developer.apple.com/documentation/healthkit/authorizing_access_to_health_data Apple Docs - Authorizing access to health data}
|
|
207
|
+
*/
|
|
208
|
+
useHealthkitAuthorization,
|
|
209
|
+
useSources,
|
|
210
|
+
useStatisticsForQuantity,
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
export {
|
|
214
|
+
authorizationStatusFor,
|
|
215
|
+
availableQuantityTypes,
|
|
216
|
+
disableAllBackgroundDelivery,
|
|
217
|
+
disableBackgroundDelivery,
|
|
218
|
+
enableBackgroundDelivery,
|
|
219
|
+
getBiologicalSex,
|
|
220
|
+
getBloodType,
|
|
221
|
+
getDateOfBirth,
|
|
222
|
+
getFitzpatrickSkinType,
|
|
223
|
+
getMostRecentCategorySample,
|
|
224
|
+
getMostRecentQuantitySample,
|
|
225
|
+
getMostRecentWorkout,
|
|
226
|
+
getPreferredUnit,
|
|
227
|
+
getPreferredUnits,
|
|
228
|
+
getRequestStatusForAuthorization,
|
|
229
|
+
getWheelchairUse,
|
|
230
|
+
getWorkoutRoutes,
|
|
231
|
+
isHealthDataAvailable,
|
|
232
|
+
queryCategorySamples,
|
|
233
|
+
queryCategorySamplesWithAnchor,
|
|
234
|
+
queryCorrelationSamples,
|
|
235
|
+
queryHeartbeatSeriesSamples,
|
|
236
|
+
queryHeartbeatSeriesSamplesWithAnchor,
|
|
237
|
+
queryQuantitySamples,
|
|
238
|
+
queryQuantitySamplesWithAnchor,
|
|
239
|
+
queryStatisticsForQuantity,
|
|
240
|
+
queryWorkouts,
|
|
241
|
+
querySources,
|
|
242
|
+
requestAuthorization,
|
|
243
|
+
deleteQuantitySample,
|
|
244
|
+
deleteSamples,
|
|
245
|
+
getWorkoutPlanById,
|
|
246
|
+
saveCategorySample,
|
|
247
|
+
saveCorrelationSample,
|
|
248
|
+
saveQuantitySample,
|
|
249
|
+
saveWorkoutSample,
|
|
250
|
+
saveWorkoutRoute,
|
|
251
|
+
subscribeToChanges,
|
|
252
|
+
useMostRecentCategorySample,
|
|
253
|
+
useMostRecentQuantitySample,
|
|
254
|
+
useMostRecentWorkout,
|
|
255
|
+
useSubscribeToChanges,
|
|
256
|
+
useHealthkitAuthorization,
|
|
257
|
+
useIsHealthDataAvailable,
|
|
258
|
+
useSources,
|
|
259
|
+
useStatisticsForQuantity,
|
|
260
|
+
isProtectedDataAvailable,
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
export * from './types'
|
package/src/index.native.tsx
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
HKAuthorizationRequestStatus, HKAuthorizationStatus, HKBiologicalSex, HKBloodType, HKFitzpatrickSkinType, HKUnits, HKWheelchairUse,
|
|
5
5
|
} from './native-types'
|
|
6
6
|
|
|
7
|
-
import type ReactNativeHealthkit from '.'
|
|
7
|
+
import type ReactNativeHealthkit from './index.ios'
|
|
8
8
|
import type { QueryCategorySamplesFn } from './utils/queryCategorySamples'
|
|
9
9
|
import type { QueryQuantitySamplesFn } from './utils/queryQuantitySamples'
|
|
10
10
|
|
|
@@ -91,7 +91,6 @@ const authorizationStatusFor = UnavailableFn(Promise.resolve(HKAuthorizationStat
|
|
|
91
91
|
useSubscribeToChanges = UnavailableFn([null, () => null]),
|
|
92
92
|
useHealthkitAuthorization = UnavailableFn([null, async () => Promise.resolve(HKAuthorizationRequestStatus.unknown)] as const),
|
|
93
93
|
useIsHealthDataAvailable = () => false,
|
|
94
|
-
canAccessProtectedData = async () => Promise.resolve(false),
|
|
95
94
|
isProtectedDataAvailable = async () => Promise.resolve(false)
|
|
96
95
|
|
|
97
96
|
const Healthkit: typeof ReactNativeHealthkit = {
|
|
@@ -141,7 +140,6 @@ const Healthkit: typeof ReactNativeHealthkit = {
|
|
|
141
140
|
useSubscribeToChanges,
|
|
142
141
|
useHealthkitAuthorization,
|
|
143
142
|
useIsHealthDataAvailable,
|
|
144
|
-
canAccessProtectedData,
|
|
145
143
|
isProtectedDataAvailable,
|
|
146
144
|
}
|
|
147
145
|
|
|
@@ -192,7 +190,6 @@ export {
|
|
|
192
190
|
useSubscribeToChanges,
|
|
193
191
|
useHealthkitAuthorization,
|
|
194
192
|
useIsHealthDataAvailable,
|
|
195
|
-
canAccessProtectedData,
|
|
196
193
|
isProtectedDataAvailable,
|
|
197
194
|
}
|
|
198
195
|
|