Skip to content

Instantly share code, notes, and snippets.

@lvjian700
Created February 25, 2024 10:34
Show Gist options
  • Save lvjian700/2baeb7d56d55efc86b7b71f7cf65ae87 to your computer and use it in GitHub Desktop.
Save lvjian700/2baeb7d56d55efc86b7b71f7cf65ae87 to your computer and use it in GitHub Desktop.
Showing iMessage like loading 3 dots animation.
import SwiftUI
struct MessageLoadingView: View {
@State private var animate = false
var body: some View {
HStack(spacing: 5) {
ForEach(0..<3, id: \.self) { index in
Circle()
.frame(width: 8, height: 8)
.foregroundColor(.gray)
.scaleEffect(animate ? 1 : 0.5)
.animation(
Animation.linear(duration: 0.6)
.repeatForever(autoreverses: true)
.delay(0.2 * Double(index))
, value: animate
)
}
}
.onAppear {
animate = true
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment