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 extractedBackgroundView: UIImageView
private let button: HighlightTrackingButton private let button: HighlightTrackingButton
private let titleContainer: UIView
fileprivate var composeLayer: StoryComposeLayer? fileprivate var composeLayer: StoryComposeLayer?
fileprivate let avatarContent: PortalSourceView fileprivate let avatarContent: PortalSourceView
@ -514,6 +515,9 @@ public final class StoryPeerListItemComponent: Component {
self.button = HighlightTrackingButton() self.button = HighlightTrackingButton()
self.titleContainer = UIView()
self.titleContainer.isUserInteractionEnabled = false
self.extractedContainerNode = ContextExtractedContentContainingNode() self.extractedContainerNode = ContextExtractedContentContainingNode()
self.containerNode = ContextControllerSourceNode() self.containerNode = ContextControllerSourceNode()
self.extractedBackgroundView = UIImageView() self.extractedBackgroundView = UIImageView()
@ -560,6 +564,8 @@ public final class StoryPeerListItemComponent: Component {
self.avatarContent.addSubview(self.avatarContainer) self.avatarContent.addSubview(self.avatarContainer)
self.button.addSubview(self.avatarContent) self.button.addSubview(self.avatarContent)
self.button.addSubview(self.titleContainer)
self.avatarContent.layer.addSublayer(self.indicatorColorSeenLayer) self.avatarContent.layer.addSublayer(self.indicatorColorSeenLayer)
self.avatarContent.layer.addSublayer(self.indicatorColorUnseenLayer) self.avatarContent.layer.addSublayer(self.indicatorColorUnseenLayer)
self.indicatorMaskSeenLayer.addSublayer(self.indicatorShapeSeenLayer) 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( let titleSize = self.title.update(
transition: .immediate, transition: .immediate,
component: AnyComponent(MultilineTextComponent( component: AnyComponent(MultilineTextComponent(
@ -885,15 +903,10 @@ public final class StoryPeerListItemComponent: Component {
maximumNumberOfLines: 1 maximumNumberOfLines: 1
)), )),
environment: {}, environment: {},
containerSize: CGSize(width: availableSize.width + 12.0, height: 100.0) containerSize: titleConstrainedSize
) )
var totalTitleWidth = titleSize.width 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 { if let currentVerifiedIconContent {
let verifiedIconView: ComponentHostView<Empty> let verifiedIconView: ComponentHostView<Empty>
if let current = self.verifiedIconView { if let current = self.verifiedIconView {
@ -902,16 +915,14 @@ public final class StoryPeerListItemComponent: Component {
verifiedIconView = ComponentHostView<Empty>() verifiedIconView = ComponentHostView<Empty>()
verifiedIconView.isUserInteractionEnabled = false verifiedIconView.isUserInteractionEnabled = false
self.verifiedIconView = verifiedIconView self.verifiedIconView = verifiedIconView
self.button.addSubview(verifiedIconView) self.titleContainer.addSubview(verifiedIconView)
} }
let containerSize = CGSize(width: 12.0, height: 12.0)
let verifiedIconComponent = EmojiStatusComponent( let verifiedIconComponent = EmojiStatusComponent(
context: component.context, context: component.context,
animationCache: component.context.animationCache, animationCache: component.context.animationCache,
animationRenderer: component.context.animationRenderer, animationRenderer: component.context.animationRenderer,
content: currentVerifiedIconContent, content: currentVerifiedIconContent,
size: containerSize, size: iconContainerSize,
isVisibleForAnimations: component.context.sharedContext.energyUsageSettings.loopEmoji, isVisibleForAnimations: component.context.sharedContext.energyUsageSettings.loopEmoji,
action: nil action: nil
) )
@ -920,38 +931,36 @@ public final class StoryPeerListItemComponent: Component {
transition: .immediate, transition: .immediate,
component: AnyComponent(verifiedIconComponent), component: AnyComponent(verifiedIconComponent),
environment: {}, environment: {},
containerSize: containerSize containerSize: iconContainerSize
) )
totalTitleWidth += iconSize.width + 1.0 totalTitleWidth += iconSize.width + iconSpacing
var titleScale = effectiveScale
if titleScale < 1.0 { let verifiedIconFrame = CGRect(origin: CGPoint(x: totalTitleWidth - iconSize.width, y: UIScreenPixel), size: iconSize)
titleScale = min(1.0, titleScale + 0.02) titleTransition.setFrame(view: verifiedIconView, frame: verifiedIconFrame)
} 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)
} else if let verifiedIconView = self.verifiedIconView { } else if let verifiedIconView = self.verifiedIconView {
self.verifiedIconView = nil self.verifiedIconView = nil
verifiedIconView.removeFromSuperview() 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 let titleView = self.title.view {
if titleView.superview == nil { if titleView.superview == nil {
titleView.layer.anchorPoint = CGPoint(x: 0.5, y: 0.5) titleView.layer.anchorPoint = CGPoint(x: 0.5, y: 0.5)
titleView.isUserInteractionEnabled = false titleView.isUserInteractionEnabled = false
self.button.addSubview(titleView) self.titleContainer.addSubview(titleView)
} }
titleTransition.setPosition(view: titleView, position: titleFrame.center) titleTransition.setPosition(view: titleView, position: titleFrame.center)
titleView.bounds = CGRect(origin: CGPoint(), size: titleFrame.size) 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 { if let ringAnimation = component.ringAnimation {
var progressTransition = transition var progressTransition = transition
let progressLayer: StoryProgressLayer let progressLayer: StoryProgressLayer