Post

Replies

Boosts

Views

Activity

Reply to My widgets appear with a Placeholder view in the Widget Gallery
When I actually add the widget to the homescreen, the widget displays properly. From the documentation, snapshot appears to be what is used for the Widget Gallery view: WidgetKit calls snapshot(for:with:completion:) when the widget appears in transient situations. If context.isPreview is true, the widget appears in the widget gallery. Regardless, I am passing entries in the timeline - below is my code. I'm only providing one timeline entry since I want to refresh the data every 15 minute increments. (This is an agenda widget, so I want to load any new calendar events, etc). I set the entry date for the 15 minute mark so it refreshes roughly every 15 minutes. I also tried passing two entries: one for Date(), and one with the Refresh date below, and I still see the same issue. var entries: [SimpleEntry] = [] let refreshDate = DateHelper.shared.nextWidgetRefreshDate(frequency: 15) let agendaViewModel = AgendaViewModel() agendaViewModel.getData(hidePastEvents: true) { let agendaItemsByDate = Array(agendaViewModel.agendaItemsByDate.prefix(2)) let entry = SimpleEntry(date: refreshDate, agendaItemsByDate: agendaItemsByDate) entries.append(entry) let timeline = Timeline(entries: entries, policy: .atEnd) completion(timeline) }
Aug ’20
Reply to onAppear is called when the view hasn't appeared
Further information This only appears on actual devices, in the simulator, the issue does not appear. The issue only appears with projects created with the SwiftUI App Life Cycle. The issue does not appear in projects with the UI Kit App Delegate Life Cycle projects. I submitted a feedback: FB8285799 You can recreate this issue by creating a new project, choosing SwiftUI App from the Life Cycle dropdown, and replacing your ContentView with the following code. If anyone has any thoughts on a workaround I'd appreciate it! import SwiftUI struct ContentView: View { 		var body: some View { TabView { AgendaView() .tabItem { Image(systemName: "list.bullet") Text("Agenda") } HealthView() .tabItem { Image(systemName: "heart") Text("Health") } SettingsView() .tabItem { Image(systemName: "gear") Text("Settings") } } 		} } struct AgendaView: View { var body: some View { VStack { Text("Hello, AgendaView!") }.onAppear{ print("AgendaView.onAppear") }.onDisappear(){ print("AgendaView.onDisappear") } } } struct HealthView: View { var body: some View { VStack { Text("Hello, HealthView!") }.onAppear{ print("HealthView.onAppear") }.onDisappear(){ print("HealthView.onDisappear") } } } struct SettingsView: View { var body: some View { VStack { Text("Hello, SettingsView!") }.onAppear{ print("SettingsView.onAppear") }.onDisappear(){ print("SettingsView.onDisappear") } } }
Aug ’20