TypingAnimationSwiftUI
Typewriter animation for SwiftUI Text, with customizable settings
Install / Use
/learn @sndwvv/TypingAnimationSwiftUIREADME
TypingAnimationSwiftUI
Add a typewriter style of animation to a SwiftUI Text, with customizable settings (typing speed, backspacing, haptic feedback).
Previews
https://github.com/sndwvv/TypingAnimationSwiftUI/assets/108448821/1281e058-eb13-4744-901a-f5078490f1a2
https://github.com/sndwvv/TypingAnimationSwiftUI/assets/108448821/82088ac6-cd0b-45f5-a9ae-809fdab4e2f3
Implementation
Simply initialize the TypingTextView with a text string:
TypingTextView(text: "Hello, World!")
Adjust settings as needed. Make use of the completion block to do something after the animation is complete.
let fullText = "Hello, World!"
let settings = TypingTextSettings(
typingSpeed: 0.04,
backspaceSpeed: 0.01,
delaySeconds: 1.0,
isBackspaceEnabled: false,
isHapticsEnabled: false
)
var body: some View {
VStack {
TypingTextView(
text: fullText,
settings: settings
) {
// animation complete
}
.font(.system(size: 12, weight: .heavy))
.foregroundColor(.primary)
}
}
| TypingTextSetting | Description | | ------------- | ------------- | | typingSpeed | Adjusts typing speed | | backspaceSpeed | Adjust backspacing / reverse typing speed | | delaySeconds | Adds a delay after backspacing is complete | | style | TypingTextStyle: add styling using one of the pre-made ViewModifiers | | isBackspaceEnabled | If true, text is fully typed then backspaced / removed | | isHapticsEnabled | Adds a haptic feedback every time a character is added or removed |
Pass an array of texts and have it loop continuously (refer to LoopingTextExample.swift)
struct LoopingTextExampleView: View {
let texts = Constants.quotes
let settings = TypingTextSettings(
typingSpeed: 0.04,
backspaceSpeed: 0.01,
delaySeconds: 1.0,
style: .medium,
isBackspaceEnabled: true,
isHapticsEnabled: true
)
@State private var currentTypingIndex = 0
var body: some View {
VStack {
TypingTextView(
text: texts[currentTypingIndex % texts.count],
settings: settings) {
// Go to next text when the animation finishes
currentTypingIndex += 1
}
.id(currentTypingIndex)
.frame(maxWidth: .infinity, maxHeight: .infinity)
.padding(.horizontal)
}
}
}
Styling
Add modifiers to the end as usual:
TypingTextView(text: "Hello World")
.foregroundColor(.brown)
.font(.system(size: 20, weight: .bold))
Or create your own modifier and add to the settings as the TypingTextStyle:
enum TypingTextStyle {
case plain
case medium
// add more
func modifier() -> some ViewModifier {
switch self {
case .medium:
return AnyViewModifier(MediumTypingTextStyle())
default:
return AnyViewModifier(EmptyModifier())
}
}
}
Upcoming
- macOS compatibitlity
Related Skills
node-connect
335.4kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
82.5kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
335.4kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
commit-push-pr
82.5kCommit, push, and open a PR
