Repository navigation
feat: query Apple HealthKit activity summaries - #397
Merged
robertherber merged 1 commit intoOct 9, 2026
Merged
Conversation
🦋 Changeset detectedLatest commit: c21a9e9 The changes in this PR will be included in the next version bump. This PR includes changesets to release 3 packages
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 |
michaelyta
marked this pull request as ready for review
October 9, 2026 01:12
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR introduces the
queryActivitySummaryAPI, exposing HealthKit'sHKActivitySummaryQuery. This allows consumers to read Apple Watch activity ring rollups and goals (active energy burned/goal, exercise time/goal, stand hours/goal, move time, and move mode) for single days or date ranges.Closes #215.
API Reference
Return Type
Design of the Change
Nitro Specification (
CoreModule.nitro.ts) & Types:queryActivitySummaryis added as an async method toCoreModule. Type definitions match HealthKit'sHKActivitySummarystructure and use the existing Nitro quantity wrappers (QuantityType<...>), keeping returned quantities strongly typed with their respective units (kilocalorie,minute,count).Native Swift Implementation (
CoreModule.swift):HealthKit requires
DateComponentswith an assigned calendar to build activity summary predicates. I convert the JS input dates toCalendar.currentdate components with.year,.month,.day,.era.To construct the query predicate, HealthKit exposes different factory methods depending on whether both dates, one date, or no date bounds are provided (
forActivitySummariesBetweenStart:end:crashes if givennilarguments). A clean Swift pattern-matching switch handles each variation:Serialization (
Serializers.swift):HKActivitySummaryis a composite object that does not conform toHKSample. A dedicatedserializeActivitySummaryserializer unwraps all goal and burned quantities usingserializeQuantityTyped, convertsdateComponents(for: Calendar.current), handlesactivityMoveModeenum mapping, and conditionally gatesisPausedbehind iOS 18 / Swift 6 availability checks.Multiplatform & Testing Stubs:
Exposed in
healthkit.ios.ts, stubbed withcreateUnavailableFninhealthkit.tsfor non-iOS platforms, and mocked intest-setup.ts.Testing & Verification
queryActivitySummary.test.tsvalidating filter constructions, date components, and enum lookups.bun run typecheck,bun run lint, andbun run swiftlint.I verified the native bridge and UI flow inside the example app. Note that the standalone iOS Simulator does not calculate or synthesize daily
HKActivitySummaryrollups (even when manually inserting raw active energy or workout samples in the Health app,HKActivitySummaryQueryreturns an empty array on simulator environments). To verify the bridge, serialization, and React Native UI rendering end-to-end on simulator, I temporarily mocked anHKActivitySummaryinstance in Swift and confirmed it rendered all values and units correctly.Because running the example app directly on a physical device hit provisioning profile/signing constraints with its bundle identifier, I packaged this patch and locally linked it into a fitness app I'm working on running on a physical iPhone. Calling
queryActivitySummary()successfully queried and returned real Apple Watch Activity Rings data (energy burned, exercise time, stand hours, and goals).