Skip to content

feat: serialize sub-activity activityType on WorkoutActivity#362

Open
TsSource wants to merge 2 commits into
kingstinct:masterfrom
TsSource:fix/serialize-workout-activity-type
Open

feat: serialize sub-activity activityType on WorkoutActivity#362
TsSource wants to merge 2 commits into
kingstinct:masterfrom
TsSource:fix/serialize-workout-activity-type

Conversation

@TsSource

Copy link
Copy Markdown

What

WorkoutProxy.activities currently serializes each HKWorkoutActivity as only { startDate, endDate, uuid, duration } — the sub-activity's activityType is dropped at the bridge (ios/WorkoutProxy.swift). This PR adds it:

  • WorkoutActivity gains readonly activityType: WorkoutActivityType (src/types/Workouts.ts)
  • the serializer reads it from activity.workoutConfiguration.activityType.rawValue, with the same ?? .other fallback idiom the parent workoutActivityType getter uses

One field, additive; nitrogen/generated is gitignored here so the diff is the two source files plus a changeset (minor).

Why

Without it, multisport (.swimBikeRun) workouts are opaque: consumers can see a triathlon has N sub-activities with time windows, but not which leg is the swim, the bike, or the run — duration/uuid alone can't type a leg, and ordering heuristics break for duathlons (run–bike–run). With the field, each leg can be typed directly off workoutConfiguration, transitions (.transition) can be filtered by raw value, and per-leg stats can be assembled from sample queries over each leg's window.

Verification

  • bun codegen regenerates the nitrogen output cleanly for the new field (standard enum-field codegen, same shape as WorkoutConfiguration.activityType); bun typecheck, bun lint, and bun run test all pass on this branch.
  • Verified in a consuming app (Expo SDK 57 / RN 0.82, new architecture): we ship this exact change against 14.0.2 via patch-package (TS interface + shipped d.ts + regenerated WorkoutActivity.hpp/WorkoutActivity.swift + the WorkoutProxy.swift serializer). The app's typecheck and full Jest suite are green, including tests that consume the typed legs end-to-end (triathlon → per-leg typing by field, transition filtering by raw value, duathlon order-independence); pod install consumes the patched pod source. We'd love to drop our patch in favor of an upstream release.

Notes

  • HR/stat queries and everything else are untouched; the field is additive so existing consumers are unaffected.
  • WorkoutActivityType.other fallback mirrors the existing parent-workout getter rather than force-unwrapping.

@changeset-bot

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: eb2f395

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

@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@362

commit: eb2f395

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 serialization support for sub-activities’ activityType on WorkoutProxy.activities, so consumers can distinguish legs in multisport workouts (e.g., triathlon swim/bike/run) instead of receiving only timing/identity fields.

Changes:

  • Added activityType: WorkoutActivityType to the WorkoutActivity TypeScript interface.
  • Updated the iOS WorkoutProxy serializer to include each sub-activity’s workoutConfiguration.activityType.
  • Added a changeset bumping @kingstinct/react-native-healthkit as a minor release for the additive field.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/react-native-healthkit/src/types/Workouts.ts Extends WorkoutActivity to include the new activityType field.
packages/react-native-healthkit/ios/WorkoutProxy.swift Serializes sub-activity activityType into WorkoutActivity objects returned to JS.
.changeset/serialize-workout-activity-type.md Declares a minor release and documents the new serialized field.

Comment on lines +377 to 381
duration: activity.duration,
activityType: WorkoutActivityType.init(
rawValue: Int32(activity.workoutConfiguration.activityType.rawValue)
) ?? WorkoutActivityType.other
)
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.

3 participants