@kingstinct/react-native-healthkit 4.4.6 → 5.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/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/xcuserdata/robertherber.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
- package/lib/commonjs/hooks/useHealthkitAuthorization.js +41 -0
- package/lib/commonjs/hooks/useHealthkitAuthorization.js.map +1 -0
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js +29 -0
- package/lib/commonjs/hooks/useIsHealthDataAvailable.js.map +1 -0
- package/lib/commonjs/hooks/useMostRecentCategorySample.js +27 -0
- package/lib/commonjs/hooks/useMostRecentCategorySample.js.map +1 -0
- package/lib/commonjs/hooks/useMostRecentQuantitySample.js +43 -0
- package/lib/commonjs/hooks/useMostRecentQuantitySample.js.map +1 -0
- package/lib/commonjs/hooks/useMostRecentWorkout.js +60 -0
- package/lib/commonjs/hooks/useMostRecentWorkout.js.map +1 -0
- package/lib/commonjs/hooks/useStatisticsForQuantity.js +35 -0
- package/lib/commonjs/hooks/useStatisticsForQuantity.js.map +1 -0
- package/lib/commonjs/hooks/useSubscribeToChanges.js +37 -0
- package/lib/commonjs/hooks/useSubscribeToChanges.js.map +1 -0
- package/lib/commonjs/index.ios.js +66 -394
- package/lib/commonjs/index.ios.js.map +1 -1
- package/lib/commonjs/index.js +2 -15
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/native-types.js +170 -78
- package/lib/commonjs/native-types.js.map +1 -1
- package/lib/commonjs/types.js +13 -0
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/deserializeCategorySample.js +15 -0
- package/lib/commonjs/utils/deserializeCategorySample.js.map +1 -0
- package/lib/commonjs/utils/deserializeCorrelation.js +32 -0
- package/lib/commonjs/utils/deserializeCorrelation.js.map +1 -0
- package/lib/commonjs/utils/deserializeSample.js +17 -0
- package/lib/commonjs/utils/deserializeSample.js.map +1 -0
- package/lib/commonjs/utils/deserializeWorkout.js +17 -0
- package/lib/commonjs/utils/deserializeWorkout.js.map +1 -0
- package/lib/commonjs/utils/ensureMetadata.js +14 -0
- package/lib/commonjs/utils/ensureMetadata.js.map +1 -0
- package/lib/commonjs/utils/ensureUnit.js +23 -0
- package/lib/commonjs/utils/ensureUnit.js.map +1 -0
- package/lib/commonjs/utils/getDateOfBirth.js +19 -0
- package/lib/commonjs/utils/getDateOfBirth.js.map +1 -0
- package/lib/commonjs/utils/getMostRecentCategorySample.js +22 -0
- package/lib/commonjs/utils/getMostRecentCategorySample.js.map +1 -0
- package/lib/commonjs/utils/getMostRecentQuantitySample.js +22 -0
- package/lib/commonjs/utils/getMostRecentQuantitySample.js.map +1 -0
- package/lib/commonjs/utils/getMostRecentWorkout.js +24 -0
- package/lib/commonjs/utils/getMostRecentWorkout.js.map +1 -0
- package/lib/commonjs/utils/getPreferredUnit.js +19 -0
- package/lib/commonjs/utils/getPreferredUnit.js.map +1 -0
- package/lib/commonjs/utils/getPreferredUnits.js +19 -0
- package/lib/commonjs/utils/getPreferredUnits.js.map +1 -0
- package/lib/commonjs/utils/getPreferredUnitsTyped.js +46 -0
- package/lib/commonjs/utils/getPreferredUnitsTyped.js.map +1 -0
- package/lib/commonjs/utils/getRequestStatusForAuthorization.js +25 -0
- package/lib/commonjs/utils/getRequestStatusForAuthorization.js.map +1 -0
- package/lib/commonjs/utils/prepareOptions.js +27 -0
- package/lib/commonjs/utils/prepareOptions.js.map +1 -0
- package/lib/commonjs/utils/queryCategorySamples.js +24 -0
- package/lib/commonjs/utils/queryCategorySamples.js.map +1 -0
- package/lib/commonjs/utils/queryCorrelationSamples.js +24 -0
- package/lib/commonjs/utils/queryCorrelationSamples.js.map +1 -0
- package/lib/commonjs/utils/queryQuantitySamples.js +27 -0
- package/lib/commonjs/utils/queryQuantitySamples.js.map +1 -0
- package/lib/commonjs/utils/queryStatisticsForQuantity.js +34 -0
- package/lib/commonjs/utils/queryStatisticsForQuantity.js.map +1 -0
- package/lib/commonjs/utils/queryWorkouts.js +30 -0
- package/lib/commonjs/utils/queryWorkouts.js.map +1 -0
- package/lib/commonjs/utils/requestAuthorization.js +25 -0
- package/lib/commonjs/utils/requestAuthorization.js.map +1 -0
- package/lib/commonjs/utils/saveCategorySample.js +21 -0
- package/lib/commonjs/utils/saveCategorySample.js.map +1 -0
- package/lib/commonjs/utils/saveCorrelationSample.js +24 -0
- package/lib/commonjs/utils/saveCorrelationSample.js.map +1 -0
- package/lib/commonjs/utils/saveQuantitySample.js +21 -0
- package/lib/commonjs/utils/saveQuantitySample.js.map +1 -0
- package/lib/commonjs/utils/saveWorkoutSample.js +25 -0
- package/lib/commonjs/utils/saveWorkoutSample.js.map +1 -0
- package/lib/commonjs/utils/serializeDate.js +12 -0
- package/lib/commonjs/utils/serializeDate.js.map +1 -0
- package/lib/commonjs/utils/subscribeToChanges.js +37 -0
- package/lib/commonjs/utils/subscribeToChanges.js.map +1 -0
- package/lib/module/hooks/useHealthkitAuthorization.js +29 -0
- package/lib/module/hooks/useHealthkitAuthorization.js.map +1 -0
- package/lib/module/hooks/useIsHealthDataAvailable.js +18 -0
- package/lib/module/hooks/useIsHealthDataAvailable.js.map +1 -0
- package/lib/module/hooks/useMostRecentCategorySample.js +15 -0
- package/lib/module/hooks/useMostRecentCategorySample.js.map +1 -0
- package/lib/module/hooks/useMostRecentQuantitySample.js +30 -0
- package/lib/module/hooks/useMostRecentQuantitySample.js.map +1 -0
- package/lib/module/hooks/useMostRecentWorkout.js +47 -0
- package/lib/module/hooks/useMostRecentWorkout.js.map +1 -0
- package/lib/module/hooks/useStatisticsForQuantity.js +23 -0
- package/lib/module/hooks/useStatisticsForQuantity.js.map +1 -0
- package/lib/module/hooks/useSubscribeToChanges.js +26 -0
- package/lib/module/hooks/useSubscribeToChanges.js.map +1 -0
- package/lib/module/index.ios.js +32 -370
- package/lib/module/index.ios.js.map +1 -1
- package/lib/module/index.js +3 -5
- package/lib/module/index.js.map +1 -1
- package/lib/module/native-types.js +154 -74
- package/lib/module/native-types.js.map +1 -1
- package/lib/module/types.js +15 -0
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/deserializeCategorySample.js +7 -0
- package/lib/module/utils/deserializeCategorySample.js.map +1 -0
- package/lib/module/utils/deserializeCorrelation.js +21 -0
- package/lib/module/utils/deserializeCorrelation.js.map +1 -0
- package/lib/module/utils/deserializeSample.js +9 -0
- package/lib/module/utils/deserializeSample.js.map +1 -0
- package/lib/module/utils/deserializeWorkout.js +9 -0
- package/lib/module/utils/deserializeWorkout.js.map +1 -0
- package/lib/module/utils/ensureMetadata.js +6 -0
- package/lib/module/utils/ensureMetadata.js.map +1 -0
- package/lib/module/utils/ensureUnit.js +13 -0
- package/lib/module/utils/ensureUnit.js.map +1 -0
- package/lib/module/utils/getDateOfBirth.js +9 -0
- package/lib/module/utils/getDateOfBirth.js.map +1 -0
- package/lib/module/utils/getMostRecentCategorySample.js +12 -0
- package/lib/module/utils/getMostRecentCategorySample.js.map +1 -0
- package/lib/module/utils/getMostRecentQuantitySample.js +12 -0
- package/lib/module/utils/getMostRecentQuantitySample.js.map +1 -0
- package/lib/module/utils/getMostRecentWorkout.js +14 -0
- package/lib/module/utils/getMostRecentWorkout.js.map +1 -0
- package/lib/module/utils/getPreferredUnit.js +9 -0
- package/lib/module/utils/getPreferredUnit.js.map +1 -0
- package/lib/module/utils/getPreferredUnits.js +9 -0
- package/lib/module/utils/getPreferredUnits.js.map +1 -0
- package/lib/module/utils/getPreferredUnitsTyped.js +34 -0
- package/lib/module/utils/getPreferredUnitsTyped.js.map +1 -0
- package/lib/module/utils/getRequestStatusForAuthorization.js +15 -0
- package/lib/module/utils/getRequestStatusForAuthorization.js.map +1 -0
- package/lib/module/utils/prepareOptions.js +17 -0
- package/lib/module/utils/prepareOptions.js.map +1 -0
- package/lib/module/utils/queryCategorySamples.js +12 -0
- package/lib/module/utils/queryCategorySamples.js.map +1 -0
- package/lib/module/utils/queryCorrelationSamples.js +12 -0
- package/lib/module/utils/queryCorrelationSamples.js.map +1 -0
- package/lib/module/utils/queryQuantitySamples.js +14 -0
- package/lib/module/utils/queryQuantitySamples.js.map +1 -0
- package/lib/module/utils/queryStatisticsForQuantity.js +23 -0
- package/lib/module/utils/queryStatisticsForQuantity.js.map +1 -0
- package/lib/module/utils/queryWorkouts.js +17 -0
- package/lib/module/utils/queryWorkouts.js.map +1 -0
- package/lib/module/utils/requestAuthorization.js +15 -0
- package/lib/module/utils/requestAuthorization.js.map +1 -0
- package/lib/module/utils/saveCategorySample.js +11 -0
- package/lib/module/utils/saveCategorySample.js.map +1 -0
- package/lib/module/utils/saveCorrelationSample.js +13 -0
- package/lib/module/utils/saveCorrelationSample.js.map +1 -0
- package/lib/module/utils/saveQuantitySample.js +11 -0
- package/lib/module/utils/saveQuantitySample.js.map +1 -0
- package/lib/module/utils/saveWorkoutSample.js +14 -0
- package/lib/module/utils/saveWorkoutSample.js.map +1 -0
- package/lib/module/utils/serializeDate.js +4 -0
- package/lib/module/utils/serializeDate.js.map +1 -0
- package/lib/module/utils/subscribeToChanges.js +25 -0
- package/lib/module/utils/subscribeToChanges.js.map +1 -0
- package/lib/typescript/example-expo/App.d.ts +2 -0
- package/lib/typescript/src/hooks/useHealthkitAuthorization.d.ts +3 -0
- package/lib/typescript/src/hooks/useIsHealthDataAvailable.d.ts +2 -0
- package/lib/typescript/src/hooks/useMostRecentCategorySample.d.ts +4 -0
- package/lib/typescript/src/hooks/useMostRecentQuantitySample.d.ts +4 -0
- package/lib/typescript/src/hooks/useMostRecentWorkout.d.ts +7 -0
- package/lib/typescript/src/hooks/useStatisticsForQuantity.d.ts +4 -0
- package/lib/typescript/src/hooks/useSubscribeToChanges.d.ts +3 -0
- package/lib/typescript/src/index.d.ts +2 -3
- package/lib/typescript/src/index.ios.d.ts +48 -3
- package/lib/typescript/src/native-types.d.ts +169 -65
- package/lib/typescript/src/types.d.ts +14 -90
- package/lib/typescript/src/utils/deserializeCategorySample.d.ts +4 -0
- package/lib/typescript/src/utils/deserializeCorrelation.d.ts +4 -0
- package/lib/typescript/src/utils/deserializeSample.d.ts +4 -0
- package/lib/typescript/src/utils/deserializeWorkout.d.ts +4 -0
- package/lib/typescript/src/utils/ensureMetadata.d.ts +2 -0
- package/lib/typescript/src/utils/ensureUnit.d.ts +3 -0
- package/lib/typescript/src/utils/getDateOfBirth.d.ts +2 -0
- package/lib/typescript/src/utils/getMostRecentCategorySample.d.ts +3 -0
- package/lib/typescript/src/utils/getMostRecentQuantitySample.d.ts +3 -0
- package/lib/typescript/src/utils/getMostRecentWorkout.d.ts +5 -0
- package/lib/typescript/src/utils/getPreferredUnit.d.ts +4 -0
- package/lib/typescript/src/utils/getPreferredUnits.d.ts +4 -0
- package/lib/typescript/src/utils/getPreferredUnitsTyped.d.ts +9 -0
- package/lib/typescript/src/utils/getRequestStatusForAuthorization.d.ts +3 -0
- package/lib/typescript/src/utils/prepareOptions.d.ts +8 -0
- package/lib/typescript/src/utils/queryCategorySamples.d.ts +5 -0
- package/lib/typescript/src/utils/queryCorrelationSamples.d.ts +5 -0
- package/lib/typescript/src/utils/queryQuantitySamples.d.ts +7 -0
- package/lib/typescript/src/utils/queryStatisticsForQuantity.d.ts +14 -0
- package/lib/typescript/src/utils/queryWorkouts.d.ts +4 -0
- package/lib/typescript/src/utils/requestAuthorization.d.ts +3 -0
- package/lib/typescript/src/utils/saveCategorySample.d.ts +7 -0
- package/lib/typescript/src/utils/saveCorrelationSample.d.ts +8 -0
- package/lib/typescript/src/utils/saveQuantitySample.d.ts +7 -0
- package/lib/typescript/src/utils/saveWorkoutSample.d.ts +7 -0
- package/lib/typescript/src/utils/serializeDate.d.ts +2 -0
- package/lib/typescript/src/utils/subscribeToChanges.d.ts +3 -0
- package/package.json +17 -6
- package/src/hooks/useHealthkitAuthorization.ts +39 -0
- package/src/hooks/useIsHealthDataAvailable.ts +17 -0
- package/src/hooks/useMostRecentCategorySample.ts +24 -0
- package/src/hooks/useMostRecentQuantitySample.ts +39 -0
- package/src/hooks/useMostRecentWorkout.ts +60 -0
- package/src/hooks/useStatisticsForQuantity.ts +42 -0
- package/src/hooks/useSubscribeToChanges.ts +31 -0
- package/src/index.ios.tsx +36 -569
- package/src/index.tsx +5 -7
- package/src/native-types.ts +213 -74
- package/src/types.ts +41 -152
- package/src/utils/deserializeCategorySample.ts +12 -0
- package/src/utils/deserializeCorrelation.ts +28 -0
- package/src/utils/deserializeSample.ts +17 -0
- package/src/utils/deserializeWorkout.ts +14 -0
- package/src/utils/ensureMetadata.ts +5 -0
- package/src/utils/ensureUnit.ts +19 -0
- package/src/utils/getDateOfBirth.ts +8 -0
- package/src/utils/getMostRecentCategorySample.ts +18 -0
- package/src/utils/getMostRecentQuantitySample.ts +19 -0
- package/src/utils/getMostRecentWorkout.ts +27 -0
- package/src/utils/getPreferredUnit.ts +14 -0
- package/src/utils/getPreferredUnits.ts +14 -0
- package/src/utils/getPreferredUnitsTyped.ts +38 -0
- package/src/utils/getRequestStatusForAuthorization.ts +21 -0
- package/src/utils/prepareOptions.ts +15 -0
- package/src/utils/queryCategorySamples.ts +29 -0
- package/src/utils/queryCorrelationSamples.ts +29 -0
- package/src/utils/queryQuantitySamples.ts +36 -0
- package/src/utils/queryStatisticsForQuantity.ts +38 -0
- package/src/utils/queryWorkouts.ts +28 -0
- package/src/utils/requestAuthorization.ts +18 -0
- package/src/utils/saveCategorySample.ts +27 -0
- package/src/utils/saveCorrelationSample.ts +34 -0
- package/src/utils/saveQuantitySample.ts +29 -0
- package/src/utils/saveWorkoutSample.ts +28 -0
- package/src/utils/serializeDate.ts +3 -0
- package/src/utils/subscribeToChanges.ts +32 -0
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { HKCorrelationTypeIdentifier } from '../native-types';
|
|
2
|
+
import type { GenericQueryOptions, HKCorrelation } from '../types';
|
|
3
|
+
export declare type QueryCorrelationSamplesFn = <TIdentifier extends HKCorrelationTypeIdentifier>(typeIdentifier: TIdentifier, options: Omit<GenericQueryOptions, 'ascending' | 'limit'>) => Promise<readonly HKCorrelation<TIdentifier>[]>;
|
|
4
|
+
declare const queryCorrelationSamples: QueryCorrelationSamplesFn;
|
|
5
|
+
export default queryCorrelationSamples;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HKQuantityTypeIdentifier, UnitForIdentifier } from '../native-types';
|
|
2
|
+
import type { GenericQueryOptions, HKQuantitySample } from '../types';
|
|
3
|
+
export declare type QueryQuantitySamplesFn = <TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier>>(identifier: TIdentifier, options: GenericQueryOptions & {
|
|
4
|
+
readonly unit?: TUnit;
|
|
5
|
+
}) => Promise<readonly HKQuantitySample<TIdentifier>[]>;
|
|
6
|
+
declare const queryQuantitySamples: QueryQuantitySamplesFn;
|
|
7
|
+
export default queryQuantitySamples;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { HKQuantityTypeIdentifier, HKStatisticsOptions, UnitForIdentifier } from '../native-types';
|
|
2
|
+
declare function queryStatisticsForQuantity<TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier> = UnitForIdentifier<TIdentifier>>(identifier: TIdentifier, options: readonly HKStatisticsOptions[], from: Date, to?: Date, unit?: TUnit): Promise<{
|
|
3
|
+
mostRecentQuantityDateInterval?: {
|
|
4
|
+
from: Date;
|
|
5
|
+
to: Date;
|
|
6
|
+
} | undefined;
|
|
7
|
+
averageQuantity?: import("../native-types").HKQuantity<HKQuantityTypeIdentifier, TUnit> | undefined;
|
|
8
|
+
maximumQuantity?: import("../native-types").HKQuantity<HKQuantityTypeIdentifier, TUnit> | undefined;
|
|
9
|
+
minimumQuantity?: import("../native-types").HKQuantity<HKQuantityTypeIdentifier, TUnit> | undefined;
|
|
10
|
+
sumQuantity?: import("../native-types").HKQuantity<HKQuantityTypeIdentifier, TUnit> | undefined;
|
|
11
|
+
mostRecentQuantity?: import("../native-types").HKQuantity<HKQuantityTypeIdentifier, TUnit> | undefined;
|
|
12
|
+
duration?: import("../native-types").HKQuantity<HKQuantityTypeIdentifier, import("../native-types").TimeUnit> | undefined;
|
|
13
|
+
}>;
|
|
14
|
+
export default queryStatisticsForQuantity;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { EnergyUnit, LengthUnit } from '../native-types';
|
|
2
|
+
import type { QueryWorkoutsOptions } from '../types';
|
|
3
|
+
declare function queryWorkouts<TEnergy extends EnergyUnit, TDistance extends LengthUnit>(options: QueryWorkoutsOptions<TEnergy, TDistance>): Promise<import("../types").HKWorkout<TEnergy, TDistance>[]>;
|
|
4
|
+
export default queryWorkouts;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { HealthkitReadAuthorization, HealthkitWriteAuthorization } from '../native-types';
|
|
2
|
+
declare const requestAuthorization: (read: readonly HealthkitReadAuthorization[], write?: readonly HealthkitWriteAuthorization[]) => Promise<boolean>;
|
|
3
|
+
export default requestAuthorization;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HKCategoryTypeIdentifier, HKCategoryValueForIdentifier, MetadataMapperForCategoryIdentifier } from '../native-types';
|
|
2
|
+
declare function saveCategorySample<T extends HKCategoryTypeIdentifier>(identifier: T, value: HKCategoryValueForIdentifier<T>, options?: {
|
|
3
|
+
readonly start?: Date;
|
|
4
|
+
readonly end?: Date;
|
|
5
|
+
readonly metadata?: MetadataMapperForCategoryIdentifier<T>;
|
|
6
|
+
}): Promise<boolean>;
|
|
7
|
+
export default saveCategorySample;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { MetadataMapperForCorrelationIdentifier, HKCorrelationTypeIdentifier } from '../native-types';
|
|
2
|
+
import type { HKCategorySampleForSaving, HKQuantitySampleForSaving } from '../types';
|
|
3
|
+
declare function saveCorrelationSample<TIdentifier extends HKCorrelationTypeIdentifier, TSamples extends readonly (HKCategorySampleForSaving | HKQuantitySampleForSaving)[]>(typeIdentifier: TIdentifier, samples: TSamples, options?: {
|
|
4
|
+
readonly start?: Date;
|
|
5
|
+
readonly end?: Date;
|
|
6
|
+
readonly metadata?: MetadataMapperForCorrelationIdentifier<TIdentifier>;
|
|
7
|
+
}): Promise<boolean>;
|
|
8
|
+
export default saveCorrelationSample;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { MetadataMapperForQuantityIdentifier, HKQuantityTypeIdentifier, UnitForIdentifier } from '../native-types';
|
|
2
|
+
declare function saveQuantitySample<TType extends HKQuantityTypeIdentifier>(identifier: TType, unit: UnitForIdentifier<TType>, value: number, options?: {
|
|
3
|
+
readonly start?: Date;
|
|
4
|
+
readonly end?: Date;
|
|
5
|
+
readonly metadata?: MetadataMapperForQuantityIdentifier<TType>;
|
|
6
|
+
}): Promise<boolean>;
|
|
7
|
+
export default saveQuantitySample;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { HKWorkoutActivityType, HKWorkoutMetadata } from '../native-types';
|
|
2
|
+
import type { HKQuantitySampleForSaving } from '../types';
|
|
3
|
+
declare function saveWorkoutSample<TIdentifier extends HKWorkoutActivityType>(typeIdentifier: TIdentifier, quantities: readonly HKQuantitySampleForSaving[], _start: Date, options?: {
|
|
4
|
+
readonly end?: Date;
|
|
5
|
+
readonly metadata?: HKWorkoutMetadata;
|
|
6
|
+
}): Promise<boolean>;
|
|
7
|
+
export default saveWorkoutSample;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kingstinct/react-native-healthkit",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "React Native bindings for HealthKit",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -20,7 +20,8 @@
|
|
|
20
20
|
"!**/__mocks__"
|
|
21
21
|
],
|
|
22
22
|
"scripts": {
|
|
23
|
-
"test": "jest",
|
|
23
|
+
"test-only": "jest",
|
|
24
|
+
"test": "concurrently \"yarn test-only\" \"yarn typecheck\" \"yarn lint\"",
|
|
24
25
|
"typecheck": "tsc --noEmit",
|
|
25
26
|
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
26
27
|
"prepare": "bob build",
|
|
@@ -44,6 +45,7 @@
|
|
|
44
45
|
},
|
|
45
46
|
"homepage": "https://github.com/kingstinct/react-native-healthkit#readme",
|
|
46
47
|
"devDependencies": {
|
|
48
|
+
"@babel/core": ">=7",
|
|
47
49
|
"@commitlint/config-conventional": "12",
|
|
48
50
|
"@graphql-eslint/eslint-plugin": ">=3",
|
|
49
51
|
"@release-it/conventional-changelog": "2",
|
|
@@ -52,20 +54,28 @@
|
|
|
52
54
|
"@types/react-native": "0.67",
|
|
53
55
|
"@typescript-eslint/eslint-plugin": ">=5",
|
|
54
56
|
"@typescript-eslint/parser": ">=5",
|
|
55
|
-
"commitlint": "
|
|
57
|
+
"commitlint": "^17.1.1",
|
|
58
|
+
"concurrently": "^7.3.0",
|
|
56
59
|
"eslint": ">=8",
|
|
60
|
+
"eslint-config-airbnb": ">=19",
|
|
57
61
|
"eslint-config-airbnb-base": ">=15",
|
|
58
|
-
"eslint-config-kingstinct": "5.1.1",
|
|
62
|
+
"eslint-config-kingstinct": "^5.1.1",
|
|
59
63
|
"eslint-import-resolver-typescript": ">=3",
|
|
60
64
|
"eslint-plugin-comment-length": ">=0",
|
|
61
65
|
"eslint-plugin-functional": ">=4",
|
|
62
66
|
"eslint-plugin-import": ">=2",
|
|
63
67
|
"eslint-plugin-jest": ">=26",
|
|
64
68
|
"eslint-plugin-jsonc": ">=2",
|
|
69
|
+
"eslint-plugin-jsx-a11y": ">=6",
|
|
70
|
+
"eslint-plugin-react": ">=7",
|
|
71
|
+
"eslint-plugin-react-hooks": ">=4",
|
|
72
|
+
"eslint-plugin-react-native": ">=4",
|
|
73
|
+
"eslint-plugin-react-native-a11y": ">=3",
|
|
65
74
|
"eslint-plugin-unicorn": ">=43",
|
|
66
75
|
"eslint-plugin-yml": ">=1",
|
|
76
|
+
"expo": ">=45",
|
|
67
77
|
"graphql": ">=16",
|
|
68
|
-
"husky": "
|
|
78
|
+
"husky": "8",
|
|
69
79
|
"jest": ">=26",
|
|
70
80
|
"metro-react-native-babel-preset": "^0.70.3",
|
|
71
81
|
"pod-install": "^0.1.0",
|
|
@@ -114,7 +124,8 @@
|
|
|
114
124
|
},
|
|
115
125
|
"plugins": {
|
|
116
126
|
"@release-it/conventional-changelog": {
|
|
117
|
-
"preset": "angular"
|
|
127
|
+
"preset": "angular",
|
|
128
|
+
"infile": "CHANGELOG.md"
|
|
118
129
|
}
|
|
119
130
|
}
|
|
120
131
|
},
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useCallback, useEffect, useRef, useState,
|
|
3
|
+
} from 'react'
|
|
4
|
+
|
|
5
|
+
import getRequestStatusForAuthorization from '../utils/getRequestStatusForAuthorization'
|
|
6
|
+
import requestAuthorization from '../utils/requestAuthorization'
|
|
7
|
+
|
|
8
|
+
import type { HealthkitReadAuthorization, HealthkitWriteAuthorization, HKAuthorizationRequestStatus } from '../native-types'
|
|
9
|
+
|
|
10
|
+
const useHealthkitAuthorization = (read: readonly HealthkitReadAuthorization[], write?: readonly HealthkitWriteAuthorization[]) => {
|
|
11
|
+
const [status, setStatus] = useState<HKAuthorizationRequestStatus | null>(null)
|
|
12
|
+
|
|
13
|
+
const readMemo = useRef(read)
|
|
14
|
+
const writeMemo = useRef(write)
|
|
15
|
+
|
|
16
|
+
useEffect(() => {
|
|
17
|
+
readMemo.current = read
|
|
18
|
+
writeMemo.current = write
|
|
19
|
+
}, [read, write])
|
|
20
|
+
|
|
21
|
+
const refreshAuthStatus = useCallback(async () => {
|
|
22
|
+
const auth = await getRequestStatusForAuthorization(readMemo.current, writeMemo.current)
|
|
23
|
+
setStatus(auth)
|
|
24
|
+
return auth
|
|
25
|
+
}, [])
|
|
26
|
+
|
|
27
|
+
const request = useCallback(async () => {
|
|
28
|
+
await requestAuthorization(readMemo.current, writeMemo.current)
|
|
29
|
+
return refreshAuthStatus()
|
|
30
|
+
}, [refreshAuthStatus])
|
|
31
|
+
|
|
32
|
+
useEffect(() => {
|
|
33
|
+
void refreshAuthStatus()
|
|
34
|
+
}, [refreshAuthStatus])
|
|
35
|
+
|
|
36
|
+
return [status, request] as const
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default useHealthkitAuthorization
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import Native from '../native-types'
|
|
4
|
+
|
|
5
|
+
const useIsHealthDataAvailable = () => {
|
|
6
|
+
const [isAvailable, setIsAvailable] = useState<boolean | null>(null)
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
const init = async () => {
|
|
9
|
+
const res = await Native.isHealthDataAvailable()
|
|
10
|
+
setIsAvailable(res)
|
|
11
|
+
}
|
|
12
|
+
void init()
|
|
13
|
+
}, [])
|
|
14
|
+
return isAvailable
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default useIsHealthDataAvailable
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useCallback, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import getMostRecentCategorySample from '../utils/getMostRecentCategorySample'
|
|
4
|
+
import useSubscribeToChanges from './useSubscribeToChanges'
|
|
5
|
+
|
|
6
|
+
import type { HKCategoryTypeIdentifier } from '../native-types'
|
|
7
|
+
import type { HKCategorySample } from '../types'
|
|
8
|
+
|
|
9
|
+
function useMostRecentCategorySample<
|
|
10
|
+
TCategory extends HKCategoryTypeIdentifier
|
|
11
|
+
>(identifier: TCategory) {
|
|
12
|
+
const [category, setCategory] = useState<HKCategorySample<TCategory> | null>(
|
|
13
|
+
null,
|
|
14
|
+
)
|
|
15
|
+
const updater = useCallback(() => {
|
|
16
|
+
void getMostRecentCategorySample(identifier).then(setCategory)
|
|
17
|
+
}, [identifier])
|
|
18
|
+
|
|
19
|
+
useSubscribeToChanges(identifier, updater)
|
|
20
|
+
|
|
21
|
+
return category
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default useMostRecentCategorySample
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
import ensureUnit from '../utils/ensureUnit'
|
|
4
|
+
import getMostRecentQuantitySample from '../utils/getMostRecentQuantitySample'
|
|
5
|
+
import subscribeToChanges from '../utils/subscribeToChanges'
|
|
6
|
+
|
|
7
|
+
import type { HKQuantityTypeIdentifier, UnitForIdentifier } from '../native-types'
|
|
8
|
+
import type { HKQuantitySample } from '../types'
|
|
9
|
+
|
|
10
|
+
function useMostRecentQuantitySample<
|
|
11
|
+
TIdentifier extends HKQuantityTypeIdentifier,
|
|
12
|
+
TUnit extends UnitForIdentifier<TIdentifier>
|
|
13
|
+
>(identifier: TIdentifier, unit?: TUnit) {
|
|
14
|
+
const [lastSample, setLastSample] = useState<HKQuantitySample<
|
|
15
|
+
TIdentifier
|
|
16
|
+
> | null>(null)
|
|
17
|
+
|
|
18
|
+
useEffect(() => {
|
|
19
|
+
let cancelSubscription: (() => Promise<boolean>) | undefined
|
|
20
|
+
|
|
21
|
+
const init = async () => {
|
|
22
|
+
const actualUnit = await ensureUnit(identifier, unit)
|
|
23
|
+
|
|
24
|
+
cancelSubscription = await subscribeToChanges(identifier, async () => {
|
|
25
|
+
const value = await getMostRecentQuantitySample(identifier, actualUnit)
|
|
26
|
+
setLastSample(value)
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
void init()
|
|
30
|
+
|
|
31
|
+
return () => {
|
|
32
|
+
void cancelSubscription?.()
|
|
33
|
+
}
|
|
34
|
+
}, [identifier, unit])
|
|
35
|
+
|
|
36
|
+
return lastSample
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default useMostRecentQuantitySample
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useEffect, useState, useRef, useCallback,
|
|
3
|
+
} from 'react'
|
|
4
|
+
|
|
5
|
+
import getMostRecentWorkout from '../utils/getMostRecentWorkout'
|
|
6
|
+
import getPreferredUnitsTyped from '../utils/getPreferredUnitsTyped'
|
|
7
|
+
import subscribeToChanges from '../utils/subscribeToChanges'
|
|
8
|
+
|
|
9
|
+
import type { EnergyUnit, LengthUnit } from '../native-types'
|
|
10
|
+
import type { HKWorkout } from '../types'
|
|
11
|
+
|
|
12
|
+
function useMostRecentWorkout<
|
|
13
|
+
TEnergy extends EnergyUnit,
|
|
14
|
+
TDistance extends LengthUnit
|
|
15
|
+
>(options?: { readonly energyUnit?: TEnergy; readonly distanceUnit?: TDistance }) {
|
|
16
|
+
const [workout, setWorkout] = useState<HKWorkout<TEnergy, TDistance> | null>(null)
|
|
17
|
+
|
|
18
|
+
const optionsRef = useRef(options)
|
|
19
|
+
|
|
20
|
+
useEffect(() => {
|
|
21
|
+
optionsRef.current = options
|
|
22
|
+
}, [options])
|
|
23
|
+
|
|
24
|
+
const update = useCallback(async () => {
|
|
25
|
+
const { energyUnit, distanceUnit } = await getPreferredUnitsTyped(
|
|
26
|
+
optionsRef.current,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
console.log({ energyUnit, distanceUnit })
|
|
30
|
+
|
|
31
|
+
setWorkout(await getMostRecentWorkout({
|
|
32
|
+
energyUnit,
|
|
33
|
+
distanceUnit,
|
|
34
|
+
}))
|
|
35
|
+
}, [])
|
|
36
|
+
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
void update()
|
|
39
|
+
}, [update])
|
|
40
|
+
|
|
41
|
+
useEffect(() => {
|
|
42
|
+
let cancelSubscription: (() => Promise<boolean>) | undefined
|
|
43
|
+
|
|
44
|
+
const init = async () => {
|
|
45
|
+
cancelSubscription = await subscribeToChanges(
|
|
46
|
+
'HKWorkoutTypeIdentifier',
|
|
47
|
+
update,
|
|
48
|
+
)
|
|
49
|
+
}
|
|
50
|
+
void init()
|
|
51
|
+
|
|
52
|
+
return () => {
|
|
53
|
+
void cancelSubscription?.()
|
|
54
|
+
}
|
|
55
|
+
}, [update])
|
|
56
|
+
|
|
57
|
+
return workout
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export default useMostRecentWorkout
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import {
|
|
2
|
+
useState, useEffect, useCallback, useRef,
|
|
3
|
+
} from 'react'
|
|
4
|
+
|
|
5
|
+
import queryStatisticsForQuantity from '../utils/queryStatisticsForQuantity'
|
|
6
|
+
import useSubscribeToChanges from './useSubscribeToChanges'
|
|
7
|
+
|
|
8
|
+
import type { HKQuantityTypeIdentifier, HKStatisticsOptions, UnitForIdentifier } from '../native-types'
|
|
9
|
+
import type { QueryStatisticsResponse } from '../types'
|
|
10
|
+
|
|
11
|
+
function useStatisticsForQuantity<TIdentifier extends HKQuantityTypeIdentifier, TUnit extends UnitForIdentifier<TIdentifier> = UnitForIdentifier<TIdentifier>>(
|
|
12
|
+
identifier: TIdentifier,
|
|
13
|
+
options: readonly HKStatisticsOptions[],
|
|
14
|
+
from: Date,
|
|
15
|
+
to?: Date,
|
|
16
|
+
unit?: TUnit,
|
|
17
|
+
) {
|
|
18
|
+
const [result, setResult] = useState<QueryStatisticsResponse<TIdentifier, TUnit> | null>(null)
|
|
19
|
+
|
|
20
|
+
const optionsRef = useRef(options)
|
|
21
|
+
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
optionsRef.current = options
|
|
24
|
+
}, [options])
|
|
25
|
+
|
|
26
|
+
const update = useCallback(async () => {
|
|
27
|
+
const res = await queryStatisticsForQuantity(identifier, optionsRef.current, from, to, unit)
|
|
28
|
+
setResult(res)
|
|
29
|
+
}, [
|
|
30
|
+
identifier, from, to, unit,
|
|
31
|
+
])
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
void update()
|
|
35
|
+
}, [update])
|
|
36
|
+
|
|
37
|
+
useSubscribeToChanges(identifier, update)
|
|
38
|
+
|
|
39
|
+
return result
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export default useStatisticsForQuantity
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react'
|
|
2
|
+
|
|
3
|
+
import subscribeToChanges from '../utils/subscribeToChanges'
|
|
4
|
+
|
|
5
|
+
import type { HKSampleTypeIdentifier } from '..'
|
|
6
|
+
|
|
7
|
+
function useSubscribeToChanges<TIdentifier extends HKSampleTypeIdentifier>(
|
|
8
|
+
identifier: TIdentifier,
|
|
9
|
+
onChange: () => void,
|
|
10
|
+
): void {
|
|
11
|
+
const onChangeRef = useRef(onChange)
|
|
12
|
+
|
|
13
|
+
useEffect(() => {
|
|
14
|
+
onChangeRef.current = onChange
|
|
15
|
+
}, [onChange])
|
|
16
|
+
|
|
17
|
+
useEffect(() => {
|
|
18
|
+
let cancelSubscription: (() => Promise<boolean>) | undefined
|
|
19
|
+
|
|
20
|
+
const init = async () => {
|
|
21
|
+
cancelSubscription = await subscribeToChanges(identifier, onChangeRef.current)
|
|
22
|
+
}
|
|
23
|
+
void init()
|
|
24
|
+
|
|
25
|
+
return () => {
|
|
26
|
+
void cancelSubscription?.()
|
|
27
|
+
}
|
|
28
|
+
}, [identifier])
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export default useSubscribeToChanges
|