uias / Pageboy

📖 A simple, highly informative page view controller
MIT License
1.99k stars 154 forks source link

Incorrect behaviour when calling insertPage at currentIndex #211

Closed crehbichler closed 4 years ago

crehbichler commented 5 years ago

Hi,

so, let's say we have a PageboyViewController that is set up with 1 page. Then I am updating my input for the PageboyViewControllerDataSource and calling insertPage(at: 0, then: .doNothing).

What I would expect is that the new page will be inserted right before my current ViewController but I'm staying at the current ViewController, because I've specified .doNothing as PageUpdateBehavior.

What happens is that the new page is indeed inserted before my current ViewController, but also it "cross-dissolves" to the inserted ViewController.

I see that this is implemented in the func performUpdates when it's checked if newIndex == currentIndex and then the crossDissolve + updateViewControllers is done. I guess that totally makes sense for deleting the page at the currentIndex, but I'm not sure if this is the desired behaviour for inserting?

Thanks in advance! (And thanks for building/improving this great library 👍 )


Version

Pageboy (3.2.0) (actually used with Tabman (2.3.0) but this should be just related to Pageboy)

msaps commented 5 years ago

@crehbichler 👍 sounds like something we should fix

zyflovelam commented 5 years ago

I met this problem too, It seems that it has not been resolved yet? version: 3.2 Swift: 4.2

jhmacdon commented 4 years ago

@msaps Is there any plan to fix this? Causes issues in one of my projects 😢

msaps commented 4 years ago

@jhmacdon sorry been really busy of late - will try and get time to work on it this week 👍

kristiyandobrev commented 4 years ago

@msaps

For now I am using the following workaround.

var dataSource = []
//......
let index = 0
dataSource.insert(viewController, at: index)
pageViewController.reloadData()
pageViewController.scrollToPage(.at(index: index+1), animated: false)

If adding something to the beginning of the data source, I am calling reloadData() which will reload the data source and then scrolling back to the current page without animation.

msaps commented 4 years ago

@kristiyandobrev @jhmacdon @zyflovelam @crehbichler this is now resolved as of v3.6.0 🎉