mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-22 22:25:57 +00:00
Various improvements
This commit is contained in:
@@ -114,7 +114,7 @@ public final class SheetComponent<ChildEnvironmentType: Equatable>: Component {
|
||||
private let scrollView: ScrollView
|
||||
private let backgroundView: UIView
|
||||
private var effectView: UIVisualEffectView?
|
||||
private let contentView: ComponentHostView<ChildEnvironmentType>
|
||||
private let contentView: ComponentView<ChildEnvironmentType>
|
||||
|
||||
private var isAnimatingOut: Bool = false
|
||||
private var previousIsDisplaying: Bool = false
|
||||
@@ -139,7 +139,7 @@ public final class SheetComponent<ChildEnvironmentType: Equatable>: Component {
|
||||
self.backgroundView.layer.cornerRadius = 12.0
|
||||
self.backgroundView.layer.masksToBounds = true
|
||||
|
||||
self.contentView = ComponentHostView<ChildEnvironmentType>()
|
||||
self.contentView = ComponentView<ChildEnvironmentType>()
|
||||
|
||||
super.init(frame: frame)
|
||||
|
||||
@@ -147,7 +147,6 @@ public final class SheetComponent<ChildEnvironmentType: Equatable>: Component {
|
||||
|
||||
self.addSubview(self.dimView)
|
||||
self.scrollView.addSubview(self.backgroundView)
|
||||
self.scrollView.addSubview(self.contentView)
|
||||
self.addSubview(self.scrollView)
|
||||
|
||||
self.dimView.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(self.dimViewTapGesture(_:))))
|
||||
@@ -251,18 +250,21 @@ public final class SheetComponent<ChildEnvironmentType: Equatable>: Component {
|
||||
self.isUserInteractionEnabled = false
|
||||
self.dimView.layer.animateAlpha(from: 1.0, to: 0.0, duration: 0.3, removeOnCompletion: false)
|
||||
|
||||
guard let contentView = self.contentView.view else {
|
||||
return
|
||||
}
|
||||
if let initialVelocity = initialVelocity {
|
||||
let transition = ContainedViewLayoutTransition.animated(duration: 0.35, curve: .customSpring(damping: 124.0, initialVelocity: initialVelocity))
|
||||
|
||||
let contentOffset = (self.scrollView.contentOffset.y + self.scrollView.contentInset.top - self.scrollView.contentSize.height) * -1.0
|
||||
let dismissalOffset = self.scrollView.contentSize.height + abs(self.contentView.frame.minY)
|
||||
let dismissalOffset = self.scrollView.contentSize.height + abs(contentView.frame.minY)
|
||||
let delta = dismissalOffset - contentOffset
|
||||
|
||||
transition.updatePosition(layer: self.scrollView.layer, position: CGPoint(x: self.scrollView.center.x, y: self.scrollView.center.y + delta), completion: { _ in
|
||||
completion()
|
||||
})
|
||||
} else {
|
||||
self.scrollView.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: self.scrollView.contentSize.height + abs(self.contentView.frame.minY)), duration: 0.25, timingFunction: CAMediaTimingFunctionName.easeInEaseOut.rawValue, removeOnCompletion: false, additive: true, completion: { _ in
|
||||
self.scrollView.layer.animatePosition(from: CGPoint(), to: CGPoint(x: 0.0, y: self.scrollView.contentSize.height + abs(contentView.frame.minY)), duration: 0.25, timingFunction: CAMediaTimingFunctionName.easeInEaseOut.rawValue, removeOnCompletion: false, additive: true, completion: { _ in
|
||||
completion()
|
||||
})
|
||||
}
|
||||
@@ -316,6 +318,7 @@ public final class SheetComponent<ChildEnvironmentType: Equatable>: Component {
|
||||
containerSize = CGSize(width: availableSize.width, height: .greatestFiniteMagnitude)
|
||||
}
|
||||
|
||||
self.contentView.parentState = state
|
||||
let contentSize = self.contentView.update(
|
||||
transition: transition,
|
||||
component: component.content,
|
||||
@@ -326,19 +329,23 @@ public final class SheetComponent<ChildEnvironmentType: Equatable>: Component {
|
||||
)
|
||||
|
||||
self.ignoreScrolling = true
|
||||
|
||||
if sheetEnvironment.isCentered {
|
||||
let y: CGFloat = floorToScreenPixels((availableSize.height - contentSize.height) / 2.0)
|
||||
transition.setFrame(view: self.contentView, frame: CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - contentSize.width) / 2.0), y: -y), size: contentSize), completion: nil)
|
||||
transition.setFrame(view: self.backgroundView, frame: CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - contentSize.width) / 2.0), y: -y), size: contentSize), completion: nil)
|
||||
if let effectView = self.effectView {
|
||||
transition.setFrame(view: effectView, frame: CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - contentSize.width) / 2.0), y: -y), size: contentSize), completion: nil)
|
||||
if let contentView = self.contentView.view {
|
||||
if contentView.superview == nil {
|
||||
self.scrollView.addSubview(contentView)
|
||||
}
|
||||
} else {
|
||||
transition.setFrame(view: self.contentView, frame: CGRect(origin: .zero, size: contentSize), completion: nil)
|
||||
transition.setFrame(view: self.backgroundView, frame: CGRect(origin: .zero, size: CGSize(width: contentSize.width, height: contentSize.height + 1000.0)), completion: nil)
|
||||
if let effectView = self.effectView {
|
||||
transition.setFrame(view: effectView, frame: CGRect(origin: .zero, size: CGSize(width: contentSize.width, height: contentSize.height + 1000.0)), completion: nil)
|
||||
if sheetEnvironment.isCentered {
|
||||
let y: CGFloat = floorToScreenPixels((availableSize.height - contentSize.height) / 2.0)
|
||||
transition.setFrame(view: contentView, frame: CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - contentSize.width) / 2.0), y: -y), size: contentSize), completion: nil)
|
||||
transition.setFrame(view: self.backgroundView, frame: CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - contentSize.width) / 2.0), y: -y), size: contentSize), completion: nil)
|
||||
if let effectView = self.effectView {
|
||||
transition.setFrame(view: effectView, frame: CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - contentSize.width) / 2.0), y: -y), size: contentSize), completion: nil)
|
||||
}
|
||||
} else {
|
||||
transition.setFrame(view: contentView, frame: CGRect(origin: .zero, size: contentSize), completion: nil)
|
||||
transition.setFrame(view: self.backgroundView, frame: CGRect(origin: .zero, size: CGSize(width: contentSize.width, height: contentSize.height + 1000.0)), completion: nil)
|
||||
if let effectView = self.effectView {
|
||||
transition.setFrame(view: effectView, frame: CGRect(origin: .zero, size: CGSize(width: contentSize.width, height: contentSize.height + 1000.0)), completion: nil)
|
||||
}
|
||||
}
|
||||
}
|
||||
transition.setFrame(view: self.scrollView, frame: CGRect(origin: CGPoint(), size: availableSize), completion: nil)
|
||||
|
||||
Reference in New Issue
Block a user