To create a custom animation, implement the ATTextAnimateEffect protocol. This protocol inherits from ViewModifier, allowing you to apply animations to the individual text elements (characters, words, etc.) generated by the library.
Your implementation must include:
data: An ATElementData object containing the element's index and value.userInfo: An optional Any? object for custom state.- An initializer:
init(_ data: ATElementData, _ userInfo: Any?). - The
body(content:) method: Where you define the actual SwiftUI animation logic applied to the content.
/// Custom animation effect.
public struct CustomEffect: ATTextAnimateEffect {
public var data: ATElementData
public var userInfo: Any?
public init(_ data: ATElementData, _ userInfo: Any?) {
self.data = data
self.userInfo = userInfo
}
public func body(content: Content) -> some View {
content
.opacity(data.value)
.animation(.easeInOut.delay(Double(data.index) * 0.06), value: data.value)
}
}