Rebuilds the sample app in the WWDC 2019 Session 223 using SwiftUI.
- 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
I could not figure out how to add bounds to the drag interaction properly. I came up with two options:
- 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.
- 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.