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)
}
}
}
Post
Replies
Boosts
Views
Activity
I use AppIntent to trigger a widget refresh, Appint is used on Button or Toggle,as follows
var isAudibleArming = false
struct SoundAlarmIntent: AppIntent {
static var title: LocalizedStringResource = "SoundAlarmIntent"
func perform() async throws -> some IntentResult {
isAudibleArming = true
return .result()
}
}
func timeline( for configuration: DynamicIntentWidgetPersonIntent, in context: Context ) async -> Timeline {
var entries: [Entry] = []
let currentDate = Date()
let entry = Entry(person: person(for: configuration))
entries.append(entry)
if isAudibleArming {
let entry2 = Entry(person: Person(name: "Friend4", dateOfBirth: currentDate.adding(.second, value: 6)))
entries.append(entry2)
}
return .init(entries: entries, policy: .never)
}
The timeline function fires, with entry corresponding to view1 and entry2 corresponding to view2. I expect to show view1 immediately and view2 6 seconds later. You get the correct response on iOS17. But the 6 second delay function on the discovery code in iOS18.2 takes effect immediately, view1 flashes, view2 appears immediately instead of waiting 6 seconds to appear.