Fix stars ref UI

(cherry picked from commit 1abaeddfad850a90402527754a69e2bd08f672f8)
This commit is contained in:
Isaac 2024-12-06 22:15:42 +08:00
parent 00150920d9
commit 285e21cbdf
3 changed files with 54 additions and 25 deletions

View File

@ -1,6 +1,7 @@
import Foundation
import UIKit
import ComponentFlow
import MultilineTextComponent
final class TextView: UIView {
private struct Params: Equatable {
@ -21,6 +22,8 @@ final class TextView: UIView {
private var layoutState: LayoutState?
private var animateContentsTransition: Bool = false
private let content = ComponentView<Empty>()
override init(frame: CGRect) {
super.init(frame: CGRect())
@ -56,17 +59,26 @@ final class TextView: UIView {
font = UIFont.systemFont(ofSize: fontSize, weight: UIFont.Weight(fontWeight))
}
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = alignment
paragraphStyle.lineSpacing = 0.6
let attributedString = NSAttributedString(string: string, attributes: [
.font: font,
.foregroundColor: color,
.paragraphStyle: paragraphStyle
])
let stringBounds = attributedString.boundingRect(with: CGSize(width: constrainedWidth, height: 200.0), options: .usesLineFragmentOrigin, context: nil)
let stringSize = CGSize(width: ceil(stringBounds.width), height: ceil(stringBounds.height))
let size = CGSize(width: min(constrainedWidth, stringSize.width), height: stringSize.height)
let contentSize = self.content.update(
transition: .immediate,
component: AnyComponent(MultilineTextComponent(
text: .plain(attributedString),
horizontalAlignment: alignment,
lineSpacing: 0.6
)),
environment: {},
containerSize: CGSize(width: constrainedWidth, height: 1000.0)
)
if let contentView = self.content.view {
contentView.frame = CGRect(origin: CGPoint(), size: contentSize)
}
let size = CGSize(width: min(constrainedWidth, contentSize.width), height: contentSize.height)
let layoutState = LayoutState(params: params, size: size, attributedString: attributedString)
if self.layoutState != layoutState {
@ -79,10 +91,12 @@ final class TextView: UIView {
}
override func draw(_ rect: CGRect) {
guard let layoutState = self.layoutState else {
guard let _ = self.layoutState else {
return
}
layoutState.attributedString.draw(with: rect, options: [.truncatesLastVisibleLine, .usesLineFragmentOrigin], context: nil)
if let contentView = self.content.view {
contentView.draw(contentView.bounds)
}
}
}

View File

@ -94,6 +94,7 @@ final class AffiliateProgramSetupScreenComponent: Component {
private let coinIcon = ComponentView<Empty>()
private let title = ComponentView<Empty>()
private let titleTransformContainer: UIView
private var titleNeutralScale: CGFloat = 1.0
private let subtitle = ComponentView<Empty>()
private let introBackground = ComponentView<Empty>()
@ -339,7 +340,7 @@ final class AffiliateProgramSetupScreenComponent: Component {
let titleYDistance: CGFloat = titleY - titleCenterY
let titleTransformFraction: CGFloat = 1.0 - max(0.0, min(1.0, titleYDistance / titleTransformDistance))
let titleMinScale: CGFloat = 17.0 / 30.0
let titleScale: CGFloat = 1.0 * (1.0 - titleTransformFraction) + titleMinScale * titleTransformFraction
let titleScale: CGFloat = self.titleNeutralScale * (1.0 - titleTransformFraction) + (titleMinScale / self.titleNeutralScale) * titleTransformFraction
if let titleView = self.title.view {
transition.setScale(view: titleView, scale: titleScale)
}
@ -668,9 +669,11 @@ final class AffiliateProgramSetupScreenComponent: Component {
text: .plain(NSAttributedString(string: titleValue, font: Font.bold(30.0), textColor: environment.theme.list.itemPrimaryTextColor))
)),
environment: {},
containerSize: CGSize(width: availableSize.width - textSideInset * 2.0, height: 1000.0)
containerSize: CGSize(width: availableSize.width + 140.0, height: 1000.0)
)
let titleFrame = CGRect(origin: CGPoint(x: floor((availableSize.width - titleSize.width) * 0.5), y: contentHeight), size: titleSize)
let titleNeutralScale: CGFloat = min(1.0, (availableSize.width - sideInset * 2.0) / titleSize.width)
self.titleNeutralScale = titleNeutralScale
if let titleView = self.title.view {
if self.titleTransformContainer.superview == nil {
if let controller = environment.controller(), let navigationBar = controller.navigationBar {
@ -685,7 +688,7 @@ final class AffiliateProgramSetupScreenComponent: Component {
titleView.bounds = CGRect(origin: CGPoint(), size: titleFrame.size)
transition.setPosition(view: self.titleTransformContainer, position: titleFrame.center)
}
contentHeight += titleSize.height
contentHeight += floor(titleSize.height * titleNeutralScale)
contentHeight += 10.0
let subtitleSize = self.subtitle.update(
@ -855,8 +858,8 @@ final class AffiliateProgramSetupScreenComponent: Component {
transition: transition,
component: AnyComponent(FilledRoundedRectangleComponent(
color: environment.theme.list.itemBlocksBackgroundColor,
cornerRadius: .value(5.0),
smoothCorners: true
cornerRadius: .value(11.0),
smoothCorners: false
)),
environment: {},
containerSize: introBackgroundFrame.size
@ -1153,7 +1156,7 @@ final class AffiliateProgramSetupScreenComponent: Component {
),
content: AnyComponentWithIdentity(id: AnyHashable(0 as Int), component: AnyComponent(Text(text: buttonText, font: Font.semibold(17.0), color: environment.theme.list.itemCheckColors.foregroundColor))),
isEnabled: self.currentProgram?.endDate == nil,
allowActionWhenDisabled: true,
allowActionWhenDisabled: false,
displaysProgress: false,
action: { [weak self] in
guard let self else {

View File

@ -286,17 +286,25 @@ private final class PeerInfoScreenDisclosureItemNode: PeerInfoScreenItemNode {
if self.labelBadgeNode.supernode == nil {
self.insertSubnode(self.labelBadgeNode, belowSubnode: self.labelNode)
}
} else if item.additionalBadgeLabel != nil {
if previousItem?.additionalBadgeLabel == nil {
self.labelBadgeNode.image = generateFilledRoundedRectImage(size: CGSize(width: 16.0, height: 16.0), cornerRadius: 5.0, color: presentationData.theme.list.itemCheckColors.fillColor)?.stretchableImage(withLeftCapWidth: 6, topCapHeight: 6)
}
if self.labelBadgeNode.supernode == nil {
self.insertSubnode(self.labelBadgeNode, belowSubnode: self.labelNode)
}
} else {
self.labelBadgeNode.removeFromSupernode()
}
if item.additionalBadgeLabel != nil {
if previousItem?.additionalBadgeLabel == nil {
let additionalLabelBadgeNode: ASImageNode
if let current = self.additionalLabelBadgeNode {
additionalLabelBadgeNode = current
} else {
additionalLabelBadgeNode = ASImageNode()
additionalLabelBadgeNode.isUserInteractionEnabled = false
self.additionalLabelBadgeNode = additionalLabelBadgeNode
self.insertSubnode(additionalLabelBadgeNode, belowSubnode: self.labelNode)
}
additionalLabelBadgeNode.image = generateFilledRoundedRectImage(size: CGSize(width: 16.0, height: 16.0), cornerRadius: 5.0, color: presentationData.theme.list.itemCheckColors.fillColor)?.stretchableImage(withLeftCapWidth: 6, topCapHeight: 6)
}
}
if let additionalBadgeIcon = item.additionalBadgeIcon {
let additionalLabelBadgeNode: ASImageNode
if let current = self.additionalLabelBadgeNode {
@ -308,7 +316,7 @@ private final class PeerInfoScreenDisclosureItemNode: PeerInfoScreenItemNode {
self.insertSubnode(additionalLabelBadgeNode, belowSubnode: self.labelNode)
}
additionalLabelBadgeNode.image = additionalBadgeIcon
} else {
} else if item.additionalBadgeLabel == nil {
if let additionalLabelBadgeNode = self.additionalLabelBadgeNode {
self.additionalLabelBadgeNode = nil
additionalLabelBadgeNode.removeFromSupernode()
@ -352,8 +360,12 @@ private final class PeerInfoScreenDisclosureItemNode: PeerInfoScreenItemNode {
}
if let additionalLabelBadgeNode = self.additionalLabelBadgeNode, let image = additionalLabelBadgeNode.image {
let additionalLabelSize = image.size
additionalLabelBadgeNode.frame = CGRect(origin: CGPoint(x: textFrame.maxX + 6.0, y: floor((height - additionalLabelSize.height) / 2.0) + 1.0), size: additionalLabelSize)
if item.additionalBadgeLabel != nil, let additionalLabelNode = self.additionalLabelNode {
additionalLabelBadgeNode.frame = additionalLabelNode.frame.insetBy(dx: -4.0, dy: -2.0 + UIScreenPixel)
} else {
let additionalLabelSize = image.size
additionalLabelBadgeNode.frame = CGRect(origin: CGPoint(x: textFrame.maxX + 6.0, y: floor((height - additionalLabelSize.height) / 2.0) + 1.0), size: additionalLabelSize)
}
}
let labelBadgeNodeFrame: CGRect