Lottie 3.1.0
You can set a AnimationTextProvider on AnimationView.textProvider
is there way too reload it without reloading whole animation?
Can you show an example of how to use dynamic texting by setting keypath and source text? Thank you so much!
class TextProvider: AnimationTextProvider {
let keypathName: String
let sourceText: String
init(keypathName: String, sourceText: String) {
self.keypathName = keypathName
self.sourceText = sourceText
}
// MARK: - AnimationTextProvider
func textFor(keypathName: String, sourceText: String) -> String {
guard keypathName == self.keypathName else { return sourceText }
return self.sourceText
}
}
animationView.textProvider = TextProvider(keypathName: "main_text", sourceText: "your text")
Text is cached and will be requested only once.
As far as I can say the only way to update it is to set animation again. (animationView.animation = ...)
Thank you for your example. Not sure if I understand it correctly, but you mean I can only edit the text layer once? if not, is there any way to edit two text layers of the Lottie Animation?
Thanks again!
you can edit as many layers as you want. Everything is handled by AnimationTextProvider protocol
Sorry for keep asking you... after setting the textProvider class, I add 4 lines to edit 4 different text layers:
animationView.textProvider = TextProvider(keypathName:name1 , sourceText: text1)
animationView.textProvider = TextProvider(keypathName:name2, sourceText: text2)
animationView.textProvider = TextProvider(keypathName:name3, sourceText: text3)
animationView.textProvider = TextProvider(keypathName:name4, sourceText: text4)
But during runtime only the fourth text layer changed. I think it is because I update textProvider 4 times. Curious: did I miss any function in order to change all the text layers?
Thank you so much again!
class TextProvider: AnimationTextProvider {
...
// MARK: - AnimationTextProvider
func textFor(keypathName: String, sourceText: String) -> String {
if name1 == keypathName {
return text1
}
else if name2 == keypathName {
return text2
}
else if name3 == keypathName {
return text3
}
else if name4 == keypathName {
return text4
}
return sourceTextelf.sourceText
}
}
Awesome it worked this time! Super appreciate your help!!