carekit-apple / CareKit

CareKit is an open source software framework for creating apps that help people better understand and manage their health.
https://www.researchandcare.org
Other
2.4k stars 443 forks source link

listViewController is not showing CareCards on some dates #514

Open igoreydman opened 3 years ago

igoreydman commented 3 years ago

I'm having issues where CareCard data isn't showing on some days where it should have data and saw that the date in the dailyPageViewController override sometimes has the wrong date. However, it is showing the correct calendar date. I'm unable to replicate the blank screens I'm getting, but I was able to demonstrate the incorrect date.

To replicate using OCKSample I printed out the date in CareViewController.swift

override func dailyPageViewController(_ dailyPageViewController: OCKDailyPageViewController,
                                          prepare listViewController: OCKListViewController, for date: Date) {
print("\nfor date: \(date)\nDate() = \(Date())\n")

}

The printed day is incorrect when swiping forward (tomorrow's date) or backward (yesterday). Swiping to yesterday prints yesterday then immediately prints tomorrows date. Swiping another day back shows the correct date. Swiping again prints twice again with the wrong date.

Tapping the date in the calendar has the correct date, but swiping repeats the issue.

Is the date variable the visible date on the dailyPageViewController? Also, in the project I'm working on the cards are not shown and the view is blank when swiping to yesterday. I wasn't able to replicate this but the data is filled when swiping 3 days into the past and returning to yesterday.

erik-apple commented 3 years ago

If I understand your explanation correctly, then what you are seeing is expected behavior for UIPageViewController is iOS. Under the hood, UIPageViewController will often attempt to pre-load adjacent pages so that it has 2-3 pages ready in memory to be displayed when the user swipes between pages. You shouldn't assume that that method will only be triggered for the currently displayed date.

OCKDailyPageViewController has a selectedDate property you can check to determine the date that's presently being shown. That is the correct route for getting the current date.

For the issue with cards not appearing, check that the effectiveDate of your tasks is greater than the selected date. If you're using the code in the sample app as a starting point, then CareKit will not display cards when you're viewing a date before your tasks were created. If you want the tasks to be visible far into the past, you need to create them with a schedule that extends backwards in time.