From 32bc94322dc654cf0e89a2ed9f060717f096fb04 Mon Sep 17 00:00:00 2001 From: Nathan Mattes Date: Sun, 27 Nov 2022 22:05:20 +0100 Subject: [PATCH] Fix scrollview-offset-calculation (#690) --- .../Welcome/View/WelcomeIllustrationView.swift | 5 ++--- .../Welcome/WelcomeViewController.swift | 15 ++++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/Mastodon/Scene/Onboarding/Welcome/View/WelcomeIllustrationView.swift b/Mastodon/Scene/Onboarding/Welcome/View/WelcomeIllustrationView.swift index 7c153ea9a..317fead61 100644 --- a/Mastodon/Scene/Onboarding/Welcome/View/WelcomeIllustrationView.swift +++ b/Mastodon/Scene/Onboarding/Welcome/View/WelcomeIllustrationView.swift @@ -206,9 +206,8 @@ extension WelcomeIllustrationView { } } - func update(currentPage: WelcomeContentPage, contentOffset: CGFloat) { - // why does it jump back??? - print("\(contentOffset) — \(currentPage)") + func update(contentOffset: CGFloat) { //TODO: @zeitschlag update frames + print(Int(contentOffset)) } } diff --git a/Mastodon/Scene/Onboarding/Welcome/WelcomeViewController.swift b/Mastodon/Scene/Onboarding/Welcome/WelcomeViewController.swift index 1aeaa1770..3b5fa8f57 100644 --- a/Mastodon/Scene/Onboarding/Welcome/WelcomeViewController.swift +++ b/Mastodon/Scene/Onboarding/Welcome/WelcomeViewController.swift @@ -85,6 +85,7 @@ final class WelcomeViewController: UIViewController, NeedsDependency { return pageController }() var currentPage: WelcomeContentPage = .whatIsMastodon + var currentPageOffset = 0 } extension WelcomeViewController { @@ -405,8 +406,11 @@ extension WelcomeViewController: UIPageViewControllerDelegate { guard let currentViewController = pageViewController.viewControllers?.first as? WelcomeContentViewController else { return } currentPage = currentViewController.page - //FIXME: @zeitschlag fix -// welcomeIllustrationView.update(for: currentPage, contentOffset: 1000) + + if let pageIndex = WelcomeContentPage.allCases.firstIndex(of: currentPage) { + let offset = Int(pageIndex) * Int(pageViewController.view.frame.width) + currentPageOffset = offset + } } } @@ -455,8 +459,9 @@ extension WelcomeViewController: UIPageViewControllerDataSource { extension WelcomeViewController: UIScrollViewDelegate { func scrollViewDidScroll(_ scrollView: UIScrollView) { - print(scrollView.contentOffset.x) - //TODO: @zeitschlag sync view - welcomeIllustrationView.update(currentPage: currentPage, contentOffset: scrollView.contentOffset.x) + let weirdScrollViewJumpingCorrectionFactor = pageViewController.view.frame.width + let contentOffset = CGFloat(currentPageOffset) + scrollView.contentOffset.x - weirdScrollViewJumpingCorrectionFactor + + welcomeIllustrationView.update(contentOffset: contentOffset) } }