Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
837 views
in Technique[技术] by (71.8m points)

text - SwiftUI and WidgetKit - Automatically updating components

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.

question from:https://stackoverflow.com/questions/65898082/swiftui-and-widgetkit-automatically-updating-components

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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)")

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

2.1m questions

2.1m answers

60 comments

56.6k users

...