Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Created November 3, 2024 04:08
Show Gist options
  • Save amosgyamfi/5d970a26fae011be158f825a1aac3612 to your computer and use it in GitHub Desktop.
Save amosgyamfi/5d970a26fae011be158f825a1aac3612 to your computer and use it in GitHub Desktop.
//
// Thinking2.swift
// CoreSwiftUI
//
import SwiftUI
struct ThinkingWithAlex: View {
@State private var currentPhraseIndex = 0
private let timer = Timer.publish(every: 5, on: .main, in: .common).autoconnect()
@State private var thinking = true
private static let phrases = [
"Thinking ",
"Weighing Options ",
"Evaluating Sentence"
]
var body: some View {
HStack {
Spacer()
animatedSparklesIcon
Spacer()
animatedPhrase
Spacer()
}
.padding(.horizontal, 90)
.onReceive(timer) { _ in
withAnimation {
currentPhraseIndex = (currentPhraseIndex + 1) % Self.phrases.count
}
}
}
private var animatedSparklesIcon: some View {
Image(systemName: "sparkles")
.font(.title)
.foregroundStyle(EllipticalGradient(colors: [.blue, .indigo], center: .center, startRadiusFraction: 0.0, endRadiusFraction: 0.5))
.phaseAnimator([false, true]) { content, phase in
content
.symbolEffect(.wiggle.byLayer, options: .repeat(3), value: phase)
.symbolEffect(.bounce.byLayer, options: .repeat(3), value: phase)
.symbolEffect(.pulse.byLayer, options: .repeat(3), value: phase)
//.symbolEffect(.breathe.byLayer, options: .repeat(3), value: phase)
}
}
private var animatedPhrase: some View {
HStack(spacing: 0) {
ForEach(Array(Self.phrases[currentPhraseIndex].enumerated()), id: \.offset) { index, letter in
Text(String(letter))
.foregroundStyle(.blue)
.hueRotation(.degrees(thinking ? 220 : 0))
.opacity(thinking ? 1 : 0)
.scaleEffect(thinking ? 1 : 0.5, anchor: .bottom)
.animation(
.easeInOut(duration: 0.5)
.repeatForever(autoreverses: true)
.delay(Double(index) * 0.05),
value: thinking
)
}
}
}
}
#Preview {
ThinkingWithAlex()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment