Update indicator positioning

This commit is contained in:
Ali 2022-06-07 14:30:11 +04:00
parent 654e8851bb
commit f72ab6bd3d
2 changed files with 22 additions and 11 deletions

View File

@ -6,13 +6,18 @@ import Display
public final class AudioTranscriptionPendingIndicatorComponent: Component {
public let color: UIColor
public let font: UIFont
public init(color: UIColor) {
public init(color: UIColor, font: UIFont) {
self.color = color
self.font = font
}
public static func ==(lhs: AudioTranscriptionPendingIndicatorComponent, rhs: AudioTranscriptionPendingIndicatorComponent) -> Bool {
if lhs.color !== rhs.color {
if lhs.color != rhs.color {
return false
}
if lhs.font != rhs.font {
return false
}
return true
@ -61,6 +66,10 @@ public final class AudioTranscriptionPendingIndicatorComponent: Component {
let dotSize: CGFloat = 2.0
let spacing: CGFloat = 3.0
var stringSize = NSAttributedString(string: "...", font: component.font, textColor: .black).boundingRect(with: CGSize(width: 100.0, height: 100.0), options: .usesLineFragmentOrigin, context: nil).size
stringSize.width = ceil(stringSize.width)
stringSize.height = ceil(stringSize.height)
if self.component?.color != component.color {
if let dotImage = generateFilledCircleImage(diameter: dotSize, color: component.color) {
for dotLayer in self.dotLayers {
@ -77,7 +86,7 @@ public final class AudioTranscriptionPendingIndicatorComponent: Component {
self.dotLayers[i].frame = CGRect(origin: CGPoint(x: CGFloat(i) * (dotSize + spacing), y: 0.0), size: CGSize(width: dotSize, height: dotSize))
}
return CGSize(width: min(availableSize.width, size.width), height: min(availableSize.height, size.height))
return CGSize(width: min(availableSize.width, stringSize.width), height: min(availableSize.height, size.height))
}
}

View File

@ -654,16 +654,18 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode {
var displayTrailingAnimatedDots = false
/*#if DEBUG
if "".isEmpty {
displayTrailingAnimatedDots = true
}
#endif*/
if let transcribedText = transcribedText, case .expanded = effectiveAudioTranscriptionState {
switch transcribedText {
case let .success(text, isPending):
textString = NSAttributedString(string: text, font: textFont, textColor: messageTheme.primaryTextColor)
/*#if DEBUG
var isPending = isPending
if "".isEmpty {
isPending = true
}
#endif*/
if isPending {
let modifiedString = NSMutableAttributedString(attributedString: textString!)
modifiedString.append(NSAttributedString(string: "...", font: textFont, textColor: .clear))
@ -1027,12 +1029,12 @@ final class ChatMessageInteractiveFileNode: ASDisplayNode {
}
let indicatorSize = transcriptionPendingIndicator.update(
transition: .immediate,
component: AnyComponent(AudioTranscriptionPendingIndicatorComponent(color: messageTheme.primaryTextColor)),
component: AnyComponent(AudioTranscriptionPendingIndicatorComponent(color: messageTheme.primaryTextColor, font: textFont)),
environment: {},
containerSize: CGSize(width: 100.0, height: 100.0)
)
transcriptionPendingIndicator.frame = CGRect(origin: CGPoint(x: strongSelf.textNode.frame.minX + textLayout.trailingLineWidth + 2.0, y: strongSelf.textNode.frame.maxY - indicatorSize.height - 6.0), size: indicatorSize)
transcriptionPendingIndicator.frame = CGRect(origin: CGPoint(x: strongSelf.textNode.frame.minX + textLayout.trailingLineWidth - indicatorSize.width + 1.0, y: strongSelf.textNode.frame.maxY - indicatorSize.height - 6.0), size: indicatorSize)
} else {
if let transcriptionPendingIndicator = strongSelf.transcriptionPendingIndicator {
strongSelf.transcriptionPendingIndicator = nil