I am working with WidgetKit and I found that the text component initialised with init(Date, style: Text.DateStyle)
is creating automatically updating texts. This is something special because iOS widgets usually require to set a timeline about when to update the view. Unfortunately scheduling these updates is in the hands of the operating system, bases on a limited budget and thus, is unreliable.
Do you know about other SwiftUI views, that are automatically updating (and might also be passively updating in a widget)? Animated shapes would also be nice to have.
I have already tried using publishing timers, which won't work in widgets.
According to Apple's documentation, the only self-updating SwiftUI view is Text
, configured to display a relative date or time. See Displaying Dynamic Dates in Widgets for details.
The options are:
Text(futureDate, style: .relative)
Text(futureDate, style: .offset)
Text(futureDate, style: .timer)
Text(aprilFirstDate, style: .date)
Text("Date: \(aprilFirstDate, style: .date)")
Text(startDate ... endDate)
Text("The meeting will take place: \(startDate ... endDate)")