Compare commits
No commits in common. "3c9f5515421c8c473009c292c7a67cd52378bce0" and "3e7baecd27ea0e8586284d7ab18204d9ba3f0e82" have entirely different histories.
3c9f551542
...
3e7baecd27
|
@ -1,38 +0,0 @@
|
|||
{
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
},
|
||||
"colors" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"red" : "1.000",
|
||||
"alpha" : "1.000",
|
||||
"blue" : "1.000",
|
||||
"green" : "1.000"
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"appearances" : [
|
||||
{
|
||||
"appearance" : "luminosity",
|
||||
"value" : "dark"
|
||||
}
|
||||
],
|
||||
"color" : {
|
||||
"color-space" : "srgb",
|
||||
"components" : {
|
||||
"red" : "0.000",
|
||||
"alpha" : "1.000",
|
||||
"blue" : "0.000",
|
||||
"green" : "0.000"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
|
@ -17,7 +17,6 @@ struct ContentView: View {
|
|||
return c
|
||||
}()
|
||||
@State var timer: Timer?
|
||||
@State var gestureState: GestureState = .none
|
||||
@State var initialXPosition: Int?
|
||||
|
||||
var body: some View {
|
||||
|
@ -41,6 +40,7 @@ struct ContentView: View {
|
|||
.onAppear(perform: self.startTimer)
|
||||
.onDisappear(perform: self.stopTimer)
|
||||
.onTapGesture(perform: self.onTap)
|
||||
.gesture(self.horizDragGesture(geometry: geometry).simultaneously(with: self.verticalDragGesture))
|
||||
// .gesture(ExclusiveGesture(horizDragGesture, verticalDragGesture))
|
||||
// .gesture(horizDragGesture.simultaneously(with: verticalDragGesture))
|
||||
|
||||
|
@ -50,8 +50,6 @@ struct ContentView: View {
|
|||
}
|
||||
.padding(.trailing, 8)
|
||||
}
|
||||
.background(Color("TempBackground")) // visually does nothing but lets the gesture work outside of the board, see FB7385742
|
||||
.gesture(self.horizDragGesture(geometry: geometry).simultaneously(with: self.verticalDragGesture))
|
||||
Spacer()
|
||||
HStack {
|
||||
Button(action: { self.controller.rotate(direction: .counterClockwise) }) {
|
||||
|
@ -75,40 +73,26 @@ struct ContentView: View {
|
|||
func horizDragGesture(geometry: GeometryProxy) -> some Gesture {
|
||||
DragGesture(coordinateSpace: .global)
|
||||
.onChanged { (state) in
|
||||
guard self.gestureState != .vertical,
|
||||
case .playing(.normal) = self.controller.state,
|
||||
guard case .playing(.normal) = self.controller.state,
|
||||
let currentPiece = self.controller.currentPiece else { return }
|
||||
if self.initialXPosition == nil {
|
||||
self.initialXPosition = currentPiece.topLeft.0
|
||||
}
|
||||
var moved = currentPiece
|
||||
let xPosition = self.initialXPosition! + Int((state.translation.width / (geometry.size.width / 10)).rounded())
|
||||
|
||||
if xPosition != self.initialXPosition {
|
||||
self.gestureState = .horizontal
|
||||
}
|
||||
moved.topLeft = (xPosition, currentPiece.topLeft.1)
|
||||
if !self.controller.overlapsAny(moved) {
|
||||
self.controller.currentPiece = moved
|
||||
}
|
||||
}.onEnded { (state) in
|
||||
self.initialXPosition = nil
|
||||
if self.gestureState == .horizontal {
|
||||
self.gestureState = .none
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var verticalDragGesture: some Gesture {
|
||||
DragGesture()
|
||||
.onChanged({ (state) in
|
||||
guard self.gestureState != .horizontal else { return }
|
||||
|
||||
})
|
||||
.onEnded { (state) in
|
||||
guard self.gestureState != .horizontal else { return }
|
||||
if abs(state.translation.height) > 80 {
|
||||
self.gestureState = .none
|
||||
if state.translation.height > 0 {
|
||||
self.onSwipeDown()
|
||||
} else {
|
||||
|
@ -149,10 +133,6 @@ struct ContentView: View {
|
|||
}
|
||||
}
|
||||
|
||||
enum GestureState: Equatable {
|
||||
case none, horizontal, vertical
|
||||
}
|
||||
|
||||
struct ContentView_Previews: PreviewProvider {
|
||||
static var previews: some View {
|
||||
ContentView()
|
||||
|
|
Loading…
Reference in New Issue