swift-cross-ui
swift-cross-ui copied to clipboard
[FEAT] TimelineView
https://developer.apple.com/documentation/SwiftUI/TimelineView
TLDR: A view redrawing periodically in specified intervals.
Possible nice additions:
- redraw on minute change ( 10:45 -> 10:46 instead of after 60 seconds where it could be anywhere in a minute)
- same for hours and days
- maybe a way to further filter updates ( e.g. only on XX:16, XX:31, XX:46, XX:01 instead of every full minute)
Implementation ideas:
- add observer in asWidget/create, depending on wether the Update source is backend or scui level (probably scui level, native support varies and is mostly lacking entirely)
- actor TimelineManager (name interchangeable)
- var observers: [TimeComponent: [() -> Void]]
- var timer: Timer?
- func addObserver(for: [TimeComponent], running block: ([DateComponent], Int/Double) -> Void)
- if timer is nil, create
- wrap block in function with early exit if it shouldn’t update on every change of a second, minute, hour or day
- add to observer dictionary
Notes:
- need to investigate if timer starts to wait after scope exit or is more fire and forget
- may need to cancel and rollback an update or drop triggers if updates take longer than the interval to the next trigger, may need to become irrelevant with fast enough layout engine