mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-24 07:05:35 +00:00
Various improvements
This commit is contained in:
@@ -6,10 +6,12 @@ import ViewControllerComponent
|
||||
|
||||
public final class SheetComponentEnvironment: Equatable {
|
||||
public let isDisplaying: Bool
|
||||
public let isCentered: Bool
|
||||
public let dismiss: (Bool) -> Void
|
||||
|
||||
public init(isDisplaying: Bool, dismiss: @escaping (Bool) -> Void) {
|
||||
public init(isDisplaying: Bool, isCentered: Bool, dismiss: @escaping (Bool) -> Void) {
|
||||
self.isDisplaying = isDisplaying
|
||||
self.isCentered = isCentered
|
||||
self.dismiss = dismiss
|
||||
}
|
||||
|
||||
@@ -17,6 +19,9 @@ public final class SheetComponentEnvironment: Equatable {
|
||||
if lhs.isDisplaying != rhs.isDisplaying {
|
||||
return false
|
||||
}
|
||||
if lhs.isCentered != rhs.isCentered {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -180,6 +185,7 @@ public final class SheetComponent<ChildEnvironmentType: Equatable>: Component {
|
||||
|
||||
private var currentAvailableSize: CGSize?
|
||||
func update(component: SheetComponent<ChildEnvironmentType>, availableSize: CGSize, state: EmptyComponentState, environment: Environment<EnvironmentType>, transition: Transition) -> CGSize {
|
||||
let sheetEnvironment = environment[SheetComponentEnvironment.self].value
|
||||
component.animateOut.connect { [weak self] completion in
|
||||
guard let strongSelf = self else {
|
||||
return
|
||||
@@ -195,19 +201,36 @@ public final class SheetComponent<ChildEnvironmentType: Equatable>: Component {
|
||||
|
||||
transition.setFrame(view: self.dimView, frame: CGRect(origin: CGPoint(), size: availableSize), completion: nil)
|
||||
|
||||
let containerSize: CGSize
|
||||
if sheetEnvironment.isCentered {
|
||||
let verticalInset: CGFloat = 44.0
|
||||
let maxSide = max(availableSize.width, availableSize.height)
|
||||
let minSide = min(availableSize.width, availableSize.height)
|
||||
containerSize = CGSize(width: min(availableSize.width - 20.0, floor(maxSide / 2.0)), height: min(availableSize.height, minSide) - verticalInset * 2.0)
|
||||
} else {
|
||||
containerSize = CGSize(width: availableSize.width, height: .greatestFiniteMagnitude)
|
||||
}
|
||||
|
||||
let contentSize = self.contentView.update(
|
||||
transition: transition,
|
||||
component: component.content,
|
||||
environment: {
|
||||
environment[ChildEnvironmentType.self]
|
||||
},
|
||||
containerSize: CGSize(width: availableSize.width, height: .greatestFiniteMagnitude)
|
||||
containerSize: containerSize
|
||||
)
|
||||
|
||||
self.ignoreScrolling = true
|
||||
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 sheetEnvironment.isCentered {
|
||||
transition.setFrame(view: self.contentView, frame: CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - contentSize.width) / 2.0), y: 0.0), size: contentSize), completion: nil)
|
||||
transition.setFrame(view: self.backgroundView, frame: CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - contentSize.width) / 2.0), y: floorToScreenPixels((availableSize.height - contentSize.height) / 2.0)), size: contentSize), completion: nil)
|
||||
} 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)
|
||||
}
|
||||
transition.setFrame(view: self.scrollView, frame: CGRect(origin: CGPoint(), size: availableSize), completion: nil)
|
||||
|
||||
self.scrollView.contentSize = contentSize
|
||||
self.scrollView.contentInset = UIEdgeInsets(top: max(0.0, availableSize.height - contentSize.height) + contentSize.height, left: 0.0, bottom: 0.0, right: 0.0)
|
||||
self.ignoreScrolling = false
|
||||
@@ -222,9 +245,8 @@ public final class SheetComponent<ChildEnvironmentType: Equatable>: Component {
|
||||
} else if !environment[SheetComponentEnvironment.self].value.isDisplaying, self.previousIsDisplaying, let _ = transition.userData(ViewControllerComponentContainer.AnimateOutTransition.self) {
|
||||
self.animateOut(completion: {})
|
||||
}
|
||||
self.previousIsDisplaying = environment[SheetComponentEnvironment.self].value.isDisplaying
|
||||
|
||||
self.dismiss = environment[SheetComponentEnvironment.self].value.dismiss
|
||||
self.previousIsDisplaying = sheetEnvironment.isDisplaying
|
||||
self.dismiss = sheetEnvironment.dismiss
|
||||
|
||||
return availableSize
|
||||
}
|
||||
|
||||
@@ -69,6 +69,7 @@ open class ViewControllerComponentContainer: ViewController {
|
||||
public let statusBarHeight: CGFloat
|
||||
public let navigationHeight: CGFloat
|
||||
public let safeInsets: UIEdgeInsets
|
||||
public let metrics: LayoutMetrics
|
||||
public let isVisible: Bool
|
||||
public let theme: PresentationTheme
|
||||
public let strings: PresentationStrings
|
||||
@@ -79,6 +80,7 @@ open class ViewControllerComponentContainer: ViewController {
|
||||
statusBarHeight: CGFloat,
|
||||
navigationHeight: CGFloat,
|
||||
safeInsets: UIEdgeInsets,
|
||||
metrics: LayoutMetrics,
|
||||
isVisible: Bool,
|
||||
theme: PresentationTheme,
|
||||
strings: PresentationStrings,
|
||||
@@ -88,6 +90,7 @@ open class ViewControllerComponentContainer: ViewController {
|
||||
self.statusBarHeight = statusBarHeight
|
||||
self.navigationHeight = navigationHeight
|
||||
self.safeInsets = safeInsets
|
||||
self.metrics = metrics
|
||||
self.isVisible = isVisible
|
||||
self.theme = theme
|
||||
self.strings = strings
|
||||
@@ -109,6 +112,9 @@ open class ViewControllerComponentContainer: ViewController {
|
||||
if lhs.safeInsets != rhs.safeInsets {
|
||||
return false
|
||||
}
|
||||
if lhs.metrics != rhs.metrics {
|
||||
return false
|
||||
}
|
||||
if lhs.isVisible != rhs.isVisible {
|
||||
return false
|
||||
}
|
||||
@@ -164,6 +170,7 @@ open class ViewControllerComponentContainer: ViewController {
|
||||
statusBarHeight: layout.statusBarHeight ?? 0.0,
|
||||
navigationHeight: navigationHeight,
|
||||
safeInsets: UIEdgeInsets(top: layout.intrinsicInsets.top + layout.safeInsets.top, left: layout.safeInsets.left, bottom: layout.intrinsicInsets.bottom + layout.safeInsets.bottom, right: layout.safeInsets.right),
|
||||
metrics: layout.metrics,
|
||||
isVisible: self.currentIsVisible,
|
||||
theme: self.theme ?? self.presentationData.theme,
|
||||
strings: self.presentationData.strings,
|
||||
|
||||
Reference in New Issue
Block a user