Merge commit 'e9a4a9347a1000386e148a490a28d601c3bd0db3' into bazel

This commit is contained in:
Ali
2020-03-01 19:10:10 +04:00
138 changed files with 6773 additions and 5008 deletions

View File

@@ -1,16 +1,23 @@
import Foundation
import UIKit
private func hasHorizontalGestures(_ view: UIView, point: CGPoint?) -> Bool {
if view.disablesInteractiveTransitionGestureRecognizer {
return true
}
private enum HorizontalGestures {
case none
case some
case strict
}
private func hasHorizontalGestures(_ view: UIView, point: CGPoint?) -> HorizontalGestures {
if let disablesInteractiveTransitionGestureRecognizerNow = view.disablesInteractiveTransitionGestureRecognizerNow, disablesInteractiveTransitionGestureRecognizerNow() {
return true
return .strict
}
if view.disablesInteractiveTransitionGestureRecognizer {
return .some
}
if let point = point, let test = view.interactiveTransitionGestureRecognizerTest, test(point) {
return true
return .some
}
if let view = view as? ListViewBackingView {
@@ -20,14 +27,14 @@ private func hasHorizontalGestures(_ view: UIView, point: CGPoint?) -> Bool {
let term2: Double = abs(angle + Double.pi / 2.0)
let term3: Double = abs(angle - Double.pi * 3.0 / 2.0)
if term1 < 0.001 || term2 < 0.001 || term3 < 0.001 {
return true
return .some
}
}
if let superview = view.superview {
return hasHorizontalGestures(superview, point: point != nil ? view.convert(point!, to: superview) : nil)
} else {
return false
return .none
}
}
@@ -38,18 +45,23 @@ public struct InteractiveTransitionGestureRecognizerDirections: OptionSet {
self.rawValue = rawValue
}
public static let left = InteractiveTransitionGestureRecognizerDirections(rawValue: 1 << 0)
public static let right = InteractiveTransitionGestureRecognizerDirections(rawValue: 1 << 1)
public static let leftEdge = InteractiveTransitionGestureRecognizerDirections(rawValue: 1 << 2)
public static let rightEdge = InteractiveTransitionGestureRecognizerDirections(rawValue: 1 << 3)
public static let leftCenter = InteractiveTransitionGestureRecognizerDirections(rawValue: 1 << 0)
public static let rightCenter = InteractiveTransitionGestureRecognizerDirections(rawValue: 1 << 1)
public static let left: InteractiveTransitionGestureRecognizerDirections = [.leftEdge, .leftCenter]
public static let right: InteractiveTransitionGestureRecognizerDirections = [.rightEdge, .rightCenter]
}
public class InteractiveTransitionGestureRecognizer: UIPanGestureRecognizer {
private let allowedDirections: () -> InteractiveTransitionGestureRecognizerDirections
private let allowedDirections: (CGPoint) -> InteractiveTransitionGestureRecognizerDirections
private var validatedGesture = false
private var firstLocation: CGPoint = CGPoint()
private var currentAllowedDirections: InteractiveTransitionGestureRecognizerDirections = []
public init(target: Any?, action: Selector?, allowedDirections: @escaping () -> InteractiveTransitionGestureRecognizerDirections) {
public init(target: Any?, action: Selector?, allowedDirections: @escaping (CGPoint) -> InteractiveTransitionGestureRecognizerDirections) {
self.allowedDirections = allowedDirections
super.init(target: target, action: action)
@@ -65,37 +77,68 @@ public class InteractiveTransitionGestureRecognizer: UIPanGestureRecognizer {
}
override public func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) {
self.currentAllowedDirections = self.allowedDirections()
if self.currentAllowedDirections.isEmpty {
let touch = touches.first!
let point = touch.location(in: self.view)
var allowedDirections = self.allowedDirections(point)
if allowedDirections.isEmpty {
self.state = .failed
return
}
super.touchesBegan(touches, with: event)
let touch = touches.first!
self.firstLocation = touch.location(in: self.view)
self.firstLocation = point
if let target = self.view?.hitTest(self.firstLocation, with: event) {
if hasHorizontalGestures(target, point: self.view?.convert(self.firstLocation, to: target)) {
self.state = .cancelled
let horizontalGestures = hasHorizontalGestures(target, point: self.view?.convert(self.firstLocation, to: target))
switch horizontalGestures {
case .some, .strict:
if case .strict = horizontalGestures {
allowedDirections = []
} else if allowedDirections.contains(.leftEdge) || allowedDirections.contains(.rightEdge) {
allowedDirections.remove(.leftCenter)
allowedDirections.remove(.rightCenter)
}
case .none:
break
}
}
if allowedDirections.isEmpty {
self.state = .failed
} else {
self.currentAllowedDirections = allowedDirections
}
}
override public func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) {
let location = touches.first!.location(in: self.view)
let translation = CGPoint(x: location.x - firstLocation.x, y: location.y - firstLocation.y)
let translation = CGPoint(x: location.x - self.firstLocation.x, y: location.y - self.firstLocation.y)
let absTranslationX: CGFloat = abs(translation.x)
let absTranslationY: CGFloat = abs(translation.y)
let size = self.view?.bounds.size ?? CGSize()
let edgeWidth: CGFloat = 20.0
if !self.validatedGesture {
if self.currentAllowedDirections.contains(.right) && self.firstLocation.x < 16.0 {
self.validatedGesture = true
} else if !self.currentAllowedDirections.contains(.left) && translation.x < 0.0 {
if self.firstLocation.x < edgeWidth && !self.currentAllowedDirections.contains(.rightEdge) {
self.state = .failed
} else if !self.currentAllowedDirections.contains(.right) && translation.x > 0.0 {
return
}
if self.firstLocation.x > size.width - edgeWidth && !self.currentAllowedDirections.contains(.leftEdge) {
self.state = .failed
return
}
if self.currentAllowedDirections.contains(.rightEdge) && self.firstLocation.x < edgeWidth {
self.validatedGesture = true
} else if self.currentAllowedDirections.contains(.leftEdge) && self.firstLocation.x > size.width - edgeWidth {
self.validatedGesture = true
} else if !self.currentAllowedDirections.contains(.leftCenter) && translation.x < 0.0 {
self.state = .failed
} else if !self.currentAllowedDirections.contains(.rightCenter) && translation.x > 0.0 {
self.state = .failed
} else if absTranslationY > 2.0 && absTranslationY > absTranslationX * 2.0 {
self.state = .failed
@@ -104,7 +147,7 @@ public class InteractiveTransitionGestureRecognizer: UIPanGestureRecognizer {
}
}
if validatedGesture {
if self.validatedGesture {
super.touchesMoved(touches, with: event)
}
}