発生したエラー
- 動作上の不具合が発生した。
- 子Componentの
DragGesutreはきちんと反応している一方で、親ViewのScrollViewが一切動かなくなってしまった。
当該のコード
親View.swift
ScrollView {
// ForEachで画面が埋まるほど繰り返し生成されている
Component()
}
子Component.swift
//省略
.gesutre(
DragGesture()
)
解決策
-
DragGestureにminimumDistanceとcoordinateを設定する -
coordinateはローカル座標系。このComponentViewだけに適用するという意図なら.localで良いと思われる。
DragGesture(minimumDistance: 30, coorindate: .local)
謝辞
You can set minimumDistance to some value (for instance 30). Then the drag only works when you drag horizontally and reach the minimum distance, otherwise the scrollview or list gesture override the view gesture
.gesture(DragGesture(minimumDistance: 30, coordinateSpace: .local)