mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-06-16 05:55:20 +00:00
Merge commit 'f801c81a9d776386d3c6aaa695b8bf244a1c59a0'
This commit is contained in:
commit
2534d80833
@ -226,7 +226,7 @@ public extension CALayer {
|
||||
self.add(animationGroup, forKey: key)
|
||||
}
|
||||
|
||||
func animateKeyframes(values: [AnyObject], duration: Double, keyPath: String, timingFunction: String = CAMediaTimingFunctionName.linear.rawValue, mediaTimingFunction: CAMediaTimingFunction? = nil, removeOnCompletion: Bool = true, additive: Bool = false, completion: ((Bool) -> Void)? = nil) {
|
||||
func animateKeyframes(values: [AnyObject], keyTimes: [NSNumber]? = nil, duration: Double, keyPath: String, timingFunction: String = CAMediaTimingFunctionName.linear.rawValue, mediaTimingFunction: CAMediaTimingFunction? = nil, removeOnCompletion: Bool = true, additive: Bool = false, completion: ((Bool) -> Void)? = nil) {
|
||||
let k = Float(UIView.animationDurationFactor())
|
||||
var speed: Float = 1.0
|
||||
if k != 0 && k != 1 {
|
||||
@ -235,17 +235,21 @@ public extension CALayer {
|
||||
|
||||
let animation = CAKeyframeAnimation(keyPath: keyPath)
|
||||
animation.values = values
|
||||
var keyTimes: [NSNumber] = []
|
||||
for i in 0 ..< values.count {
|
||||
if i == 0 {
|
||||
keyTimes.append(0.0)
|
||||
} else if i == values.count - 1 {
|
||||
keyTimes.append(1.0)
|
||||
} else {
|
||||
keyTimes.append((Double(i) / Double(values.count - 1)) as NSNumber)
|
||||
var effectiveKeyTimes: [NSNumber] = []
|
||||
if let keyTimes {
|
||||
effectiveKeyTimes = keyTimes
|
||||
} else {
|
||||
for i in 0 ..< values.count {
|
||||
if i == 0 {
|
||||
effectiveKeyTimes.append(0.0)
|
||||
} else if i == values.count - 1 {
|
||||
effectiveKeyTimes.append(1.0)
|
||||
} else {
|
||||
effectiveKeyTimes.append((Double(i) / Double(values.count - 1)) as NSNumber)
|
||||
}
|
||||
}
|
||||
}
|
||||
animation.keyTimes = keyTimes
|
||||
animation.keyTimes = effectiveKeyTimes
|
||||
animation.speed = speed
|
||||
animation.duration = duration
|
||||
animation.isAdditive = additive
|
||||
|
@ -551,6 +551,19 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
|
||||
return nil
|
||||
}
|
||||
|
||||
public func getView(at point: CGPoint) -> DrawingEntityView? {
|
||||
for case let view as DrawingEntityView in self.subviews {
|
||||
if view is DrawingMediaEntityView {
|
||||
continue
|
||||
}
|
||||
if view.frame.contains(point) {
|
||||
return view
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
public func eachView(_ f: (DrawingEntityView) -> Void) {
|
||||
for case let view as DrawingEntityView in self.subviews {
|
||||
f(view)
|
||||
@ -604,10 +617,11 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
|
||||
return intersectedViews.last
|
||||
}
|
||||
|
||||
public func selectEntity(_ entity: DrawingEntity?) {
|
||||
public func selectEntity(_ entity: DrawingEntity?, animate: Bool = true) {
|
||||
if entity?.isMedia == true {
|
||||
return
|
||||
}
|
||||
var selectionChanged = false
|
||||
if entity !== self.selectedEntityView?.entity {
|
||||
if let selectedEntityView = self.selectedEntityView {
|
||||
if let textEntityView = selectedEntityView as? DrawingTextEntityView, textEntityView.isEditing {
|
||||
@ -621,9 +635,12 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
|
||||
self.selectedEntityView = nil
|
||||
if let selectionView = selectedEntityView.selectionView {
|
||||
selectedEntityView.selectionView = nil
|
||||
selectionView.removeFromSuperview()
|
||||
selectionView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak selectionView] _ in
|
||||
selectionView?.removeFromSuperview()
|
||||
})
|
||||
}
|
||||
}
|
||||
selectionChanged = true
|
||||
}
|
||||
|
||||
if let entity = entity, let entityView = self.getView(for: entity.uuid) {
|
||||
@ -640,6 +657,9 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
|
||||
self.selectionContainerView?.addSubview(selectionView)
|
||||
}
|
||||
entityView.update()
|
||||
if selectionChanged && animate {
|
||||
entityView.animateSelection()
|
||||
}
|
||||
}
|
||||
|
||||
self.selectionChanged(self.selectedEntityView?.entity)
|
||||
@ -712,6 +732,7 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
|
||||
selectedEntityView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { _ in
|
||||
self.remove(uuid: selectedEntityView.entity.uuid)
|
||||
})
|
||||
selectedEntityView.selectionView?.removeFromSuperview()
|
||||
self.selectEntity(nil)
|
||||
|
||||
Queue.mainQueue().after(0.3, {
|
||||
@ -762,9 +783,10 @@ public final class DrawingEntitiesView: UIView, TGPhotoDrawingEntitiesView {
|
||||
}
|
||||
}
|
||||
}
|
||||
// else if gestureRecognizer.numberOfTouches == 1, let viewToSelect = self.entity(at: location) {
|
||||
// self.selectEntity(viewToSelect.entity)
|
||||
// }
|
||||
else if gestureRecognizer.numberOfTouches == 1, let viewToSelect = self.entity(at: location) {
|
||||
self.selectEntity(viewToSelect.entity, animate: false)
|
||||
self.onInteractionUpdated(true)
|
||||
}
|
||||
else if gestureRecognizer.numberOfTouches == 2, let mediaEntityView = self.subviews.first(where: { $0 is DrawingEntityMediaView }) as? DrawingEntityMediaView {
|
||||
mediaEntityView.handlePan(gestureRecognizer)
|
||||
}
|
||||
@ -862,6 +884,31 @@ public class DrawingEntityView: UIView {
|
||||
return self.bounds
|
||||
}
|
||||
|
||||
func animateInsertion() {
|
||||
self.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
|
||||
|
||||
let values = [0.0, self.entity.scale * 1.1, self.entity.scale]
|
||||
let keyTimes = [0.0, 0.67, 1.0]
|
||||
self.layer.animateKeyframes(values: values as [NSNumber], keyTimes: keyTimes as [NSNumber], duration: 0.35, keyPath: "transform.scale")
|
||||
|
||||
if let selectionView = self.selectionView {
|
||||
selectionView.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2, delay: 0.3)
|
||||
}
|
||||
}
|
||||
|
||||
func animateSelection() {
|
||||
guard let selectionView = self.selectionView else {
|
||||
return
|
||||
}
|
||||
|
||||
selectionView.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2, delay: 0.1)
|
||||
selectionView.layer.animateScale(from: 0.87, to: 1.0, duration: 0.2, delay: 0.1)
|
||||
|
||||
let values = [self.entity.scale, self.entity.scale * 0.88, self.entity.scale]
|
||||
let keyTimes = [0.0, 0.33, 1.0]
|
||||
self.layer.animateKeyframes(values: values as [NSNumber], keyTimes: keyTimes as [NSNumber], duration: 0.3, keyPath: "transform.scale")
|
||||
}
|
||||
|
||||
public func play() {
|
||||
|
||||
}
|
||||
|
@ -3122,7 +3122,7 @@ public final class DrawingToolsInteraction {
|
||||
entity.scale = scale
|
||||
}
|
||||
self.entitiesView.add(entity)
|
||||
self.entitiesView.selectEntity(entity)
|
||||
self.entitiesView.selectEntity(entity, animate: !(entity is DrawingTextEntity))
|
||||
|
||||
if let entityView = self.entitiesView.getView(for: entity.uuid) {
|
||||
if let textEntityView = entityView as? DrawingTextEntityView {
|
||||
@ -3138,12 +3138,7 @@ public final class DrawingToolsInteraction {
|
||||
entityView.seek(to: 0.0)
|
||||
}
|
||||
|
||||
entityView.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2)
|
||||
entityView.layer.animateScale(from: 0.1, to: entity.scale, duration: 0.2)
|
||||
|
||||
if let selectionView = entityView.selectionView {
|
||||
selectionView.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2, delay: 0.2)
|
||||
}
|
||||
entityView.animateInsertion()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -82,6 +82,10 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate
|
||||
self.displayLink?.invalidate()
|
||||
}
|
||||
|
||||
override func animateInsertion() {
|
||||
|
||||
}
|
||||
|
||||
private var isSuspended = false
|
||||
private var _isEditing = false
|
||||
public var isEditing: Bool {
|
||||
@ -629,7 +633,7 @@ public final class DrawingTextEntityView: DrawingEntityView, UITextViewDelegate
|
||||
self.textView.strokeColor = color
|
||||
self.textView.frameColor = nil
|
||||
}
|
||||
self.textView.tintColor = cursorColor
|
||||
self.textView.tintColor = self.textView.text.isEmpty ? .white : cursorColor
|
||||
|
||||
if case .regular = self.textEntity.style {
|
||||
self.textView.layer.shadowColor = UIColor.black.cgColor
|
||||
|
@ -29,6 +29,14 @@ final class DrawingVectorEntityView: DrawingEntityView {
|
||||
return max(10.0, max(self.vectorEntity.referenceDrawingSize.width, self.vectorEntity.referenceDrawingSize.height) * 0.1)
|
||||
}
|
||||
|
||||
override func animateSelection() {
|
||||
guard let selectionView = self.selectionView else {
|
||||
return
|
||||
}
|
||||
|
||||
selectionView.layer.animateAlpha(from: 0.0, to: 1.0, duration: 0.2, delay: 0.1)
|
||||
}
|
||||
|
||||
override func update(animated: Bool) {
|
||||
self.center = CGPoint(x: self.vectorEntity.drawingSize.width * 0.5, y: self.vectorEntity.drawingSize.height * 0.5)
|
||||
self.bounds = CGRect(origin: .zero, size: self.vectorEntity.drawingSize)
|
||||
|
@ -1774,6 +1774,10 @@ public final class EmojiSearchHeaderView: UIView, UITextFieldDelegate {
|
||||
self.textView.view?.isHidden = false*/
|
||||
}
|
||||
|
||||
var isActive: Bool {
|
||||
return self.textField?.isFirstResponder ?? false
|
||||
}
|
||||
|
||||
func deactivate() {
|
||||
if let text = self.textField?.text, !text.isEmpty {
|
||||
self.textField?.endEditing(true)
|
||||
@ -5209,12 +5213,8 @@ public final class EmojiPagerContentComponent: Component {
|
||||
scrollView.layer.removeAllAnimations()
|
||||
}
|
||||
|
||||
if self.isSearchActivated, let component = self.component, component.searchState == .empty(hasResults: true), !component.searchAlwaysActive, let visibleSearchHeader = self.visibleSearchHeader, visibleSearchHeader.currentPresetSearchTerm == nil {
|
||||
scrollView.isScrollEnabled = false
|
||||
DispatchQueue.main.async {
|
||||
scrollView.isScrollEnabled = true
|
||||
}
|
||||
self.visibleSearchHeader?.deactivate()
|
||||
if let component = self.component, self.isSearchActivated, let visibleSearchHeader = self.visibleSearchHeader, visibleSearchHeader.isActive && !component.searchAlwaysActive {
|
||||
visibleSearchHeader.deactivate()
|
||||
}
|
||||
self.component?.inputInteractionHolder.inputInteraction?.onScroll()
|
||||
self.component?.inputInteractionHolder.inputInteraction?.scrollingStickersGridPromise.set(true)
|
||||
|
@ -2192,7 +2192,8 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
||||
return false
|
||||
}
|
||||
if gestureRecognizer === self.dismissPanGestureRecognizer {
|
||||
if self.isDisplayingTool || self.entitiesView.hasSelection {
|
||||
let location = gestureRecognizer.location(in: self.entitiesView)
|
||||
if self.isDisplayingTool || self.entitiesView.hasSelection || self.entitiesView.getView(at: location) != nil {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@ -2900,7 +2901,7 @@ public final class MediaEditorScreen: ViewController, UIDropInteractionDelegate
|
||||
if let self {
|
||||
if let content {
|
||||
let stickerEntity = DrawingStickerEntity(content: content)
|
||||
self.interaction?.insertEntity(stickerEntity)
|
||||
self.interaction?.insertEntity(stickerEntity, scale: 1.33)
|
||||
|
||||
self.hasAnyChanges = true
|
||||
self.controller?.isSavingAvailable = true
|
||||
|
Loading…
x
Reference in New Issue
Block a user