We will entertain your mind, enhance your brain, expand your lifestyle.

Mysterious behavior of TimelineView

Periodee uses a SwiftUI View called TimelineView on the elapsed time display screen. This updates the containing View at the specified interval. The elapsed time display is specified to be updated in units of one minute.

struct TimeKeepingView: View {
	@EnvironmentObject var myModel: SessionModel
	@Binding var session: Session
	var today:String
	var testingCurrentTime:String = ""

	var body: some View {
		//TimelineView(.everyMinute) { context in
		//TimelineView(EveryMinuteTimelineSchedule()) { context in
		TimelineView(.periodic(from: appStartDate, by: 60.0)) { context in
			GeometryReader { geometry in
				let gw = geometry.size.width
				let gh = geometry.size.height					
				ZStack {
					let cx = gw / 2
					let cy = gh / 2
					session.SetCurrentTime_Period(withTimeCode: context.date)

Within the TimelineView, it is necessary to use the date stored in the argument context, but this context.date is wrong.

TimelineView is updated multiple times when the app is launched or when the elapsed time screen is redisplayed by switching sessions, but at a certain timing, the time in context.date shifts by a few minutes at intervals of less than 1 second. . And suddenly it’s back to the right time.

The above behavior was exposed by incorporating Haptic notification as a new function. Moreover, it does not occur in the simulator, and it does not occur unless it is on the Apple Watch.

We tried changing the TimelineView specification method, but there was no effect and we are continuing to investigate.