Change how next and previous articles are selected so that animation timings can't impact them. Issue #1707

This commit is contained in:
Maurice Parker 2020-01-26 14:21:04 -07:00
parent 5f5724388b
commit 4a63b28c73
2 changed files with 20 additions and 2 deletions

View File

@ -268,14 +268,18 @@ extension ArticleViewController: WebViewControllerDelegate {
extension ArticleViewController: UIPageViewControllerDataSource {
func pageViewController(_ pageViewController: UIPageViewController, viewControllerBefore viewController: UIViewController) -> UIViewController? {
guard let article = coordinator.prevArticle else {
guard let webViewController = viewController as? WebViewController,
let currentArticle = webViewController.article,
let article = coordinator.findPrevArticle(currentArticle) else {
return nil
}
return createWebViewController(article)
}
func pageViewController(_ pageViewController: UIPageViewController, viewControllerAfter viewController: UIViewController) -> UIViewController? {
guard let article = coordinator.nextArticle else {
guard let webViewController = viewController as? WebViewController,
let currentArticle = webViewController.article,
let article = coordinator.findNextArticle(currentArticle) else {
return nil
}
return createWebViewController(article)

View File

@ -825,6 +825,20 @@ class SceneCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
}
func findPrevArticle(_ article: Article) -> Article? {
guard let index = articles.firstIndex(of: article), index > 0 else {
return nil
}
return articles[index - 1]
}
func findNextArticle(_ article: Article) -> Article? {
guard let index = articles.firstIndex(of: article), index + 1 != articles.count else {
return nil
}
return articles[index + 1]
}
func selectPrevArticle() {
if let article = prevArticle {
selectArticle(article)