Skip to content

[Bug] When isInfiniteScrollEnabled, ViewController disappears intermittently. #265

@KYHyeon

Description

@KYHyeon

When isInfiniteScrollEnabled is true and the scroll direction changes on the last page, the view controller disappears intermittently.
This is easy to reproduce if you have two viewcontrollers.

Here is my code

import UIKit
import Pageboy

class ViewController: PageboyViewController {
    let firstVC: UIViewController = {
        let viewController = UIViewController()
        viewController.view.backgroundColor = .systemOrange
        return viewController
    }()
    
    let secondVC: UIViewController = {
        let viewController = UIViewController()
        viewController.view.backgroundColor = .systemPurple
        return viewController
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        self.dataSource = self
        self.isInfiniteScrollEnabled = true
    }
}

extension ViewController: PageboyViewControllerDataSource {
    func numberOfViewControllers(in pageboyViewController: PageboyViewController) -> Int {
        2
    }
    
    func viewController(for pageboyViewController: PageboyViewController, at index: PageboyViewController.PageIndex) -> UIViewController? {
        switch index {
        case 0:
            return firstVC
        case 1:
            return secondVC
        default:
            fatalError("unknown index!")
        }
    }
    
    func defaultPage(for pageboyViewController: PageboyViewController) -> PageboyViewController.Page? {
        .first
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions