Various improvements

This commit is contained in:
Ilya Laktyushin
2023-11-25 19:57:04 +04:00
parent af9c7ed5d3
commit 0337de2cc3
6 changed files with 115 additions and 37 deletions

View File

@@ -75,6 +75,7 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
public var present: (ViewController) -> Void = { _ in }
public var push: (ViewController) -> Void = { _ in }
public var canInteract: () -> Bool = { return true }
public var hasSelectionChanged: (Bool) -> Void = { _ in }
var selectionChanged: (DrawingEntity?) -> Void = { _ in }
var requestedMenuForEntityView: (DrawingEntityView, Bool) -> Void = { _, _ in }
@@ -633,6 +634,9 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
}
@objc private func handleTap(_ gestureRecognzier: UITapGestureRecognizer) {
guard self.canInteract() else {
return
}
let location = gestureRecognzier.location(in: self)
if let entityView = self.entity(at: location) {
self.selectEntity(entityView.entity)
@@ -757,6 +761,9 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
}
public func handlePan(_ gestureRecognizer: UIPanGestureRecognizer) {
guard self.canInteract() else {
return
}
let location = gestureRecognizer.location(in: self)
if let selectedEntityView = self.selectedEntityView, let selectionView = selectedEntityView.selectionView {
if !self.hasBin {
@@ -839,6 +846,9 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
}
public func handlePinch(_ gestureRecognizer: UIPinchGestureRecognizer) {
guard self.canInteract() else {
return
}
if !self.hasSelection, let mediaEntityView = self.subviews.first(where: { $0 is DrawingEntityMediaView }) as? DrawingEntityMediaView {
mediaEntityView.handlePinch(gestureRecognizer)
} else if let selectedEntityView = self.selectedEntityView, let selectionView = selectedEntityView.selectionView {
@@ -847,6 +857,9 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
}
public func handleRotate(_ gestureRecognizer: UIRotationGestureRecognizer) {
guard self.canInteract() else {
return
}
if !self.hasSelection, let mediaEntityView = self.subviews.first(where: { $0 is DrawingEntityMediaView }) as? DrawingEntityMediaView {
mediaEntityView.handleRotate(gestureRecognizer)
} else if let selectedEntityView = self.selectedEntityView, let selectionView = selectedEntityView.selectionView {