Cherry-pick some fixes

This commit is contained in:
Ilya Laktyushin
2022-06-24 20:25:31 +05:00
parent f7641fb550
commit 554bd37791
4 changed files with 85 additions and 53 deletions
+3
View File
@@ -3347,6 +3347,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
if progress == 1.0 {
for itemNode in temporaryPreviousNodes {
itemNode.visibility = .none
itemNode.removeFromSupernode()
itemNode.extractedBackgroundNode?.removeFromSupernode()
}
@@ -3360,6 +3361,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
} else {
animation.completion = { _ in
for itemNode in temporaryPreviousNodes {
itemNode.visibility = .none
itemNode.removeFromSupernode()
itemNode.extractedBackgroundNode?.removeFromSupernode()
}
@@ -3442,6 +3444,7 @@ open class ListView: ASDisplayNode, UIScrollViewAccessibilityDelegate, UIGesture
private func removeItemNodeAtIndex(_ index: Int) {
let node = self.itemNodes[index]
self.itemNodes.remove(at: index)
node.visibility = .none
node.removeFromSupernode()
node.extractedBackgroundNode?.removeFromSupernode()
node.accessoryItemNode?.removeFromSupernode()
@@ -3,6 +3,7 @@ import UIKit
import SceneKit
import Display
import AppBundle
import LegacyComponents
final class FasterStarsView: UIView, PhoneDemoDecorationView {
private let sceneView: SCNView
@@ -55,23 +56,37 @@ final class FasterStarsView: UIView, PhoneDemoDecorationView {
}
self.playing = true
let speedAnimation = CABasicAnimation(keyPath: "speedFactor")
speedAnimation.fromValue = 1.0
speedAnimation.toValue = 1.8
let speedAnimation = POPBasicAnimation()
speedAnimation.property = (POPAnimatableProperty.property(withName: "speedFactor", initializer: { property in
property?.readBlock = { particleSystem, values in
values?.pointee = (particleSystem as! SCNParticleSystem).speedFactor
}
property?.writeBlock = { particleSystem, values in
(particleSystem as! SCNParticleSystem).speedFactor = values!.pointee
}
property?.threshold = 0.01
}) as! POPAnimatableProperty)
speedAnimation.fromValue = 1.0 as NSNumber
speedAnimation.toValue = 3.0 as NSNumber
speedAnimation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
speedAnimation.duration = 0.8
speedAnimation.fillMode = .forwards
particles.addAnimation(speedAnimation, forKey: "speedFactor")
particles.pop_add(speedAnimation, forKey: "speedFactor")
particles.speedFactor = 3.0
let stretchAnimation = CABasicAnimation(keyPath: "stretchFactor")
stretchAnimation.fromValue = 0.05
stretchAnimation.toValue = 0.3
let stretchAnimation = POPBasicAnimation()
stretchAnimation.property = (POPAnimatableProperty.property(withName: "stretchFactor", initializer: { property in
property?.readBlock = { particleSystem, values in
values?.pointee = (particleSystem as! SCNParticleSystem).stretchFactor
}
property?.writeBlock = { particleSystem, values in
(particleSystem as! SCNParticleSystem).stretchFactor = values!.pointee
}
property?.threshold = 0.01
}) as! POPAnimatableProperty)
stretchAnimation.fromValue = 0.05 as NSNumber
stretchAnimation.toValue = 0.3 as NSNumber
stretchAnimation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
stretchAnimation.duration = 0.8
stretchAnimation.fillMode = .forwards
particles.addAnimation(stretchAnimation, forKey: "stretchFactor")
particles.stretchFactor = 0.3
particles.pop_add(stretchAnimation, forKey: "stretchFactor")
}
func resetAnimation() {
@@ -79,24 +94,38 @@ final class FasterStarsView: UIView, PhoneDemoDecorationView {
return
}
self.playing = false
let speedAnimation = CABasicAnimation(keyPath: "speedFactor")
speedAnimation.fromValue = 3.0
speedAnimation.toValue = 1.0
let speedAnimation = POPBasicAnimation()
speedAnimation.property = (POPAnimatableProperty.property(withName: "speedFactor", initializer: { property in
property?.readBlock = { particleSystem, values in
values?.pointee = (particleSystem as! SCNParticleSystem).speedFactor
}
property?.writeBlock = { particleSystem, values in
(particleSystem as! SCNParticleSystem).speedFactor = values!.pointee
}
property?.threshold = 0.01
}) as! POPAnimatableProperty)
speedAnimation.fromValue = 3.0 as NSNumber
speedAnimation.toValue = 1.0 as NSNumber
speedAnimation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
speedAnimation.duration = 0.35
speedAnimation.fillMode = .forwards
particles.addAnimation(speedAnimation, forKey: "speedFactor")
particles.pop_add(speedAnimation, forKey: "speedFactor")
particles.speedFactor = 1.0
let stretchAnimation = CABasicAnimation(keyPath: "stretchFactor")
stretchAnimation.fromValue = 0.3
stretchAnimation.toValue = 0.05
let stretchAnimation = POPBasicAnimation()
stretchAnimation.property = (POPAnimatableProperty.property(withName: "stretchFactor", initializer: { property in
property?.readBlock = { particleSystem, values in
values?.pointee = (particleSystem as! SCNParticleSystem).stretchFactor
}
property?.writeBlock = { particleSystem, values in
(particleSystem as! SCNParticleSystem).stretchFactor = values!.pointee
}
property?.threshold = 0.01
}) as! POPAnimatableProperty)
stretchAnimation.fromValue = 0.3 as NSNumber
stretchAnimation.toValue = 0.05 as NSNumber
stretchAnimation.timingFunction = CAMediaTimingFunction(name: CAMediaTimingFunctionName.linear)
stretchAnimation.duration = 0.35
stretchAnimation.fillMode = .forwards
particles.addAnimation(stretchAnimation, forKey: "stretchFactor")
particles.stretchFactor = 0.05
particles.pop_add(stretchAnimation, forKey: "stretchFactor")
}
override func layoutSubviews() {
@@ -295,7 +295,7 @@ func chatMediaInputGridEntries(view: ItemCollectionsView, savedStickers: Ordered
let filteredTrending = trendingPacks.filter { !installedPacks.contains($0.info.id) }
if !trendingIsDismissed && !filteredTrending.isEmpty {
entries.append(.trendingList(theme: theme, strings: strings, packs: filteredTrending, isPremium: false))
entries.append(.trendingList(theme: theme, strings: strings, packs: filteredTrending, isPremium: trendingIsPremium))
}
if let recentStickers = recentStickers, !recentStickers.items.isEmpty {
@@ -402,11 +402,11 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
}
}
private var visibilityStatus: Bool = false {
private var visibilityStatus: Bool? {
didSet {
if self.visibilityStatus != oldValue {
self.updateVisibility()
self.haptic?.enabled = self.visibilityStatus
self.haptic?.enabled = self.visibilityStatus == true
}
}
}
@@ -593,28 +593,18 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
}
}
let isPlaying = self.visibilityStatus && !self.forceStopAnimations
if let animationNode = self.animationNode as? AnimatedStickerNode {
if !isPlaying {
for decorationNode in self.additionalAnimationNodes {
if let transitionNode = item.controllerInteraction.getMessageTransitionNode() {
decorationNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak decorationNode] _ in
if let decorationNode = decorationNode {
transitionNode.remove(decorationNode: decorationNode)
}
})
}
}
self.additionalAnimationNodes.removeAll()
if let overlayMeshAnimationNode = self.overlayMeshAnimationNode {
self.overlayMeshAnimationNode = nil
if let transitionNode = item.controllerInteraction.getMessageTransitionNode() {
transitionNode.remove(decorationNode: overlayMeshAnimationNode)
}
let isPlaying = self.visibilityStatus == true && !self.forceStopAnimations
if !isPlaying {
self.removeAdditionalAnimations()
if let overlayMeshAnimationNode = self.overlayMeshAnimationNode {
self.overlayMeshAnimationNode = nil
if let transitionNode = item.controllerInteraction.getMessageTransitionNode() {
transitionNode.remove(decorationNode: overlayMeshAnimationNode)
}
}
}
if let animationNode = self.animationNode as? AnimatedStickerNode {
if self.isPlaying != isPlaying {
self.isPlaying = isPlaying
@@ -1721,10 +1711,20 @@ class ChatMessageAnimatedStickerItemNode: ChatMessageItemView {
self.additionalAnimationNodes.append(decorationNode)
additionalAnimationNode.play()
additionalAnimationNode.visibility = true
}
}
private func removeAdditionalAnimations() {
for decorationNode in self.additionalAnimationNodes {
if let additionalAnimationNode = decorationNode.contentView.asyncdisplaykit_node as? AnimatedStickerNode {
additionalAnimationNode.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.2, removeOnCompletion: false, completion: { [weak additionalAnimationNode] _ in
additionalAnimationNode?.visibility = false
})
}
}
}
private func gestureRecognized(gesture: TapLongTapOrDoubleTapGesture, location: CGPoint, recognizer: TapLongTapOrDoubleTapGestureRecognizer?) -> InternalBubbleTapAction? {
switch gesture {
case .tap: