Skip to content

feat: add queryActivitySummaries#358

Open
imikeyi03 wants to merge 6 commits into
kingstinct:masterfrom
imikeyi03:feat/activity-summary-query
Open

feat: add queryActivitySummaries#358
imikeyi03 wants to merge 6 commits into
kingstinct:masterfrom
imikeyi03:feat/activity-summary-query

Conversation

@imikeyi03

@imikeyi03 imikeyi03 commented Jun 10, 2026

Copy link
Copy Markdown

Summary

Adds a minimal queryActivitySummaries(startDate, endDate) API exposing HKActivitySummaryQuery — the per-day Apple activity-ring rollups (move/exercise/stand values and goals), which were previously unreachable from this library even though ActivitySummaryTypeIdentifier is already supported for authorization.

Closes #215.

API

const summaries = await queryActivitySummaries(startDate, endDate)
// → [{ dateYear, dateMonth, dateDay,
//      activeEnergyBurned, activeEnergyBurnedGoal,        // kcal
//      appleExerciseTime, appleExerciseTimeGoal,          // minutes
//      appleStandHours, appleStandHoursGoal,              // count
//      appleMoveTime, appleMoveTimeGoal }]                // minutes (move-minutes mode; 0 otherwise)

Design notes:

  • Dates are returned as calendar components (dateYear/dateMonth/dateDay) rather than a Date, because HKActivitySummary is keyed by DateComponents — converting to a timestamp would impose a timezone assumption on callers. The query inputs are reduced to day granularity in the user's current calendar, which is inherent to HKActivitySummaryQuery.
  • The predicate sets .calendar on both DateComponents (the classic HKActivitySummaryQuery gotcha — without it the query silently returns nothing).
  • New standalone ActivitySummaryModule mirroring the existing per-domain module structure (StateOfMindModule was the exemplar): nitro spec + nitro.json autolinking registration + Swift impl + bindRetypedMethod bindings + UnavailableFnFromModule fallback on non-iOS platforms.

Testing

  • bun codegen, bun typecheck, bun lint, bun run test all green locally.
  • Honest caveat: authored on Linux against Apple's documentation and this repo's module patterns — I could not run the example app on a device. I'd appreciate a maintainer validating the query on hardware; happy to iterate on anything (API shape included) in review.

@changeset-bot

changeset-bot Bot commented Jun 10, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 0d184df

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@kingstinct/react-native-healthkit Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@robertherber
robertherber requested a review from Copilot July 17, 2026 06:33
@pkg-pr-new

pkg-pr-new Bot commented Jul 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/kingstinct/react-native-healthkit/@kingstinct/react-native-healthkit@358

commit: 0d184df

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds first-class support for querying Apple HealthKit Activity Ring daily rollups by introducing a new Nitro-backed ActivitySummaryModule and exposing a queryActivitySummaries(startDate, endDate) API from the JS surface of react-native-healthkit.

Changes:

  • Introduces ActivitySummary TS type plus a new Nitro spec ActivitySummaryModule.nitro.ts for querying HKActivitySummaryQuery results.
  • Wires the new module through Nitro registration (nitro.json), JS module creation (modules.ts), and platform exports (healthkit.ts / healthkit.ios.ts).
  • Adds a changeset to publish the new API as a minor version bump.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/react-native-healthkit/src/types/index.ts Re-exports the new ActivitySummary type from the types barrel.
packages/react-native-healthkit/src/types/ActivitySummary.ts Defines the JS/TS shape for per-day activity ring values + goals.
packages/react-native-healthkit/src/specs/ActivitySummaryModule.nitro.ts Adds the Nitro module interface for queryActivitySummaries.
packages/react-native-healthkit/src/modules.ts Registers ActivitySummaryModule as a Nitro hybrid object factory.
packages/react-native-healthkit/src/healthkit.ts Exposes queryActivitySummaries with a non-iOS unavailable fallback and adds it to the default export object.
packages/react-native-healthkit/src/healthkit.ios.ts Binds and re-exports queryActivitySummaries on iOS via bindRetypedMethod.
packages/react-native-healthkit/nitro.json Adds Swift module autolinking registration for ActivitySummaryModule.
packages/react-native-healthkit/ios/ActivitySummaryModule.swift Implements HKActivitySummaryQuery execution and serialization to the Nitro-generated ActivitySummary type.
.changeset/itchy-pandas-applaud.md Declares a minor release for the new API.

Comment on lines +6 to +12
return Promise.async {
let calendar = Calendar.current

var startComponents = calendar.dateComponents(
[.day, .month, .year, .era], from: startDate)
var endComponents = calendar.dateComponents(
[.day, .month, .year, .era], from: endDate)
Comment on lines +23 to +29
let query = HKActivitySummaryQuery(predicate: predicate) { _, summaries, error in
if let error = error {
continuation.resume(throwing: error)
} else {
continuation.resume(returning: summaries ?? [])
}
}
Comment on lines +33 to +48
return summaries.map { summary in
let components = summary.dateComponents(for: calendar)
return ActivitySummary(
dateYear: Double(components.year ?? 0),
dateMonth: Double(components.month ?? 0),
dateDay: Double(components.day ?? 0),
activeEnergyBurned: summary.activeEnergyBurned.doubleValue(for: .kilocalorie()),
activeEnergyBurnedGoal: summary.activeEnergyBurnedGoal.doubleValue(for: .kilocalorie()),
appleExerciseTime: summary.appleExerciseTime.doubleValue(for: .minute()),
appleExerciseTimeGoal: summary.appleExerciseTimeGoal.doubleValue(for: .minute()),
appleStandHours: summary.appleStandHours.doubleValue(for: .count()),
appleStandHoursGoal: summary.appleStandHoursGoal.doubleValue(for: .count()),
appleMoveTime: summary.appleMoveTime.doubleValue(for: .minute()),
appleMoveTimeGoal: summary.appleMoveTimeGoal.doubleValue(for: .minute())
)
}
Comment on lines +9 to +12
queryActivitySummaries(
startDate: Date,
endDate: Date,
): Promise<ActivitySummary[]>
Comment on lines +301 to +312
const ActivitySummaryBindings = {
queryActivitySummaries: bindRetypedMethod<
typeof ActivitySummaries,
typeof ActivitySummaries.queryActivitySummaries,
Promise<ActivitySummary[]>
>(ActivitySummaries, ActivitySummaries.queryActivitySummaries),
} satisfies {
queryActivitySummaries: BoundMethod<
typeof ActivitySummaries.queryActivitySummaries,
Promise<ActivitySummary[]>
>
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: add support for querying Activity Summary objects from HealthKit

3 participants