Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k 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 Reply

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...