Skip to content

Latest commit

 

History

History
19 lines (15 loc) · 1.89 KB

README.md

File metadata and controls

19 lines (15 loc) · 1.89 KB

Core Haptics Palette

Rebuilds the sample app in the WWDC 2019 Session 223 using SwiftUI.

A screenshot of the HapticPalette interface, showing a labeled circle and the meaning of coordinate axes controlling intensity and sharpness.

Currently WIP

  • Building UI
  • Adding drag interaction
  • Adding bounds to the drag interaction
  • Calculating parameters using the position of the circle
  • Adding Core Haptics
  • Dark mode support

Discussion

I could not figure out how to add bounds to the drag interaction properly. I came up with two options:

  1. Save gesture data as @State, and calculate the offset of the circle using the frame data of GeometryReader. However, when the circle is dragged out of the rectangle, though the circle stays inside the rectangle near the edge, the gesture data still includes part of the offset which exceeeds the frame of the rectangle (because the calculation is inside the "body"). When dragging the circle back to the center of the rectangle, the circle doesn't move at all at first.
  2. Calculate offset inside gesture's "updating" modifier. But you simply cannot get the frame of the rectangle outside of the "body". And the frame can change dramatically, like when rotating the device or using split screen etc. This means you have to listen to the layout event, which in my opinion doesn't comply with what SwiftUI is all about.

So maybe it's time to pause the project, and learn more about SwiftUI now.