Fix story verification icon

This commit is contained in:
Ilya Laktyushin 2025-09-10 15:58:38 +04:00
parent 9d97a62195
commit 2c3a49780f

View File

@ -485,6 +485,7 @@ public final class StoryPeerListItemComponent: Component {
private let extractedBackgroundView: UIImageView
private let button: HighlightTrackingButton
private let titleContainer: UIView
fileprivate var composeLayer: StoryComposeLayer?
fileprivate let avatarContent: PortalSourceView
@ -514,6 +515,9 @@ public final class StoryPeerListItemComponent: Component {
self.button = HighlightTrackingButton()
self.titleContainer = UIView()
self.titleContainer.isUserInteractionEnabled = false
self.extractedContainerNode = ContextExtractedContentContainingNode()
self.containerNode = ContextControllerSourceNode()
self.extractedBackgroundView = UIImageView()
@ -560,6 +564,8 @@ public final class StoryPeerListItemComponent: Component {
self.avatarContent.addSubview(self.avatarContainer)
self.button.addSubview(self.avatarContent)
self.button.addSubview(self.titleContainer)
self.avatarContent.layer.addSublayer(self.indicatorColorSeenLayer)
self.avatarContent.layer.addSublayer(self.indicatorColorUnseenLayer)
self.indicatorMaskSeenLayer.addSublayer(self.indicatorShapeSeenLayer)
@ -878,6 +884,18 @@ public final class StoryPeerListItemComponent: Component {
}
}
let iconContainerSize = CGSize(width: 12.0, height: 12.0)
let iconSpacing: CGFloat = 1.0
var currentVerifiedIconContent: EmojiStatusComponent.Content?
if component.peer.isVerified {
currentVerifiedIconContent = .verified(fillColor: component.theme.list.itemCheckColors.fillColor, foregroundColor: component.theme.list.itemCheckColors.foregroundColor, sizeType: .smaller)
}
var titleConstrainedSize = CGSize(width: availableSize.width + 12.0, height: 100.0)
if let _ = currentVerifiedIconContent {
titleConstrainedSize.width -= iconContainerSize.width + iconSpacing
}
let titleSize = self.title.update(
transition: .immediate,
component: AnyComponent(MultilineTextComponent(
@ -885,15 +903,10 @@ public final class StoryPeerListItemComponent: Component {
maximumNumberOfLines: 1
)),
environment: {},
containerSize: CGSize(width: availableSize.width + 12.0, height: 100.0)
containerSize: titleConstrainedSize
)
var totalTitleWidth = titleSize.width
var currentVerifiedIconContent: EmojiStatusComponent.Content?
if component.peer.isVerified {
currentVerifiedIconContent = .verified(fillColor: component.theme.list.itemCheckColors.fillColor, foregroundColor: component.theme.list.itemCheckColors.foregroundColor, sizeType: .smaller)
}
if let currentVerifiedIconContent {
let verifiedIconView: ComponentHostView<Empty>
if let current = self.verifiedIconView {
@ -902,16 +915,14 @@ public final class StoryPeerListItemComponent: Component {
verifiedIconView = ComponentHostView<Empty>()
verifiedIconView.isUserInteractionEnabled = false
self.verifiedIconView = verifiedIconView
self.button.addSubview(verifiedIconView)
self.titleContainer.addSubview(verifiedIconView)
}
let containerSize = CGSize(width: 12.0, height: 12.0)
let verifiedIconComponent = EmojiStatusComponent(
context: component.context,
animationCache: component.context.animationCache,
animationRenderer: component.context.animationRenderer,
content: currentVerifiedIconContent,
size: containerSize,
size: iconContainerSize,
isVisibleForAnimations: component.context.sharedContext.energyUsageSettings.loopEmoji,
action: nil
)
@ -920,38 +931,36 @@ public final class StoryPeerListItemComponent: Component {
transition: .immediate,
component: AnyComponent(verifiedIconComponent),
environment: {},
containerSize: containerSize
containerSize: iconContainerSize
)
totalTitleWidth += iconSize.width + 1.0
var titleScale = effectiveScale
if titleScale < 1.0 {
titleScale = min(1.0, titleScale + 0.02)
} else if titleScale > 1.01 {
titleScale = max(1.0, titleScale * 0.96)
}
let verifiedIconFrame = CGRect(origin: CGPoint(x: floor((availableSize.width - totalTitleWidth) * 0.5) + (titleSize.width + 1.0) * titleScale + (effectiveWidth - availableSize.width) * 0.5, y: indicatorFrame.midY + (indicatorFrame.height * 0.5 + 2.0 + UIScreenPixel) * effectiveScale), size: iconSize)
titleTransition.setPosition(view: verifiedIconView, position: verifiedIconFrame.center)
verifiedIconView.bounds = CGRect(origin: CGPoint(), size: verifiedIconFrame.size)
titleTransition.setScale(view: verifiedIconView, scale: effectiveScale)
titleTransition.setAlpha(view: verifiedIconView, alpha: component.expandedAlphaFraction)
totalTitleWidth += iconSize.width + iconSpacing
let verifiedIconFrame = CGRect(origin: CGPoint(x: totalTitleWidth - iconSize.width, y: UIScreenPixel), size: iconSize)
titleTransition.setFrame(view: verifiedIconView, frame: verifiedIconFrame)
} else if let verifiedIconView = self.verifiedIconView {
self.verifiedIconView = nil
verifiedIconView.removeFromSuperview()
}
let titleFrame = CGRect(origin: CGPoint(x: floor((availableSize.width - totalTitleWidth) * 0.5) + (effectiveWidth - availableSize.width) * 0.5, y: indicatorFrame.midY + (indicatorFrame.height * 0.5 + 2.0) * effectiveScale), size: titleSize)
let titleFrame = CGRect(origin: .zero, size: titleSize)
if let titleView = self.title.view {
if titleView.superview == nil {
titleView.layer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
titleView.isUserInteractionEnabled = false
self.button.addSubview(titleView)
self.titleContainer.addSubview(titleView)
}
titleTransition.setPosition(view: titleView, position: titleFrame.center)
titleView.bounds = CGRect(origin: CGPoint(), size: titleFrame.size)
titleTransition.setScale(view: titleView, scale: effectiveScale)
titleTransition.setAlpha(view: titleView, alpha: component.expandedAlphaFraction)
}
let titleContainerSize = CGSize(width: totalTitleWidth, height: titleSize.height)
let titleContainerFrame = CGRect(origin: CGPoint(x: floor((availableSize.width - titleContainerSize.width) * 0.5) + (effectiveWidth - availableSize.width) * 0.5, y: indicatorFrame.midY + (indicatorFrame.height * 0.5 + 2.0) * effectiveScale), size: titleContainerSize)
titleTransition.setPosition(view: self.titleContainer, position: titleContainerFrame.center)
self.titleContainer.bounds = CGRect(origin: CGPoint(), size: titleContainerFrame.size)
titleTransition.setScale(view: self.titleContainer, scale: effectiveScale)
titleTransition.setAlpha(view: self.titleContainer, alpha: component.expandedAlphaFraction)
if let ringAnimation = component.ringAnimation {
var progressTransition = transition
let progressLayer: StoryProgressLayer