Skip to content

feat: serialize HKWorkoutEvent.metadata in workout queries#333

Closed
sh940701 wants to merge 4 commits intokingstinct:masterfrom
sh940701:feat/serialize-workout-event-metadata
Closed

feat: serialize HKWorkoutEvent.metadata in workout queries#333
sh940701 wants to merge 4 commits intokingstinct:masterfrom
sh940701:feat/serialize-workout-event-metadata

Conversation

@sh940701
Copy link
Contributor

Summary

This PR adds metadata serialization to WorkoutEvent, making per-event metadata from HKWorkoutEvent available to JS consumers.

Closes #332

Changes

packages/react-native-healthkit/src/types/Workouts.ts

Added optional metadata field to WorkoutEvent interface using AnyMap from react-native-nitro-modules, consistent with how BaseObject.metadata is typed:

export interface WorkoutEvent {
  readonly type: WorkoutEventType
  readonly startDate: Date
  readonly endDate: Date
  readonly metadata?: AnyMap  // new
}

packages/react-native-healthkit/ios/WorkoutProxy.swift

Pass event.metadata through the existing serializeMetadata() helper in the events computed property:

return WorkoutEvent(
  type: type,
  startDate: event.dateInterval.start,
  endDate: event.dateInterval.end,
  metadata: serializeMetadata(event.metadata)  // new
)

Motivation

Apple's HKWorkoutEvent has a metadata: [String: Any]? property. For swimming workouts, Apple documents that HKMetadataKeySwimmingStrokeStyle should be "set on workout lap events". Without event metadata, consumers cannot access per-lap stroke style through the documented path.

Backward compatibility

  • metadata is optional (AnyMap?) — existing consumers are unaffected
  • Reuses the existing serializeMetadata() helper (already used for workout metadata, sample metadata, and route metadata)
  • serializeMetadata() handles nil input gracefully (returns empty map)

Note

I haven't run bun codegen locally since Nitrogen may need to regenerate types for the new metadata field on WorkoutEvent. Happy to update if the generated output needs adjustment — just let me know.

Add optional metadata field to WorkoutEvent interface and pass
event.metadata through serializeMetadata() in WorkoutProxy.swift.

This exposes per-event metadata from HealthKit workout queries,
most notably HKSwimmingStrokeStyle on swimming lap events.

Closes kingstinct#332
Serialize HKWorkoutEvent.metadata using the existing serializeMetadata()
helper, making per-event metadata available to JS consumers.

This is particularly useful for swimming workouts where lap events carry
HKSwimmingStrokeStyle in their metadata.
@changeset-bot
Copy link

changeset-bot bot commented Mar 23, 2026

⚠️ No Changeset found

Latest commit: c99a57f

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

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

@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 23, 2026

Open in StackBlitz

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

commit: c99a57f

@sh940701
Copy link
Contributor Author

Closing to resubmit with a clean commit history — the branch had intermediate commits that shouldn't be in the final PR.

@sh940701 sh940701 closed this Mar 23, 2026
@sh940701 sh940701 deleted the feat/serialize-workout-event-metadata branch March 23, 2026 09:02
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.

feat: serialize HKWorkoutEvent.metadata in workout query results

1 participant