Fix chat send button behavior

This commit is contained in:
2026-03-02 03:22:19 +05:00
parent d1fcc04125
commit 8238fd1940
27 changed files with 3423 additions and 610 deletions

View File

@@ -45,6 +45,15 @@ struct LottieView: UIViewRepresentable, Equatable {
lhs.isPlaying == rhs.isPlaying
}
func makeCoordinator() -> Coordinator {
Coordinator()
}
final class Coordinator {
var didPlayOnce = false
var lastAnimationName = ""
}
func makeUIView(context: Context) -> LottieAnimationView {
let animationView: LottieAnimationView
if let cached = LottieAnimationCache.shared.animation(named: animationName) {
@@ -57,21 +66,45 @@ struct LottieView: UIViewRepresentable, Equatable {
animationView.animationSpeed = animationSpeed
animationView.setContentCompressionResistancePriority(.defaultLow, for: .horizontal)
animationView.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
if isPlaying {
animationView.play()
}
context.coordinator.lastAnimationName = animationName
playIfNeeded(animationView, coordinator: context.coordinator)
return animationView
}
func updateUIView(_ uiView: LottieAnimationView, context: Context) {
if isPlaying {
if !uiView.isAnimationPlaying {
uiView.play()
if context.coordinator.lastAnimationName != animationName {
if let cached = LottieAnimationCache.shared.animation(named: animationName) {
uiView.animation = cached
} else {
uiView.animation = LottieAnimation.named(animationName)
}
} else {
context.coordinator.lastAnimationName = animationName
context.coordinator.didPlayOnce = false
}
uiView.loopMode = loopMode
uiView.animationSpeed = animationSpeed
if !isPlaying {
context.coordinator.didPlayOnce = false
if uiView.isAnimationPlaying {
uiView.stop()
}
return
}
playIfNeeded(uiView, coordinator: context.coordinator)
}
private func playIfNeeded(_ view: LottieAnimationView, coordinator: Coordinator) {
if loopMode == .playOnce {
guard !coordinator.didPlayOnce else { return }
coordinator.didPlayOnce = true
view.play()
return
}
if !view.isAnimationPlaying {
view.play()
}
}
}