I introduced lottie to toggle in my widget to show a transition animation, but found that the.json file wouldn't load. The loading_hc.json file is validated and exists in the widget target. Ask for help, thank you!
struct LottieView: UIViewRepresentable {
let animationName: String
func makeUIView(context: Context) -> LOTAnimationView {
let lotAnimationView = LOTAnimationView(name: animationName, bundle: .main)
lotAnimationView.contentMode = .scaleAspectFit
lotAnimationView.play()
return lotAnimationView
}
func updateUIView(_ uiView: LOTAnimationView, context: Context) {
}
func makeCoordinator() -> Coordinator {
Coordinator()
}
}
struct ControlToggleDisarmingStyle: ToggleStyle {
func makeBody(configuration: Configuration) -> some View {
if configuration.isOn {
LottieView(animationName: "loading_hc.json").foregroundColor(.clear).frame(width: 24,height: 24)
} else {
Image("icon_disarm", bundle: Bundle.main).foregroundColor(.clear)
}
}
}
UIViewRepresentable is not recommended to try and use with WidgetKit. Native SwiftUI views are required to ensure quick archiving and loading of the views for your Widget. It looks like you are trying to load something that animates as well. Please note, such custom animations are also not supported. You can use system animation transitions, countdown timers, progress bars and such that are supported in SwiftUI but not custom elements.