Skip to content

Commit 285e21c

Browse files
author
Isaac
committed
Fix stars ref UI
(cherry picked from commit 1abaedd)
1 parent 0015092 commit 285e21c

File tree

3 files changed

+54
-25
lines changed

3 files changed

+54
-25
lines changed

submodules/TelegramUI/Components/Calls/CallScreen/Sources/Components/TitleView.swift

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Foundation
22
import UIKit
33
import ComponentFlow
4+
import MultilineTextComponent
45

56
final class TextView: UIView {
67
private struct Params: Equatable {
@@ -21,6 +22,8 @@ final class TextView: UIView {
2122
private var layoutState: LayoutState?
2223
private var animateContentsTransition: Bool = false
2324

25+
private let content = ComponentView<Empty>()
26+
2427
override init(frame: CGRect) {
2528
super.init(frame: CGRect())
2629

@@ -56,17 +59,26 @@ final class TextView: UIView {
5659
font = UIFont.systemFont(ofSize: fontSize, weight: UIFont.Weight(fontWeight))
5760
}
5861

59-
let paragraphStyle = NSMutableParagraphStyle()
60-
paragraphStyle.alignment = alignment
61-
paragraphStyle.lineSpacing = 0.6
6262
let attributedString = NSAttributedString(string: string, attributes: [
6363
.font: font,
6464
.foregroundColor: color,
65-
.paragraphStyle: paragraphStyle
6665
])
67-
let stringBounds = attributedString.boundingRect(with: CGSize(width: constrainedWidth, height: 200.0), options: .usesLineFragmentOrigin, context: nil)
68-
let stringSize = CGSize(width: ceil(stringBounds.width), height: ceil(stringBounds.height))
69-
let size = CGSize(width: min(constrainedWidth, stringSize.width), height: stringSize.height)
66+
67+
let contentSize = self.content.update(
68+
transition: .immediate,
69+
component: AnyComponent(MultilineTextComponent(
70+
text: .plain(attributedString),
71+
horizontalAlignment: alignment,
72+
lineSpacing: 0.6
73+
)),
74+
environment: {},
75+
containerSize: CGSize(width: constrainedWidth, height: 1000.0)
76+
)
77+
if let contentView = self.content.view {
78+
contentView.frame = CGRect(origin: CGPoint(), size: contentSize)
79+
}
80+
81+
let size = CGSize(width: min(constrainedWidth, contentSize.width), height: contentSize.height)
7082

7183
let layoutState = LayoutState(params: params, size: size, attributedString: attributedString)
7284
if self.layoutState != layoutState {
@@ -79,10 +91,12 @@ final class TextView: UIView {
7991
}
8092

8193
override func draw(_ rect: CGRect) {
82-
guard let layoutState = self.layoutState else {
94+
guard let _ = self.layoutState else {
8395
return
8496
}
8597

86-
layoutState.attributedString.draw(with: rect, options: [.truncatesLastVisibleLine, .usesLineFragmentOrigin], context: nil)
98+
if let contentView = self.content.view {
99+
contentView.draw(contentView.bounds)
100+
}
87101
}
88102
}

submodules/TelegramUI/Components/PeerInfo/AffiliateProgramSetupScreen/Sources/AffiliateProgramSetupScreen.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ final class AffiliateProgramSetupScreenComponent: Component {
9494
private let coinIcon = ComponentView<Empty>()
9595
private let title = ComponentView<Empty>()
9696
private let titleTransformContainer: UIView
97+
private var titleNeutralScale: CGFloat = 1.0
9798
private let subtitle = ComponentView<Empty>()
9899

99100
private let introBackground = ComponentView<Empty>()
@@ -339,7 +340,7 @@ final class AffiliateProgramSetupScreenComponent: Component {
339340
let titleYDistance: CGFloat = titleY - titleCenterY
340341
let titleTransformFraction: CGFloat = 1.0 - max(0.0, min(1.0, titleYDistance / titleTransformDistance))
341342
let titleMinScale: CGFloat = 17.0 / 30.0
342-
let titleScale: CGFloat = 1.0 * (1.0 - titleTransformFraction) + titleMinScale * titleTransformFraction
343+
let titleScale: CGFloat = self.titleNeutralScale * (1.0 - titleTransformFraction) + (titleMinScale / self.titleNeutralScale) * titleTransformFraction
343344
if let titleView = self.title.view {
344345
transition.setScale(view: titleView, scale: titleScale)
345346
}
@@ -668,9 +669,11 @@ final class AffiliateProgramSetupScreenComponent: Component {
668669
text: .plain(NSAttributedString(string: titleValue, font: Font.bold(30.0), textColor: environment.theme.list.itemPrimaryTextColor))
669670
)),
670671
environment: {},
671-
containerSize: CGSize(width: availableSize.width - textSideInset * 2.0, height: 1000.0)
672+
containerSize: CGSize(width: availableSize.width + 140.0, height: 1000.0)
672673
)
673674
let titleFrame = CGRect(origin: CGPoint(x: floor((availableSize.width - titleSize.width) * 0.5), y: contentHeight), size: titleSize)
675+
let titleNeutralScale: CGFloat = min(1.0, (availableSize.width - sideInset * 2.0) / titleSize.width)
676+
self.titleNeutralScale = titleNeutralScale
674677
if let titleView = self.title.view {
675678
if self.titleTransformContainer.superview == nil {
676679
if let controller = environment.controller(), let navigationBar = controller.navigationBar {
@@ -685,7 +688,7 @@ final class AffiliateProgramSetupScreenComponent: Component {
685688
titleView.bounds = CGRect(origin: CGPoint(), size: titleFrame.size)
686689
transition.setPosition(view: self.titleTransformContainer, position: titleFrame.center)
687690
}
688-
contentHeight += titleSize.height
691+
contentHeight += floor(titleSize.height * titleNeutralScale)
689692
contentHeight += 10.0
690693

691694
let subtitleSize = self.subtitle.update(
@@ -855,8 +858,8 @@ final class AffiliateProgramSetupScreenComponent: Component {
855858
transition: transition,
856859
component: AnyComponent(FilledRoundedRectangleComponent(
857860
color: environment.theme.list.itemBlocksBackgroundColor,
858-
cornerRadius: .value(5.0),
859-
smoothCorners: true
861+
cornerRadius: .value(11.0),
862+
smoothCorners: false
860863
)),
861864
environment: {},
862865
containerSize: introBackgroundFrame.size
@@ -1153,7 +1156,7 @@ final class AffiliateProgramSetupScreenComponent: Component {
11531156
),
11541157
content: AnyComponentWithIdentity(id: AnyHashable(0 as Int), component: AnyComponent(Text(text: buttonText, font: Font.semibold(17.0), color: environment.theme.list.itemCheckColors.foregroundColor))),
11551158
isEnabled: self.currentProgram?.endDate == nil,
1156-
allowActionWhenDisabled: true,
1159+
allowActionWhenDisabled: false,
11571160
displaysProgress: false,
11581161
action: { [weak self] in
11591162
guard let self else {

submodules/TelegramUI/Components/PeerInfo/PeerInfoScreen/Sources/ListItems/PeerInfoScreenDisclosureItem.swift

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -286,17 +286,25 @@ private final class PeerInfoScreenDisclosureItemNode: PeerInfoScreenItemNode {
286286
if self.labelBadgeNode.supernode == nil {
287287
self.insertSubnode(self.labelBadgeNode, belowSubnode: self.labelNode)
288288
}
289-
} else if item.additionalBadgeLabel != nil {
290-
if previousItem?.additionalBadgeLabel == nil {
291-
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)
292-
}
293-
if self.labelBadgeNode.supernode == nil {
294-
self.insertSubnode(self.labelBadgeNode, belowSubnode: self.labelNode)
295-
}
296289
} else {
297290
self.labelBadgeNode.removeFromSupernode()
298291
}
299292

293+
if item.additionalBadgeLabel != nil {
294+
if previousItem?.additionalBadgeLabel == nil {
295+
let additionalLabelBadgeNode: ASImageNode
296+
if let current = self.additionalLabelBadgeNode {
297+
additionalLabelBadgeNode = current
298+
} else {
299+
additionalLabelBadgeNode = ASImageNode()
300+
additionalLabelBadgeNode.isUserInteractionEnabled = false
301+
self.additionalLabelBadgeNode = additionalLabelBadgeNode
302+
self.insertSubnode(additionalLabelBadgeNode, belowSubnode: self.labelNode)
303+
}
304+
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)
305+
}
306+
}
307+
300308
if let additionalBadgeIcon = item.additionalBadgeIcon {
301309
let additionalLabelBadgeNode: ASImageNode
302310
if let current = self.additionalLabelBadgeNode {
@@ -308,7 +316,7 @@ private final class PeerInfoScreenDisclosureItemNode: PeerInfoScreenItemNode {
308316
self.insertSubnode(additionalLabelBadgeNode, belowSubnode: self.labelNode)
309317
}
310318
additionalLabelBadgeNode.image = additionalBadgeIcon
311-
} else {
319+
} else if item.additionalBadgeLabel == nil {
312320
if let additionalLabelBadgeNode = self.additionalLabelBadgeNode {
313321
self.additionalLabelBadgeNode = nil
314322
additionalLabelBadgeNode.removeFromSupernode()
@@ -352,8 +360,12 @@ private final class PeerInfoScreenDisclosureItemNode: PeerInfoScreenItemNode {
352360
}
353361

354362
if let additionalLabelBadgeNode = self.additionalLabelBadgeNode, let image = additionalLabelBadgeNode.image {
355-
let additionalLabelSize = image.size
356-
additionalLabelBadgeNode.frame = CGRect(origin: CGPoint(x: textFrame.maxX + 6.0, y: floor((height - additionalLabelSize.height) / 2.0) + 1.0), size: additionalLabelSize)
363+
if item.additionalBadgeLabel != nil, let additionalLabelNode = self.additionalLabelNode {
364+
additionalLabelBadgeNode.frame = additionalLabelNode.frame.insetBy(dx: -4.0, dy: -2.0 + UIScreenPixel)
365+
} else {
366+
let additionalLabelSize = image.size
367+
additionalLabelBadgeNode.frame = CGRect(origin: CGPoint(x: textFrame.maxX + 6.0, y: floor((height - additionalLabelSize.height) / 2.0) + 1.0), size: additionalLabelSize)
368+
}
357369
}
358370

359371
let labelBadgeNodeFrame: CGRect

0 commit comments

Comments
 (0)