Change how next and previous articles are selected so that animation timings can't impact them. Issue #1707
This commit is contained in:
parent
5f5724388b
commit
4a63b28c73
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue