Various fixes

This commit is contained in:
Ilya Laktyushin 2024-10-06 04:49:00 +04:00
parent eb4519e192
commit aa23e95384
12 changed files with 117 additions and 173 deletions

View File

@ -366,6 +366,7 @@ public final class SheetComponent<ChildEnvironmentType: Equatable>: Component {
self.scrollView.addSubview(contentView) self.scrollView.addSubview(contentView)
} }
contentView.clipsToBounds = component.clipsContent contentView.clipsToBounds = component.clipsContent
contentView.layer.cornerRadius = self.backgroundView.layer.cornerRadius
if sheetEnvironment.isCentered { if sheetEnvironment.isCentered {
let y: CGFloat = floorToScreenPixels((availableSize.height - contentSize.height) / 2.0) 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: contentView, frame: CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - contentSize.width) / 2.0), y: -y), size: contentSize), completion: nil)

View File

@ -80,7 +80,7 @@ public final class ButtonBadgeComponent: Component {
if contentView.superview == nil { if contentView.superview == nil {
self.addSubview(contentView) self.addSubview(contentView)
} }
transition.setFrame(view: contentView, frame: CGRect(origin: CGPoint(x: floor((backgroundFrame.width - contentSize.width) * 0.5), y: floor((backgroundFrame.height - contentSize.height) * 0.5)), size: contentSize)) transition.setFrame(view: contentView, frame: CGRect(origin: CGPoint(x: floorToScreenPixels((backgroundFrame.width - contentSize.width) * 0.5), y: floorToScreenPixels((backgroundFrame.height - contentSize.height) * 0.5)), size: contentSize))
} }
if themeUpdated || backgroundFrame.height != self.backgroundView.image?.size.height { if themeUpdated || backgroundFrame.height != self.backgroundView.image?.size.height {
@ -264,7 +264,7 @@ public final class ButtonTextContentComponent: Component {
size.height = max(size.height, badgeSize.height) size.height = max(size.height, badgeSize.height)
} }
let contentFrame = CGRect(origin: CGPoint(x: floor((size.width - measurementSize.width) * 0.5), y: floor((size.height - measurementSize.height) * 0.5)), size: measurementSize) let contentFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((size.width - measurementSize.width) * 0.5), y: floorToScreenPixels((size.height - measurementSize.height) * 0.5)), size: measurementSize)
if let contentView = self.content.view { if let contentView = self.content.view {
if contentView.superview == nil { if contentView.superview == nil {
@ -274,7 +274,7 @@ public final class ButtonTextContentComponent: Component {
} }
if let badgeSize, let badge = self.badge { if let badgeSize, let badge = self.badge {
let badgeFrame = CGRect(origin: CGPoint(x: contentFrame.minX + contentSize.width + badgeSpacing, y: floor((size.height - badgeSize.height) * 0.5) + 1.0), size: badgeSize) let badgeFrame = CGRect(origin: CGPoint(x: contentFrame.minX + contentSize.width + badgeSpacing, y: floorToScreenPixels((size.height - badgeSize.height) * 0.5) + 1.0), size: badgeSize)
if let badgeView = badge.view { if let badgeView = badge.view {
var animateIn = false var animateIn = false
@ -490,7 +490,7 @@ public final class ButtonComponent: Component {
contentView.isUserInteractionEnabled = false contentView.isUserInteractionEnabled = false
self.addSubview(contentView) self.addSubview(contentView)
} }
let contentFrame = CGRect(origin: CGPoint(x: floor((availableSize.width - contentSize.width) * 0.5), y: floor((availableSize.height - contentSize.height) * 0.5)), size: contentSize) let contentFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - contentSize.width) * 0.5), y: floorToScreenPixels((availableSize.height - contentSize.height) * 0.5)), size: contentSize)
contentTransition.setFrame(view: contentView, frame: contentFrame) contentTransition.setFrame(view: contentView, frame: contentFrame)
contentTransition.setAlpha(view: contentView, alpha: contentAlpha) contentTransition.setAlpha(view: contentView, alpha: contentAlpha)
@ -528,7 +528,7 @@ public final class ButtonComponent: Component {
} }
let indicatorSize = CGSize(width: 22.0, height: 22.0) let indicatorSize = CGSize(width: 22.0, height: 22.0)
transition.setAlpha(view: activityIndicator.view, alpha: 1.0) transition.setAlpha(view: activityIndicator.view, alpha: 1.0)
activityIndicatorTransition.setFrame(view: activityIndicator.view, frame: CGRect(origin: CGPoint(x: floor((availableSize.width - indicatorSize.width) / 2.0), y: floor((availableSize.height - indicatorSize.height) / 2.0)), size: indicatorSize)) activityIndicatorTransition.setFrame(view: activityIndicator.view, frame: CGRect(origin: CGPoint(x: floorToScreenPixels((availableSize.width - indicatorSize.width) / 2.0), y: floorToScreenPixels((availableSize.height - indicatorSize.height) / 2.0)), size: indicatorSize))
} else { } else {
if let activityIndicator = self.activityIndicator { if let activityIndicator = self.activityIndicator {
self.activityIndicator = nil self.activityIndicator = nil

View File

@ -159,7 +159,7 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
self.addSubnode(self.buttonNode) self.addSubnode(self.buttonNode)
self.buttonNode.addSubnode(self.buttonStarsNode) self.buttonNode.addSubnode(self.buttonStarsNode)
self.addSubnode(self.buttonTitleNode) self.buttonNode.addSubnode(self.buttonTitleNode)
self.addSubnode(self.ribbonBackgroundNode) self.addSubnode(self.ribbonBackgroundNode)
self.addSubnode(self.ribbonTextNode) self.addSubnode(self.ribbonTextNode)
@ -169,13 +169,9 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
if highlighted { if highlighted {
strongSelf.buttonNode.layer.removeAnimation(forKey: "opacity") strongSelf.buttonNode.layer.removeAnimation(forKey: "opacity")
strongSelf.buttonNode.alpha = 0.4 strongSelf.buttonNode.alpha = 0.4
strongSelf.buttonTitleNode.layer.removeAnimation(forKey: "opacity")
strongSelf.buttonTitleNode.alpha = 0.4
} else { } else {
strongSelf.buttonNode.alpha = 1.0 strongSelf.buttonNode.alpha = 1.0
strongSelf.buttonNode.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2) strongSelf.buttonNode.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2)
strongSelf.buttonTitleNode.alpha = 1.0
strongSelf.buttonTitleNode.layer.animateAlpha(from: 0.4, to: 1.0, duration: 0.2)
} }
} }
} }
@ -544,7 +540,7 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
backgroundMaskImage = nil backgroundMaskImage = nil
} }
var backgroundSize = CGSize(width: labelLayout.size.width + 8.0 + 8.0, height: giftSize.height) var backgroundSize = giftSize
if hasServiceMessage { if hasServiceMessage {
backgroundSize.height += labelLayout.size.height + 18.0 backgroundSize.height += labelLayout.size.height + 18.0
} else { } else {
@ -556,13 +552,14 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
if let strongSelf = self { if let strongSelf = self {
let isFirstTime = strongSelf.item == nil let isFirstTime = strongSelf.item == nil
var isExpandedUpdated = false
if strongSelf.appliedIsExpanded != currentIsExpanded { if strongSelf.appliedIsExpanded != currentIsExpanded {
strongSelf.appliedIsExpanded = currentIsExpanded strongSelf.appliedIsExpanded = currentIsExpanded
info?.setInvertOffsetDirection() info?.setInvertOffsetDirection()
isExpandedUpdated = true
if let maskOverlayView = strongSelf.maskOverlayView {
animation.transition.updateAlpha(layer: maskOverlayView.layer, alpha: currentIsExpanded ? 1.0 : 0.0)
}
} }
let _ = isExpandedUpdated
let overlayColor = item.presentationData.theme.theme.overallDarkAppearance ? UIColor(rgb: 0xffffff, alpha: 0.12) : UIColor(rgb: 0x000000, alpha: 0.12) let overlayColor = item.presentationData.theme.theme.overallDarkAppearance ? UIColor(rgb: 0xffffff, alpha: 0.12) : UIColor(rgb: 0x000000, alpha: 0.12)
@ -637,7 +634,7 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
let _ = ribbonTextApply() let _ = ribbonTextApply()
let _ = moreApply() let _ = moreApply()
let labelFrame = CGRect(origin: CGPoint(x: 8.0, y: 2.0), size: labelLayout.size) let labelFrame = CGRect(origin: CGPoint(x: floorToScreenPixels((backgroundSize.width - labelLayout.size.width) / 2.0), y: 2.0), size: labelLayout.size)
strongSelf.labelNode.frame = labelFrame strongSelf.labelNode.frame = labelFrame
let titleFrame = CGRect(origin: CGPoint(x: mediaBackgroundFrame.minX + floorToScreenPixels((mediaBackgroundFrame.width - titleLayout.size.width) / 2.0) , y: mediaBackgroundFrame.minY + 151.0), size: titleLayout.size) let titleFrame = CGRect(origin: CGPoint(x: mediaBackgroundFrame.minX + floorToScreenPixels((mediaBackgroundFrame.width - titleLayout.size.width) / 2.0) , y: mediaBackgroundFrame.minY + 151.0), size: titleLayout.size)
@ -678,11 +675,10 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
strongSelf.dustNode = nil strongSelf.dustNode = nil
} }
let buttonTitleFrame = CGRect(origin: CGPoint(x: mediaBackgroundFrame.minX + floorToScreenPixels((mediaBackgroundFrame.width - buttonTitleLayout.size.width) / 2.0), y: clippingTextFrame.maxY + 18.0), size: buttonTitleLayout.size)
strongSelf.buttonTitleNode.frame = buttonTitleFrame
let buttonSize = CGSize(width: buttonTitleLayout.size.width + 38.0, height: 34.0) let buttonSize = CGSize(width: buttonTitleLayout.size.width + 38.0, height: 34.0)
strongSelf.buttonNode.frame = CGRect(origin: CGPoint(x: mediaBackgroundFrame.minX + floorToScreenPixels((mediaBackgroundFrame.width - buttonSize.width) / 2.0), y: clippingTextFrame.maxY + 10.0), size: buttonSize) strongSelf.buttonTitleNode.frame = CGRect(origin: CGPoint(x: floorToScreenPixels((buttonSize.width - buttonTitleLayout.size.width) / 2.0), y: 8.0), size: buttonTitleLayout.size)
animation.animator.updateFrame(layer: strongSelf.buttonNode.layer, frame: CGRect(origin: CGPoint(x: mediaBackgroundFrame.minX + floorToScreenPixels((mediaBackgroundFrame.width - buttonSize.width) / 2.0), y: clippingTextFrame.maxY + 10.0), size: buttonSize), completion: nil)
strongSelf.buttonStarsNode.frame = CGRect(origin: .zero, size: buttonSize) strongSelf.buttonStarsNode.frame = CGRect(origin: .zero, size: buttonSize)
if ribbonTextLayout.size.width > 0.0 { if ribbonTextLayout.size.width > 0.0 {
@ -712,6 +708,7 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
if ribbonTextLayout.size.width > 0.0 { if ribbonTextLayout.size.width > 0.0 {
let backgroundMaskFrame = mediaBackgroundFrame.insetBy(dx: -2.0, dy: -2.0) let backgroundMaskFrame = mediaBackgroundFrame.insetBy(dx: -2.0, dy: -2.0)
backgroundContent.frame = backgroundMaskFrame backgroundContent.frame = backgroundMaskFrame
animation.animator.updateFrame(layer: backgroundContent.layer, frame: backgroundMaskFrame, completion: nil)
backgroundContent.cornerRadius = 0.0 backgroundContent.cornerRadius = 0.0
if strongSelf.mediaBackgroundMaskNode.image?.size != mediaBackgroundFrame.size { if strongSelf.mediaBackgroundMaskNode.image?.size != mediaBackgroundFrame.size {
@ -731,7 +728,7 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
backgroundContent.view.mask = strongSelf.mediaBackgroundMaskNode.view backgroundContent.view.mask = strongSelf.mediaBackgroundMaskNode.view
strongSelf.mediaBackgroundMaskNode.frame = CGRect(origin: .zero, size: backgroundMaskFrame.size) strongSelf.mediaBackgroundMaskNode.frame = CGRect(origin: .zero, size: backgroundMaskFrame.size)
} else { } else {
backgroundContent.frame = mediaBackgroundFrame animation.animator.updateFrame(layer: backgroundContent.layer, frame: mediaBackgroundFrame, completion: nil)
backgroundContent.clipsToBounds = true backgroundContent.clipsToBounds = true
backgroundContent.cornerRadius = 24.0 backgroundContent.cornerRadius = 24.0
backgroundContent.view.mask = nil backgroundContent.view.mask = nil
@ -906,8 +903,9 @@ public class ChatMessageGiftBubbleContentNode: ChatMessageBubbleContentNode {
if self.buttonNode.frame.contains(point) { if self.buttonNode.frame.contains(point) {
return ChatMessageBubbleContentTapAction(content: .ignore) return ChatMessageBubbleContentTapAction(content: .ignore)
} else if self.textClippingNode.frame.contains(point) && !self.isExpanded && !self.moreTextNode.alpha.isZero { } else if self.textClippingNode.frame.contains(point) && !self.isExpanded && !self.moreTextNode.alpha.isZero {
self.expandPressed() return ChatMessageBubbleContentTapAction(content: .custom({ [weak self] in
return ChatMessageBubbleContentTapAction(content: .ignore) self?.expandPressed()
}))
} else if let backgroundNode = self.backgroundNode, backgroundNode.frame.contains(point) { } else if let backgroundNode = self.backgroundNode, backgroundNode.frame.contains(point) {
return ChatMessageBubbleContentTapAction(content: .openMessage) return ChatMessageBubbleContentTapAction(content: .openMessage)
} else if self.mediaBackgroundContent?.frame.contains(point) == true { } else if self.mediaBackgroundContent?.frame.contains(point) == true {

View File

@ -330,6 +330,7 @@ final class GiftOptionsScreenComponent: Component {
action: { _ in return true } action: { _ in return true }
) )
mainController.present(resultController, in: .window(.root)) mainController.present(resultController, in: .window(.root))
HapticFeedback().error()
} else { } else {
let giftController = GiftSetupScreen( let giftController = GiftSetupScreen(
context: component.context, context: component.context,
@ -801,8 +802,6 @@ final class GiftOptionsScreenComponent: Component {
return return
} }
let introController = component.context.sharedContext.makeStarsIntroScreen(context: component.context) let introController = component.context.sharedContext.makeStarsIntroScreen(context: component.context)
introController.navigationPresentation = .modal
if let controller = environment.controller() as? GiftOptionsScreen { if let controller = environment.controller() as? GiftOptionsScreen {
let mainController: ViewController let mainController: ViewController
if let parentController = controller.parentController() { if let parentController = controller.parentController() {

View File

@ -196,6 +196,11 @@ final class GiftSetupScreenComponent: Component {
if let navigationTitleView = self.navigationTitle.view { if let navigationTitleView = self.navigationTitle.view {
transition.setAlpha(view: navigationTitleView, alpha: 1.0) transition.setAlpha(view: navigationTitleView, alpha: 1.0)
} }
let bottomContentOffset = max(0.0, self.scrollView.contentSize.height - self.scrollView.contentOffset.y - self.scrollView.frame.height)
let bottomPanelAlpha = min(16.0, bottomContentOffset) / 16.0
self.buttonBackground.view?.alpha = bottomPanelAlpha
self.buttonSeparator.opacity = Float(bottomPanelAlpha)
} }
func proceed() { func proceed() {
@ -856,7 +861,6 @@ final class GiftSetupScreenComponent: Component {
let bottomInset: CGFloat = environment.safeInsets.bottom > 0.0 ? environment.safeInsets.bottom + 5.0 : bottomPanelPadding let bottomInset: CGFloat = environment.safeInsets.bottom > 0.0 ? environment.safeInsets.bottom + 5.0 : bottomPanelPadding
let bottomPanelHeight = bottomPanelPadding + buttonHeight + bottomInset let bottomPanelHeight = bottomPanelPadding + buttonHeight + bottomInset
let bottomPanelAlpha: CGFloat = 1.0
let bottomPanelSize = self.buttonBackground.update( let bottomPanelSize = self.buttonBackground.update(
transition: transition, transition: transition,
component: AnyComponent(BlurredBackgroundComponent( component: AnyComponent(BlurredBackgroundComponent(
@ -866,14 +870,12 @@ final class GiftSetupScreenComponent: Component {
containerSize: CGSize(width: availableSize.width, height: bottomPanelHeight) containerSize: CGSize(width: availableSize.width, height: bottomPanelHeight)
) )
self.buttonSeparator.backgroundColor = environment.theme.rootController.tabBar.separatorColor.cgColor self.buttonSeparator.backgroundColor = environment.theme.rootController.tabBar.separatorColor.cgColor
self.buttonSeparator.opacity = Float(bottomPanelAlpha)
if let view = self.buttonBackground.view { if let view = self.buttonBackground.view {
if view.superview == nil { if view.superview == nil {
self.addSubview(view) self.addSubview(view)
self.layer.addSublayer(self.buttonSeparator) self.layer.addSublayer(self.buttonSeparator)
} }
view.alpha = bottomPanelAlpha
view.frame = CGRect(origin: CGPoint(x: 0.0, y: availableSize.height - bottomPanelSize.height), size: bottomPanelSize) view.frame = CGRect(origin: CGPoint(x: 0.0, y: availableSize.height - bottomPanelSize.height), size: bottomPanelSize)
self.buttonSeparator.frame = CGRect(origin: CGPoint(x: 0.0, y: availableSize.height - bottomPanelSize.height), size: CGSize(width: availableSize.width, height: UIScreenPixel)) self.buttonSeparator.frame = CGRect(origin: CGPoint(x: 0.0, y: availableSize.height - bottomPanelSize.height), size: CGSize(width: availableSize.width, height: UIScreenPixel))
} }

View File

@ -916,7 +916,6 @@ public class GiftViewScreen: ViewControllerComponentContainer {
return return
} }
let introController = context.sharedContext.makeStarsIntroScreen(context: context) let introController = context.sharedContext.makeStarsIntroScreen(context: context)
introController.navigationPresentation = .modal
self.push(introController) self.push(introController)
} }
} }

View File

@ -354,8 +354,8 @@ public final class PeerInfoGiftsPaneNode: ASDisplayNode, PeerInfoPaneNode, UIScr
} }
} }
let bottomOffset = max(0.0, self.scrollNode.view.contentSize.height - self.scrollNode.view.contentOffset.y - self.scrollNode.view.frame.height) let bottomContentOffset = max(0.0, self.scrollNode.view.contentSize.height - self.scrollNode.view.contentOffset.y - self.scrollNode.view.frame.height)
if bottomOffset < 100.0 { if bottomContentOffset < 100.0 {
self.profileGifts.loadMore() self.profileGifts.loadMore()
} }
} }

View File

@ -108,11 +108,9 @@ private final class ArchiveInfoSheetContentComponent: Component {
} }
contentHeight += buttonSize.height contentHeight += buttonSize.height
if environment.safeInsets.bottom.isZero { let bottomPanelPadding: CGFloat = 12.0
contentHeight += 16.0 let bottomInset: CGFloat = environment.safeInsets.bottom > 0.0 ? environment.safeInsets.bottom + 5.0 : bottomPanelPadding
} else { contentHeight += bottomInset
contentHeight += environment.safeInsets.bottom + 14.0
}
return CGSize(width: availableSize.width, height: contentHeight) return CGSize(width: availableSize.width, height: contentHeight)
} }
@ -226,7 +224,7 @@ private final class ArchiveInfoScreenComponent: Component {
}) })
} }
)), )),
backgroundColor: .color(environment.theme.list.plainBackgroundColor), backgroundColor: .color(environment.theme.actionSheet.opaqueItemBackgroundColor),
animateOut: self.sheetAnimateOut animateOut: self.sheetAnimateOut
)), )),
environment: { environment: {

View File

@ -31,11 +31,9 @@ swift_library(
"//submodules/TextFormat", "//submodules/TextFormat",
"//submodules/TelegramUI/Components/ListSectionComponent", "//submodules/TelegramUI/Components/ListSectionComponent",
"//submodules/TelegramUI/Components/ListActionItemComponent", "//submodules/TelegramUI/Components/ListActionItemComponent",
"//submodules/TelegramUI/Components/ScrollComponent",
"//submodules/TelegramUI/Components/Premium/PremiumStarComponent", "//submodules/TelegramUI/Components/Premium/PremiumStarComponent",
"//submodules/TelegramUI/Components/ButtonComponent", "//submodules/TelegramUI/Components/ButtonComponent",
"//submodules/Components/BundleIconComponent", "//submodules/Components/BundleIconComponent",
"//submodules/Components/SolidRoundedButtonComponent",
"//submodules/Components/BlurredBackgroundComponent", "//submodules/Components/BlurredBackgroundComponent",
], ],
visibility = [ visibility = [

View File

@ -8,18 +8,17 @@ import Markdown
import TextFormat import TextFormat
import TelegramPresentationData import TelegramPresentationData
import ViewControllerComponent import ViewControllerComponent
import ScrollComponent
import BundleIconComponent import BundleIconComponent
import BalancedTextComponent import BalancedTextComponent
import MultilineTextComponent import MultilineTextComponent
import SolidRoundedButtonComponent import ButtonComponent
import AccountContext import AccountContext
import ScrollComponent import SheetComponent
import BlurredBackgroundComponent import BlurredBackgroundComponent
import PremiumStarComponent import PremiumStarComponent
private final class ScrollContent: CombinedComponent { private final class SheetContent: CombinedComponent {
typealias EnvironmentType = (ViewControllerComponentContainer.Environment, ScrollChildEnvironment) typealias EnvironmentType = ViewControllerComponentContainer.Environment
let context: AccountContext let context: AccountContext
let openExamples: () -> Void let openExamples: () -> Void
@ -35,7 +34,7 @@ private final class ScrollContent: CombinedComponent {
self.dismiss = dismiss self.dismiss = dismiss
} }
static func ==(lhs: ScrollContent, rhs: ScrollContent) -> Bool { static func ==(lhs: SheetContent, rhs: SheetContent) -> Bool {
if lhs.context !== rhs.context { if lhs.context !== rhs.context {
return false return false
} }
@ -44,10 +43,10 @@ private final class ScrollContent: CombinedComponent {
static var body: Body { static var body: Body {
let star = Child(PremiumStarComponent.self) let star = Child(PremiumStarComponent.self)
let title = Child(BalancedTextComponent.self) let title = Child(BalancedTextComponent.self)
let text = Child(BalancedTextComponent.self) let text = Child(BalancedTextComponent.self)
let list = Child(List<Empty>.self) let list = Child(List<Empty>.self)
let actionButton = Child(ButtonComponent.self)
return { context in return { context in
let environment = context.environment[ViewControllerComponentContainer.Environment.self].value let environment = context.environment[ViewControllerComponentContainer.Environment.self].value
@ -82,13 +81,13 @@ private final class ScrollContent: CombinedComponent {
UIColor(rgb: 0xfdd219) UIColor(rgb: 0xfdd219)
], ],
particleColor: UIColor(rgb: 0xf9b004), particleColor: UIColor(rgb: 0xf9b004),
backgroundColor: environment.theme.list.plainBackgroundColor backgroundColor: environment.theme.actionSheet.opaqueItemBackgroundColor
), ),
availableSize: CGSize(width: min(414.0, context.availableSize.width), height: 220.0), availableSize: CGSize(width: min(414.0, context.availableSize.width), height: 220.0),
transition: context.transition transition: context.transition
) )
context.add(star context.add(star
.position(CGPoint(x: context.availableSize.width / 2.0, y: environment.navigationHeight + 24.0)) .position(CGPoint(x: context.availableSize.width / 2.0, y: 79.0))
) )
let title = title.update( let title = title.update(
@ -193,14 +192,39 @@ private final class ScrollContent: CombinedComponent {
.position(CGPoint(x: context.availableSize.width / 2.0, y: contentSize.height + list.size.height / 2.0)) .position(CGPoint(x: context.availableSize.width / 2.0, y: contentSize.height + list.size.height / 2.0))
) )
contentSize.height += list.size.height contentSize.height += list.size.height
contentSize.height += spacing - 9.0 contentSize.height += spacing
contentSize.height += 12.0 + 50.0 let buttonHeight: CGFloat = 50.0
if environment.safeInsets.bottom > 0 { let bottomPanelPadding: CGFloat = 12.0
contentSize.height += environment.safeInsets.bottom + 5.0 let bottomInset: CGFloat = environment.safeInsets.bottom > 0.0 ? environment.safeInsets.bottom + 5.0 : bottomPanelPadding
} else {
contentSize.height += 12.0 contentSize.height += bottomPanelPadding
let controller = environment.controller() as? StarsIntroScreen
let actionButton = actionButton.update(
component: ButtonComponent(
background: ButtonComponent.Background(
color: environment.theme.list.itemCheckColors.fillColor,
foreground: environment.theme.list.itemCheckColors.foregroundColor,
pressedColor: environment.theme.list.itemCheckColors.fillColor.withMultipliedAlpha(0.8)
),
content: AnyComponentWithIdentity(id: AnyHashable(0 as Int), component: AnyComponent(
Text(text: strings.Stars_Info_Done, font: Font.semibold(17.0), color: environment.theme.list.itemCheckColors.foregroundColor)
)),
isEnabled: true,
displaysProgress: false,
action: {
controller?.dismissAnimated()
} }
),
availableSize: CGSize(width: context.availableSize.width - sideInset * 2.0, height: buttonHeight),
transition: context.transition
)
context.add(actionButton
.position(CGPoint(x: context.availableSize.width / 2.0, y: contentSize.height + actionButton.size.height / 2.0))
.cornerRadius(10.0)
)
contentSize.height += actionButton.size.height + bottomInset
return contentSize return contentSize
} }
@ -238,129 +262,58 @@ private final class ContainerComponent: CombinedComponent {
} }
static var body: Body { static var body: Body {
let background = Child(Rectangle.self) let sheet = Child(SheetComponent<(EnvironmentType)>.self)
let scroll = Child(ScrollComponent<ViewControllerComponentContainer.Environment>.self) let animateOut = StoredActionSlot(Action<Void>.self)
let bottomPanel = Child(BlurredBackgroundComponent.self)
let bottomSeparator = Child(Rectangle.self)
let actionButton = Child(SolidRoundedButtonComponent.self)
let scrollExternalState = ScrollComponent<EnvironmentType>.ExternalState()
return { context in return { context in
let environment = context.environment[EnvironmentType.self] let environment = context.environment[EnvironmentType.self]
let theme = environment.theme
let strings = environment.strings
let state = context.state
let controller = environment.controller let controller = environment.controller
let background = background.update( let sheet = sheet.update(
component: Rectangle(color: environment.theme.list.plainBackgroundColor), component: SheetComponent<EnvironmentType>(
environment: {}, content: AnyComponent(SheetContent(
availableSize: context.availableSize,
transition: context.transition
)
context.add(background
.position(CGPoint(x: context.availableSize.width / 2.0, y: context.availableSize.height / 2.0))
)
let scroll = scroll.update(
component: ScrollComponent<EnvironmentType>(
content: AnyComponent(ScrollContent(
context: context.component.context, context: context.component.context,
openExamples: context.component.openExamples, openExamples: context.component.openExamples,
dismiss: { dismiss: {
controller()?.dismiss() controller()?.dismiss()
} }
)), )),
externalState: scrollExternalState, backgroundColor: .color(environment.theme.actionSheet.opaqueItemBackgroundColor),
contentInsets: UIEdgeInsets(top: 0.0, left: 0.0, bottom: 1.0, right: 0.0), followContentSizeChanges: true,
contentOffsetUpdated: { [weak state] topContentOffset, bottomContentOffset in clipsContent: true,
state?.topContentOffset = topContentOffset animateOut: animateOut
state?.bottomContentOffset = bottomContentOffset
Queue.mainQueue().justDispatch {
state?.updated(transition: .immediate)
}
},
contentOffsetWillCommit: { targetContentOffset in
}
), ),
environment: { environment }, environment: {
environment
SheetComponentEnvironment(
isDisplaying: environment.value.isVisible,
isCentered: environment.metrics.widthClass == .regular,
hasInputHeight: !environment.inputHeight.isZero,
regularMetricsSize: CGSize(width: 430.0, height: 900.0),
dismiss: { animated in
if animated {
animateOut.invoke(Action { _ in
if let controller = controller() {
controller.dismiss(completion: nil)
}
})
} else {
if let controller = controller() {
controller.dismiss(completion: nil)
}
}
}
)
},
availableSize: context.availableSize, availableSize: context.availableSize,
transition: context.transition transition: context.transition
) )
context.add(scroll context.add(sheet
.position(CGPoint(x: context.availableSize.width / 2.0, y: context.availableSize.height / 2.0)) .position(CGPoint(x: context.availableSize.width / 2.0, y: context.availableSize.height / 2.0))
) )
let buttonHeight: CGFloat = 50.0
let bottomPanelPadding: CGFloat = 12.0
let bottomInset: CGFloat = environment.safeInsets.bottom > 0.0 ? environment.safeInsets.bottom + 5.0 : bottomPanelPadding
let bottomPanelHeight = bottomPanelPadding + buttonHeight + bottomInset
let bottomPanelAlpha: CGFloat
if scrollExternalState.contentHeight > context.availableSize.height {
if let bottomContentOffset = state.bottomContentOffset {
bottomPanelAlpha = min(16.0, bottomContentOffset) / 16.0
} else {
bottomPanelAlpha = 1.0
}
} else {
bottomPanelAlpha = 0.0
}
let bottomPanel = bottomPanel.update(
component: BlurredBackgroundComponent(
color: theme.rootController.tabBar.backgroundColor
),
availableSize: CGSize(width: context.availableSize.width, height: bottomPanelHeight),
transition: context.transition
)
let bottomSeparator = bottomSeparator.update(
component: Rectangle(
color: theme.rootController.tabBar.separatorColor
),
availableSize: CGSize(width: context.availableSize.width, height: UIScreenPixel),
transition: context.transition
)
context.add(bottomPanel
.position(CGPoint(x: context.availableSize.width / 2.0, y: context.availableSize.height - bottomPanel.size.height / 2.0))
.opacity(bottomPanelAlpha)
)
context.add(bottomSeparator
.position(CGPoint(x: context.availableSize.width / 2.0, y: context.availableSize.height - bottomPanel.size.height))
.opacity(bottomPanelAlpha)
)
let sideInset: CGFloat = 16.0 + environment.safeInsets.left
let actionButton = actionButton.update(
component: SolidRoundedButtonComponent(
title: strings.Stars_Info_Done,
theme: SolidRoundedButtonComponent.Theme(
backgroundColor: theme.list.itemCheckColors.fillColor,
backgroundColors: [],
foregroundColor: theme.list.itemCheckColors.foregroundColor
),
font: .bold,
fontSize: 17.0,
height: buttonHeight,
cornerRadius: 10.0,
gloss: false,
iconName: nil,
animationName: nil,
iconPosition: .left,
action: {
controller()?.dismiss()
}
),
availableSize: CGSize(width: context.availableSize.width - sideInset * 2.0, height: 50.0),
transition: context.transition
)
context.add(actionButton
.position(CGPoint(x: context.availableSize.width / 2.0, y: context.availableSize.height - bottomPanelHeight + bottomPanelPadding + actionButton.size.height / 2.0))
)
return context.availableSize return context.availableSize
} }
} }
@ -389,7 +342,7 @@ public final class StarsIntroScreen: ViewControllerComponentContainer {
theme: forceDark ? .dark : .default theme: forceDark ? .dark : .default
) )
self.navigationPresentation = .modal self.navigationPresentation = .flatModal
openExamplesImpl = { [weak self] in openExamplesImpl = { [weak self] in
guard let self else { guard let self else {
@ -408,6 +361,12 @@ public final class StarsIntroScreen: ViewControllerComponentContainer {
required public init(coder aDecoder: NSCoder) { required public init(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented") fatalError("init(coder:) has not been implemented")
} }
public func dismissAnimated() {
if let view = self.node.hostView.findTaggedView(tag: SheetComponent<ViewControllerComponentContainer.Environment>.View.Tag()) as? SheetComponent<ViewControllerComponentContainer.Environment>.View {
view.dismissAnimated()
}
}
} }
private final class ParagraphComponent: CombinedComponent { private final class ParagraphComponent: CombinedComponent {

View File

@ -732,7 +732,7 @@ private final class StarsTransferSheetComponent: CombinedComponent {
}) })
} }
)), )),
backgroundColor: .blur(.light), backgroundColor: .color(environment.theme.list.modalBlocksBackgroundColor),
followContentSizeChanges: true, followContentSizeChanges: true,
clipsContent: true, clipsContent: true,
animateOut: animateOut animateOut: animateOut

View File

@ -52,7 +52,6 @@ private final class SheetContent: CombinedComponent {
} }
static var body: Body { static var body: Body {
let background = Child(RoundedRectangle.self)
let closeButton = Child(Button.self) let closeButton = Child(Button.self)
let title = Child(Text.self) let title = Child(Text.self)
let amountSection = Child(ListSectionComponent.self) let amountSection = Child(ListSectionComponent.self)
@ -75,15 +74,6 @@ private final class SheetContent: CombinedComponent {
let sideInset: CGFloat = 16.0 let sideInset: CGFloat = 16.0
var contentSize = CGSize(width: context.availableSize.width, height: 18.0) var contentSize = CGSize(width: context.availableSize.width, height: 18.0)
let background = background.update(
component: RoundedRectangle(color: theme.list.blocksBackgroundColor, cornerRadius: 8.0),
availableSize: CGSize(width: context.availableSize.width, height: 1000.0),
transition: .immediate
)
context.add(background
.position(CGPoint(x: context.availableSize.width / 2.0, y: background.size.height / 2.0))
)
let constrainedTitleWidth = context.availableSize.width - 16.0 * 2.0 let constrainedTitleWidth = context.availableSize.width - 16.0 * 2.0
let closeImage: UIImage let closeImage: UIImage
@ -466,7 +456,7 @@ private final class StarsWithdrawSheetComponent: CombinedComponent {
}) })
} }
)), )),
backgroundColor: .blur(.light), backgroundColor: .color(environment.theme.actionSheet.opaqueItemBackgroundColor),
followContentSizeChanges: false, followContentSizeChanges: false,
clipsContent: true, clipsContent: true,
isScrollEnabled: false, isScrollEnabled: false,