Fix chat send button behavior
This commit is contained in:
@@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user