UNPKG

react-native-healthkit-bridge

Version:

A comprehensive React Native bridge for Apple HealthKit with TypeScript support, advanced authorization, and flexible data queries

79 lines (63 loc) 3.32 kB
import { NativeModules } from 'react-native'; import { HealthKitDataSource } from './HealthKitDataSource'; import { AuthorizationStatus, HealthKitTypeInfo } from '../../domain/repositories/HealthKitRepository'; import { HealthKitAuthorizationStatusItem } from '../../../core/types/HealthKitTypes'; import { HealthKitSample, HealthKitCategorySample, HealthKitWorkout } from '../../domain/entities/HealthKitSample'; export class NativeHealthKitDataSource implements HealthKitDataSource { private nativeModule = NativeModules.HealthKitBridge; async requestAuthorization(): Promise<boolean> { return await this.nativeModule.requestAuthorization(); } async requestSelectiveAuthorization(readTypes: string[], writeTypes: string[] = []): Promise<boolean> { return await this.nativeModule.requestSelectiveAuthorization(readTypes, writeTypes); } async getAuthorizationStatus(identifiers: string[]): Promise<HealthKitAuthorizationStatusItem[]> { const status = await this.nativeModule.getAuthorizationStatus(identifiers); return status.map((item: any) => ({ identifier: item.identifier, status: item.status })); } async getAvailableTypes(): Promise<HealthKitTypeInfo[]> { return await this.nativeModule.getAvailableTypes(); } async getTypeInfo(identifier: string): Promise<HealthKitTypeInfo> { return await this.nativeModule.getTypeInfo(identifier); } async getQuantitySamplesForDays(identifier: string, unit: string, days: number): Promise<HealthKitSample[]> { return await this.nativeModule.getQuantitySamplesForDays(identifier, unit, days); } async getCategorySamplesForDays(identifier: string, days: number): Promise<HealthKitCategorySample[]> { return await this.nativeModule.getCategorySamplesForDays(identifier, days); } async getWorkoutsForDays(days: number): Promise<HealthKitWorkout[]> { return await this.nativeModule.getWorkoutsForDays(days); } async getQuantitySamplesForRange(identifier: string, unit: string, startDate: string, endDate: string): Promise<HealthKitSample[]> { return await this.nativeModule.getQuantitySamplesForRange(identifier, unit, startDate, endDate); } async getCategorySamplesForRange(identifier: string, startDate: string, endDate: string): Promise<HealthKitCategorySample[]> { return await this.nativeModule.getCategorySamplesForRange(identifier, startDate, endDate); } async getWorkoutsForRange(startDate: string, endDate: string): Promise<HealthKitWorkout[]> { return await this.nativeModule.getWorkoutsForRange(startDate, endDate); } async getQuantitySamplesWithRange(identifier: string, unit: string, startDate: number, endDate: number): Promise<number[]> { return await this.nativeModule.getQuantitySamplesWithRange(identifier, unit, startDate, endDate); } async getCategorySamplesWithRange(identifier: string, startDate: number, endDate: number): Promise<HealthKitCategorySample[]> { return await this.nativeModule.getCategorySamplesWithRange(identifier, startDate, endDate); } async getWorkoutsWithRange(startDate: number, endDate: number): Promise<HealthKitWorkout[]> { return await this.nativeModule.getWorkoutsWithRange(startDate, endDate); } isAvailable(): boolean { return this.nativeModule.isAvailable(); } }