Hi, everyone. I'm trying my first TimelineView
with an explicit schedule, but my attempt – and even the simple example from the documentation – doesn't seem to work as documented. Here's what the documentation says an explicit schedule does:
The timeline view updates its content on exactly the dates that you specify, until it runs out of dates, after which it stops changing.
And it gives this example:
let dates = [
Date(timeIntervalSinceNow: 10), // Update ten seconds from now,
Date(timeIntervalSinceNow: 12), // and a few seconds later.
]
struct MyView: View {
var body: some View {
TimelineView(.explicit(dates)) { context in
Text(context.date.description)
}
}
}
There are stipulations about what the view – which always displays some version of its content body – will do given only past or future dates, but it seems clear we should expect the view in this example to redraw at least once after it appears.
Here's the rest of the discussion from the documentation with my comments after testing what's stated:
If the dates you provide are in the past, the timeline view updates exactly once with the last entry.
That seems true, considering the "update" to be the initial draw.
If you only provide dates in the future, the timeline view renders with the current date until the first date arrives.
Not exactly: it looks the "date" property of the initial render is the (future) date of the first schedule entry, even though it's drawn early. When the first date does arrive, the body closure doesn't seem to be called. Only on the next date, if there is one, is it called again.
If you provide one or more dates in the past and one or more in the future, the view renders the most recent past date, refreshing normally on all subsequent dates.
That also seems correct, except…
… that in every scenario, the final date entry seems to be ignored completely! In other words, unless all date entries are in the past, the Timeline View stops before it runs out of dates. That documented example from the start, which we expect to redraw at least once after it appears? When I test it in a Playground, it appears, but doesn't redraw at all!
So, that's my main point of confusion after experimenting with TimelineView for the first time. I can achieve my own goal by appending an extra entry to my explicit schedule – even appending an entry identical to the previous "final" entry seems to work – but naturally that leaves me unclear about why I need to.
If anyone can tell me what I'm not understanding, I'd be grateful.