Compare commits
2 Commits
3e7baecd27
...
3c9f551542
Author | SHA1 | Date |
---|---|---|
Shadowfacts | 3c9f551542 | |
Shadowfacts | 5acbf0f5c3 |
|
@ -0,0 +1,38 @@
|
|||
{
|
||||
"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,6 +17,7 @@ struct ContentView: View {
|
|||
return c
|
||||
}()
|
||||
@State var timer: Timer?
|
||||
@State var gestureState: GestureState = .none
|
||||
@State var initialXPosition: Int?
|
||||
|
||||
var body: some View {
|
||||
|
@ -40,7 +41,6 @@ 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,6 +50,8 @@ 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) }) {
|
||||
|
@ -73,26 +75,40 @@ struct ContentView: View {
|
|||
func horizDragGesture(geometry: GeometryProxy) -> some Gesture {
|
||||
DragGesture(coordinateSpace: .global)
|
||||
.onChanged { (state) in
|
||||
guard case .playing(.normal) = self.controller.state,
|
||||
guard self.gestureState != .vertical,
|
||||
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 {
|
||||
|
@ -133,6 +149,10 @@ 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