Skip to content

About

SwiftUI body map: muscle highlights, injection-site markers and soreness/injury areas. Geometry from react-native-body-highlighter (MIT).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

BodyMapKit

A SwiftUI front/back body map: tap muscle regions, drop injection-site markers, and paint soreness or injury areas. iOS 26, macOS 15, watchOS 26 (watchOS has no pinch gesture; handle drag and accessibility actions still resize). No dependencies.

Male back, female front and a custom dark style

Acknowledgements

The body artwork (muscle regions and silhouettes for male and female, front and back) is derived from react-native-body-highlighter by ELABBASSI Hicham, used under the MIT License. Thank you for making it available. BodyMapKit converts that project's SVG path data (version 3.2.0) into native SwiftUI shapes with a checked-in generator script; the original copyright and license text are kept in NOTICE.md and in the header of the generated geometry file. If you ship BodyMapKit in an app, include both notices (for example on an Acknowledgements screen).

Installation

Swift Package Manager:

.package(url: "https://github.com/greglose/BodyMapKit.git", from: "1.1.0")

then add "BodyMapKit" to your target's dependencies. In Xcode: File > Add Package Dependencies and paste the URL.

Three layers

Layer Folder What it is
Geometry Sources/BodyMapKit/Geometry Four variants (male/female x front/back), 23 muscles as normalized Paths, silhouette outline, BodyGeometry.region(at:in:) hit testing. GeneratedGeometry.swift is generated; never edit it.
Overlays Sources/BodyMapKit/Overlays Plain value types the host app owns and persists: BodyHighlight (region intensities), BodyPoint (dated markers), BodyArea (movable, resizable circles), BodyMapOverlay, BodyCoordinateSpace (normalized 0...1 <-> view points).
Views Sources/BodyMapKit/Views BodyMapView (humble SwiftUI shell), BodyMapViewModel (pure: drawables, VoiceOver elements, hit testing, editing rules), BodyMapStrings (String Catalog lookups in Bundle.module).

Regions are named <muscle>.<side> (BodyRegionID), where the side is the person's own left/right (gluteal.left, abs.center), not the viewer's.

Usage

import BodyMapKit

struct SoreMap: View {
    @State private var face: BodyFace = .back
    @State private var overlay = BodyMapOverlay(
        highlight: BodyHighlight(["gluteal.left": 0.6]),
        points: [BodyPoint(face: .back, location: CGPoint(x: 0.4, y: 0.5), date: .now, style: .injection, label: "Site 1")]
    )

    var body: some View {
        BodyMapView(
            sex: .male,
            face: $face,
            overlay: overlay,
            allowsAreaEditing: true,
            addAreaOnTap: .soreness,   // omit to make taps select-only
            onRegionTap: { print("region", $0) },
            onPointTap: { print("point", $0.label) },
            onAreaChange: { overlay.areas = $0 }   // full replacement list, every face
        )
    }
}

BodyMapView never mutates your model: edits come back through onAreaChange as the complete [BodyArea] (add, move, resize, intensity, delete); live drags preview locally and report once when they end.

Two independent switches:

  • allowsAreaEditing: true edits existing areas: drag to move, drag the handle or pinch to resize, long-press for Delete. VoiceOver gets an adjustable (swipe up/down changes intensity, the value it reads) plus actions "Increase/Decrease intensity", "Larger", "Smaller" and "Delete".
  • addAreaOnTap: .soreness (default nil) makes a tap on the body add an area of that kind, reported through onAreaChange, and does not also fire onRegionTap. With nil, taps only select (onRegionTap, onPointTap). VoiceOver activation of a region behaves like a visual tap (adds an area at the region centre, hint "Mark area here"), so there is no separate named action.

Point and area targets are at least 44pt. The front/back flip button honours Reduce Motion.

Zoom and pan

Zoom is on by default (zoomEnabled: true). Pinch on the body zooms 1x to 4x about the pinch centre (a pinch that starts on an area still resizes that area when allowsAreaEditing is on); double-tap zooms to 2.5x centred on the tap and double-tap again returns to 1x (instantly under Reduce Motion); when zoomed, a one-finger drag that does not start on an area or its handle pans, clamped so at least three quarters of the body's visible extent (more than half its visible area) stays on screen. Flipping front/back resets zoom. VoiceOver gets "Zoom in", "Zoom out" and "Reset zoom" actions on the map. watchOS has no pinch; double-tap and the actions work.

With zoom on, a single tap waits for the double-tap window before it fires (SwiftUI resolves tap versus double-tap exclusively); set zoomEnabled: false for immediate taps.

Markers, handles and their 44pt targets keep a constant on-screen size; area circles scale with the body. Pass a Binding<BodyMapViewport> to drive or observe zoom:

@State private var viewport = BodyMapViewport.identity

BodyMapView(sex: .male, face: $face, viewport: $viewport)
Button("Show glutes") {
    viewport = .focused(on: "gluteal.left", in: BodyVariant(sex: .male, face: face), size: mapSize)
}

BodyCoordinateSpace(variant:size:viewport:) includes zoom in toView, toBody and radius conversions.

Styling

Outline, muscle-group strokes, the unhighlighted fill and the selection ring are a BodyMapStyle; highlight colours stay in BodyHighlightPalette. An unhighlighted region uses regionFillColor; a highlighted region uses the palette ramp (an empty ramp falls back to regionFillColor; the palette holds only the ramp). Colours can differ per appearance, widths clamp to 0...10, and Increase Contrast multiplies outline and stroke opacity (increasedContrastOpacityScale, default 1.8).

let style = BodyMapStyle(
    outlineColor: BodyMapColor(light: .black, dark: .white, opacity: 0.8),
    outlineWidth: 2,
    regionFillColor: BodyMapColor(.gray, opacity: 0.12),
    selectedColor: BodyMapColor(.indigo)
)

BodyMapView(sex: .female, face: $face, style: style)      // one map
ContentView().bodyMapStyle(style)                         // every map below; an explicit `style:` wins

BodyMapStyle.default is the original look.

Localization

Resources/Localizable.xcstrings carries every key in 39 locales (the App Store Connect set) (plural variations for counts). Lookups go through BodyMapStrings with Bundle.module; swift test cannot compile catalogs, so English fallbacks live in code and a test keeps them equal to the catalog. Verify real resolution with xcodebuild.

Regenerating the geometry

npm pack react-native-body-highlighter@3.2.0 && mkdir upstream && tar -xzf react-native-body-highlighter-*.tgz -C upstream
python3 -I scripts/generate_geometry.py upstream/package

Tests

swift test
xcodebuild build -scheme BodyMapKit -destination 'platform=iOS Simulator,id=<udid>' -quiet

License

BodyMapKit is released under the MIT License; see LICENSE. The bundled body geometry is derived from react-native-body-highlighter (MIT, Copyright (c) 2022 ELABBASSI Hicham); see NOTICE.md.

About

SwiftUI body map: muscle highlights, injection-site markers and soreness/injury areas. Geometry from react-native-body-highlighter (MIT).

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages