Various fixes

This commit is contained in:
Ilya Laktyushin
2023-07-25 22:37:45 +02:00
parent f4fc72b762
commit ab6b0140cd
17 changed files with 379 additions and 77 deletions

View File

@@ -9,15 +9,21 @@ final class SectionHeaderComponent: Component {
let theme: PresentationTheme
let style: ShareWithPeersScreenComponent.Style
let title: String
let actionTitle: String?
let action: (() -> Void)?
init(
theme: PresentationTheme,
style: ShareWithPeersScreenComponent.Style,
title: String
title: String,
actionTitle: String?,
action: (() -> Void)?
) {
self.theme = theme
self.style = style
self.title = title
self.actionTitle = actionTitle
self.action = action
}
static func ==(lhs: SectionHeaderComponent, rhs: SectionHeaderComponent) -> Bool {
@@ -30,12 +36,16 @@ final class SectionHeaderComponent: Component {
if lhs.title != rhs.title {
return false
}
if lhs.actionTitle != rhs.actionTitle {
return false
}
return true
}
final class View: UIView {
private let title = ComponentView<Empty>()
private let backgroundView: BlurredBackgroundView
private let action = ComponentView<Empty>()
private var component: SectionHeaderComponent?
private weak var state: EmptyComponentState?
@@ -95,6 +105,32 @@ final class SectionHeaderComponent: Component {
}
}
if let actionTitle = component.actionTitle {
let actionSize = self.action.update(
transition: .immediate,
component: AnyComponent(
Button(content: AnyComponent(MultilineTextComponent(
text: .plain(NSAttributedString(string: actionTitle, font: Font.regular(13.0), textColor: component.theme.list.itemSecondaryTextColor))
)), action: { [weak self] in
if let self, let component = self.component {
component.action?()
}
})
),
environment: {},
containerSize: CGSize(width: availableSize.width - leftInset - rightInset, height: 100.0)
)
if let view = self.action.view {
if view.superview == nil {
self.addSubview(view)
}
let actionFrame = CGRect(origin: CGPoint(x: availableSize.width - leftInset - titleSize.width, y: floor((height - titleSize.height) / 2.0)), size: actionSize)
view.frame = actionFrame
}
} else if self.action.view?.superview != nil {
self.action.view?.removeFromSuperview()
}
let size = CGSize(width: availableSize.width, height: height)
transition.setFrame(view: self.backgroundView, frame: CGRect(origin: CGPoint(), size: size))