@kingstinct/react-native-healthkit 4.1.0 → 4.3.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.
Files changed (42) hide show
  1. package/README.md +1 -1
  2. package/ios/ReactNativeHealthkit.m +15 -10
  3. package/ios/ReactNativeHealthkit.swift +364 -175
  4. package/lib/commonjs/index.ios.js +17 -8
  5. package/lib/commonjs/index.ios.js.map +1 -1
  6. package/lib/commonjs/index.js +9 -8
  7. package/lib/commonjs/index.js.map +1 -1
  8. package/lib/commonjs/native-types.js +17 -1
  9. package/lib/commonjs/native-types.js.map +1 -1
  10. package/lib/commonjs/types.js +4 -0
  11. package/lib/commonjs/types.js.map +1 -1
  12. package/lib/example/App.js +197 -0
  13. package/lib/index.ios.js +310 -0
  14. package/lib/index.js +44 -0
  15. package/lib/module/index.ios.js +17 -8
  16. package/lib/module/index.ios.js.map +1 -1
  17. package/lib/module/index.js +2 -1
  18. package/lib/module/index.js.map +1 -1
  19. package/lib/module/native-types.js +16 -1
  20. package/lib/module/native-types.js.map +1 -1
  21. package/lib/module/types.js +1 -1
  22. package/lib/module/types.js.map +1 -1
  23. package/lib/native-types.js +447 -0
  24. package/lib/src/index.ios.js +314 -0
  25. package/lib/src/index.js +45 -0
  26. package/lib/src/native-types.js +453 -0
  27. package/lib/src/types.js +1 -0
  28. package/lib/types.js +1 -0
  29. package/lib/typescript/src/index.d.ts +1 -1
  30. package/lib/typescript/src/index.ios.d.ts +1 -1
  31. package/lib/typescript/src/native-types.d.ts +29 -1
  32. package/lib/typescript/src/types.d.ts +3 -1
  33. package/package.json +8 -7
  34. package/src/index.ios.tsx +17 -12
  35. package/src/index.tsx +2 -1
  36. package/src/native-types.ts +65 -33
  37. package/src/types.ts +8 -2
  38. package/ios/.DS_Store +0 -0
  39. package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -4
  40. package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  41. package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/xcuserdata/robertherber.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  42. package/ios/ReactNativeHealthkit.xcodeproj/xcuserdata/robertherber.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
package/src/index.ios.tsx CHANGED
@@ -1,4 +1,4 @@
1
- import { useState, useEffect, useCallback } from 'react';
1
+ import { useCallback, useEffect, useState } from 'react';
2
2
  import Native, {
3
3
  EventEmitter,
4
4
  HKCategorySampleRaw,
@@ -23,6 +23,7 @@ import type {
23
23
  GetMostRecentWorkoutFn,
24
24
  GetPreferredUnitFn,
25
25
  GetPreferredUnitsFn,
26
+ GetWorkoutRoutesFn,
26
27
  HKCategorySample,
27
28
  HKCorrelation,
28
29
  HKQuantitySample,
@@ -291,16 +292,14 @@ const queryStatisticsForQuantity: QueryStatisticsForQuantityFn = async (
291
292
  ) => {
292
293
  const actualUnit = await ensureUnit(identifier, unit);
293
294
  const toDate = to || new Date();
294
- const {
295
- mostRecentQuantityDateInterval,
296
- ...rawResponse
297
- } = await Native.queryStatisticsForQuantity(
298
- identifier,
299
- actualUnit,
300
- from.toISOString(),
301
- toDate.toISOString(),
302
- options
303
- );
295
+ const { mostRecentQuantityDateInterval, ...rawResponse } =
296
+ await Native.queryStatisticsForQuantity(
297
+ identifier,
298
+ actualUnit,
299
+ from.toISOString(),
300
+ toDate.toISOString(),
301
+ options
302
+ );
304
303
 
305
304
  const response = {
306
305
  ...rawResponse,
@@ -531,6 +530,10 @@ const saveWorkoutSample: SaveWorkoutSampleFn = (
531
530
  );
532
531
  };
533
532
 
533
+ const getWorkoutRoutes: GetWorkoutRoutesFn = (workoutUUID: string) => {
534
+ return Native.getWorkoutRoutes(workoutUUID);
535
+ };
536
+
534
537
  const Healthkit: ReactNativeHealthkit = {
535
538
  authorizationStatusFor: Native.authorizationStatusFor,
536
539
 
@@ -557,6 +560,8 @@ const Healthkit: ReactNativeHealthkit = {
557
560
  getPreferredUnits,
558
561
  getRequestStatusForAuthorization,
559
562
 
563
+ getWorkoutRoutes,
564
+
560
565
  // query methods
561
566
  queryCategorySamples,
562
567
  queryCorrelationSamples,
@@ -584,7 +589,7 @@ const Healthkit: ReactNativeHealthkit = {
584
589
  useSubscribeToChanges,
585
590
  };
586
591
 
587
- export * from './types';
588
592
  export * from './native-types';
593
+ export * from './types';
589
594
 
590
595
  export default Healthkit;
package/src/index.tsx CHANGED
@@ -27,6 +27,7 @@ const Healthkit: ReactNativeHealthkit = {
27
27
  getPreferredUnits: UnavailableFn,
28
28
  getRequestStatusForAuthorization: UnavailableFn,
29
29
  getWheelchairUse: UnavailableFn,
30
+ getWorkoutRoutes: UnavailableFn,
30
31
  isHealthDataAvailable: () => Promise.resolve(false),
31
32
  queryCategorySamples: UnavailableFn,
32
33
  queryCorrelationSamples: UnavailableFn,
@@ -45,7 +46,7 @@ const Healthkit: ReactNativeHealthkit = {
45
46
  useSubscribeToChanges: UnavailableFn,
46
47
  };
47
48
 
48
- export * from './types';
49
49
  export * from './native-types';
50
+ export * from './types';
50
51
 
51
52
  export default Healthkit;
@@ -1,7 +1,7 @@
1
1
  import {
2
- NativeModules,
3
- NativeEventEmitter,
4
2
  EmitterSubscription,
3
+ NativeEventEmitter,
4
+ NativeModules,
5
5
  } from 'react-native';
6
6
 
7
7
  export type HKWorkoutTypeIdentifier = 'HKWorkoutTypeIdentifier';
@@ -279,6 +279,15 @@ export enum HKQuantityTypeIdentifier {
279
279
  dietaryCaffeine = 'HKQuantityTypeIdentifierDietaryCaffeine', // Mass, Cumulative
280
280
  dietaryWater = 'HKQuantityTypeIdentifierDietaryWater', // Volume, Cumulative
281
281
 
282
+ // Mobility
283
+ sixMinuteWalkTestDistance = 'HKQuantityTypeIdentifierSixMinuteWalkTestDistance',
284
+ walkingSpeed = 'HKQuantityTypeIdentifierWalkingSpeed',
285
+ walkingStepLength = 'HKQuantityTypeIdentifierWalkingStepLength',
286
+ walkingAsymmetryPercentage = 'HKQuantityTypeIdentifierWalkingAsymmetryPercentage',
287
+ walkingDoubleSupportPercentage = 'HKQuantityTypeIdentifierWalkingDoubleSupportPercentage',
288
+ stairAscentSpeed = 'HKQuantityTypeIdentifierStairAscentSpeed',
289
+ stairDescentSpeed = 'HKQuantityTypeIdentifierStairDescentSpeed',
290
+
282
291
  uvExposure = 'HKQuantityTypeIdentifierUvExposure', // Scalar (Count), Discrete
283
292
  }
284
293
 
@@ -288,6 +297,12 @@ export enum HKAuthorizationRequestStatus {
288
297
  unnecessary = 2,
289
298
  }
290
299
 
300
+ export enum HKAuthorizationStatus {
301
+ notDetermined = 0,
302
+ sharingDenied = 1,
303
+ sharingAuthorized = 2,
304
+ }
305
+
291
306
  export type HKQuantity<T extends HKUnit = HKUnit> = {
292
307
  unit: T;
293
308
  quantity: number;
@@ -436,27 +451,26 @@ export type MetadataMapperForCorrelationIdentifier<
436
451
  }
437
452
  : HKGenericMetadata;
438
453
 
439
- export type HKCategoryValueForIdentifier<
440
- T extends HKCategoryTypeIdentifier
441
- > = T extends HKCategoryTypeIdentifier.cervicalMucusQuality
442
- ? HKCategoryValueCervicalMucusQuality
443
- : T extends HKCategoryTypeIdentifier.menstrualFlow
444
- ? HKCategoryValueMenstrualFlow
445
- : T extends HKCategoryTypeIdentifier.ovulationTestResult
446
- ? HKCategoryValueOvulationTestResult
447
- : T extends HKCategoryTypeIdentifier.sleepAnalysis
448
- ? HKCategoryValueSleepAnalysis
449
- : T extends HKCategoryTypeIdentifier.mindfulSession
450
- ? HKCategoryValueNotApplicable
451
- : T extends HKCategoryTypeIdentifier.intermenstrualBleeding
452
- ? HKCategoryValueNotApplicable
453
- : T extends HKCategoryTypeIdentifier.highHeartRateEvent
454
- ? HKCategoryValueNotApplicable
455
- : T extends HKCategoryTypeIdentifier.sexualActivity
456
- ? HKCategoryValueNotApplicable
457
- : T extends HKCategoryTypeIdentifier.appleStandHour
458
- ? HKCategoryValueAppleStandHour
459
- : number;
454
+ export type HKCategoryValueForIdentifier<T extends HKCategoryTypeIdentifier> =
455
+ T extends HKCategoryTypeIdentifier.cervicalMucusQuality
456
+ ? HKCategoryValueCervicalMucusQuality
457
+ : T extends HKCategoryTypeIdentifier.menstrualFlow
458
+ ? HKCategoryValueMenstrualFlow
459
+ : T extends HKCategoryTypeIdentifier.ovulationTestResult
460
+ ? HKCategoryValueOvulationTestResult
461
+ : T extends HKCategoryTypeIdentifier.sleepAnalysis
462
+ ? HKCategoryValueSleepAnalysis
463
+ : T extends HKCategoryTypeIdentifier.mindfulSession
464
+ ? HKCategoryValueNotApplicable
465
+ : T extends HKCategoryTypeIdentifier.intermenstrualBleeding
466
+ ? HKCategoryValueNotApplicable
467
+ : T extends HKCategoryTypeIdentifier.highHeartRateEvent
468
+ ? HKCategoryValueNotApplicable
469
+ : T extends HKCategoryTypeIdentifier.sexualActivity
470
+ ? HKCategoryValueNotApplicable
471
+ : T extends HKCategoryTypeIdentifier.appleStandHour
472
+ ? HKCategoryValueAppleStandHour
473
+ : number;
460
474
 
461
475
  export type MetadataMapperForCategoryIdentifier<
462
476
  T extends HKCategoryTypeIdentifier
@@ -635,15 +649,14 @@ export type HKCategorySampleRaw<
635
649
  sourceRevision?: HKSourceRevision;
636
650
  };
637
651
 
638
- export type HKCorrelationRaw<
639
- TIdentifier extends HKCorrelationTypeIdentifier
640
- > = {
641
- correlationType: HKCorrelationTypeIdentifier;
642
- objects: (HKQuantitySampleRaw | HKCategorySampleRaw)[];
643
- metadata: MetadataMapperForCorrelationIdentifier<TIdentifier>;
644
- startDate: string;
645
- endDate: string;
646
- };
652
+ export type HKCorrelationRaw<TIdentifier extends HKCorrelationTypeIdentifier> =
653
+ {
654
+ correlationType: HKCorrelationTypeIdentifier;
655
+ objects: (HKQuantitySampleRaw | HKCategorySampleRaw)[];
656
+ metadata: MetadataMapperForCorrelationIdentifier<TIdentifier>;
657
+ startDate: string;
658
+ endDate: string;
659
+ };
647
660
 
648
661
  type QueryId = string;
649
662
 
@@ -659,6 +672,23 @@ export enum HKUpdateFrequency {
659
672
  weekly = 4,
660
673
  }
661
674
 
675
+ export type WorkoutLocation = {
676
+ longitude: number;
677
+ latitude: number;
678
+ altitude: number;
679
+ speed: number;
680
+ timestamp: number;
681
+ horizontalAccuracy: number;
682
+ speedAccuracy: number;
683
+ verticalAccuracy: number;
684
+ };
685
+
686
+ export type WorkoutRoute = {
687
+ locations: WorkoutLocation[];
688
+ HKMetadataKeySyncIdentifier?: string;
689
+ HKMetadataKeySyncVersion?: number;
690
+ };
691
+
662
692
  type ReactNativeHealthkitTypeNative = {
663
693
  isHealthDataAvailable(): Promise<boolean>;
664
694
  getBloodType(): Promise<HKBloodType>;
@@ -770,9 +800,11 @@ type ReactNativeHealthkitTypeNative = {
770
800
  getPreferredUnits: (
771
801
  identifiers: HKQuantityTypeIdentifier[]
772
802
  ) => Promise<TypeToUnitMapping>;
803
+ getWorkoutRoutes: (workoutUUID: string) => Promise<WorkoutRoute[]>;
773
804
  };
774
805
 
775
- const Native = NativeModules.ReactNativeHealthkit as ReactNativeHealthkitTypeNative;
806
+ const Native =
807
+ NativeModules.ReactNativeHealthkit as ReactNativeHealthkitTypeNative;
776
808
 
777
809
  type OnChangeCallback = ({
778
810
  typeIdentifier,
package/src/types.ts CHANGED
@@ -9,7 +9,6 @@ import type {
9
9
  HKCorrelationRaw,
10
10
  HKCorrelationTypeIdentifier,
11
11
  HKFitzpatrickSkinType,
12
- MetadataMapperForCategoryIdentifier,
13
12
  HKQuantitySampleRaw,
14
13
  HKQuantityTypeIdentifier,
15
14
  HKSampleTypeIdentifier,
@@ -17,14 +16,16 @@ import type {
17
16
  HKUnit,
18
17
  HKUnitSI,
19
18
  HKUnitSIPrefix,
19
+ HKUpdateFrequency,
20
20
  HKWheelchairUse,
21
21
  HKWorkoutActivityType,
22
22
  HKWorkoutMetadata,
23
23
  HKWorkoutRaw,
24
+ MetadataMapperForCategoryIdentifier,
24
25
  MetadataMapperForCorrelationIdentifier,
25
26
  MetadataMapperForQuantityIdentifier,
26
27
  QueryStatisticsResponseRaw,
27
- HKUpdateFrequency,
28
+ WorkoutRoute,
28
29
  } from './native-types';
29
30
 
30
31
  export interface QueryWorkoutsOptions<
@@ -268,6 +269,10 @@ export type SubscribeToChangesHook = <
268
269
  runInitialUpdate?: boolean
269
270
  ) => void;
270
271
 
272
+ export type GetWorkoutRoutesFn = (
273
+ workoutUUID: string
274
+ ) => Promise<WorkoutRoute[]>;
275
+
271
276
  export type ReactNativeHealthkit = {
272
277
  authorizationStatusFor: AuthorizationStatusForFn;
273
278
 
@@ -282,6 +287,7 @@ export type ReactNativeHealthkit = {
282
287
  getPreferredUnits: GetPreferredUnitsFn;
283
288
  getRequestStatusForAuthorization: GetRequestStatusForAuthorizationFn;
284
289
  getWheelchairUse: GetWheelchairUseFn;
290
+ getWorkoutRoutes: GetWorkoutRoutesFn;
285
291
 
286
292
  buildUnitWithPrefix: (prefix: HKUnitSIPrefix, unit: HKUnitSI) => HKUnit;
287
293
 
package/ios/.DS_Store DELETED
Binary file
@@ -1,4 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <Workspace
3
- version = "1.0">
4
- </Workspace>
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>IDEDidComputeMac32BitWarning</key>
6
- <true/>
7
- </dict>
8
- </plist>
@@ -1,14 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>SchemeUserState</key>
6
- <dict>
7
- <key>ReactNativeHealthkit.xcscheme_^#shared#^_</key>
8
- <dict>
9
- <key>orderHint</key>
10
- <integer>0</integer>
11
- </dict>
12
- </dict>
13
- </dict>
14
- </plist>