I'm developing a widget with WidgetKit, and I'm having a problem: I need to click on an image, and when I click it triggers a network request, the image automatically rotates clockwise, and when the network ends, the image automatically stops rotating. How to do that?
My current idea is to click on the image and await the call to the network request. Should Toggle be used for the control corresponding to the picture? Because Toggle has two states. Then there is how to do image rotation, did not find support API.
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
struct DeployAndWithdrawDefensesAppIntent: WidgetConfigurationIntent {
// An example configurable parameter.
@Parameter(title:LocalizedStringResource("ax_alarm_device_name"))
}
In the process of using iOS widgetKit development team a, configuration item title need language internationalization (@ Parameter (title: LocalizedStringResource (" ax_alarm_device_name "))),
but found no effect. I first changed the language of the system on the iphone and found that the widget worked. However, just changing the language of the app did not take effect. Is there any way to just change the app language and make the widgets change? Thank you very much!
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)
}
}
}
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.