Merge commit '7621e2f8dec938cf48181c8b10afc9b01f444e68' into beta

This commit is contained in:
Ilya Laktyushin
2025-12-06 02:17:48 +04:00
commit 8344b97e03
28070 changed files with 7995182 additions and 0 deletions
@@ -0,0 +1,29 @@
import Foundation
import UIKit
public class Gesture {
class Id {
private var _id: UInt = 0
public var id: UInt {
return self._id
}
init() {
self._id = UInt(bitPattern: Unmanaged.passUnretained(self).toOpaque())
}
}
let id: Id
init(id: Id) {
self.id = id
}
func create() -> UIGestureRecognizer {
preconditionFailure()
}
func update(gesture: UIGestureRecognizer) {
preconditionFailure()
}
}
@@ -0,0 +1,59 @@
import Foundation
import UIKit
public extension Gesture {
enum LongPressGestureState {
case began
case ended
}
private final class LongPressGesture: Gesture {
private class Impl: UILongPressGestureRecognizer {
var action: (LongPressGestureState) -> Void
init(pressDuration: Double, action: @escaping (LongPressGestureState) -> Void) {
self.action = action
super.init(target: nil, action: nil)
self.minimumPressDuration = pressDuration
self.addTarget(self, action: #selector(self.onAction))
}
@objc private func onAction() {
switch self.state {
case .began:
self.action(.began)
case .ended, .cancelled:
self.action(.ended)
default:
break
}
}
}
static let id = Id()
private let pressDuration: Double
private let action: (LongPressGestureState) -> Void
init(pressDuration: Double, action: @escaping (LongPressGestureState) -> Void) {
self.pressDuration = pressDuration
self.action = action
super.init(id: Self.id)
}
override func create() -> UIGestureRecognizer {
return Impl(pressDuration: self.pressDuration, action: self.action)
}
override func update(gesture: UIGestureRecognizer) {
(gesture as! Impl).minimumPressDuration = self.pressDuration
(gesture as! Impl).action = self.action
}
}
static func longPress(duration: Double = 0.2, _ action: @escaping (LongPressGestureState) -> Void) -> Gesture {
return LongPressGesture(pressDuration: duration, action: action)
}
}
@@ -0,0 +1,59 @@
import Foundation
import UIKit
public extension Gesture {
enum PanGestureState {
case began
case updated(offset: CGPoint)
case ended(velocity: CGPoint)
}
private final class PanGesture: Gesture {
private class Impl: UIPanGestureRecognizer {
var action: (PanGestureState) -> Void
init(action: @escaping (PanGestureState) -> Void) {
self.action = action
super.init(target: nil, action: nil)
self.addTarget(self, action: #selector(self.onAction))
}
@objc private func onAction() {
switch self.state {
case .began:
self.action(.began)
case .ended, .cancelled:
self.action(.ended(velocity: self.velocity(in: self.view)))
case .changed:
let offset = self.translation(in: self.view)
self.action(.updated(offset: offset))
default:
break
}
}
}
static let id = Id()
private let action: (PanGestureState) -> Void
init(action: @escaping (PanGestureState) -> Void) {
self.action = action
super.init(id: Self.id)
}
override func create() -> UIGestureRecognizer {
return Impl(action: self.action)
}
override func update(gesture: UIGestureRecognizer) {
(gesture as! Impl).action = action
}
}
static func pan(_ action: @escaping (PanGestureState) -> Void) -> Gesture {
return PanGesture(action: action)
}
}
@@ -0,0 +1,43 @@
import Foundation
import UIKit
public extension Gesture {
private final class TapGesture: Gesture {
private class Impl: UITapGestureRecognizer {
var action: () -> Void
init(action: @escaping () -> Void) {
self.action = action
super.init(target: nil, action: nil)
self.addTarget(self, action: #selector(self.onAction))
}
@objc private func onAction() {
self.action()
}
}
static let id = Id()
private let action: () -> Void
init(action: @escaping () -> Void) {
self.action = action
super.init(id: Self.id)
}
override func create() -> UIGestureRecognizer {
return Impl(action: self.action)
}
override func update(gesture: UIGestureRecognizer) {
(gesture as! Impl).action = action
}
}
static func tap(_ action: @escaping () -> Void) -> Gesture {
return TapGesture(action: action)
}
}