Git Product home page Git Product logo

Comments (3)

msaps avatar msaps commented on June 9, 2024

Hi @AndresCianio

The way that PageboyViewControllerDataSource currently works doesn't make this sort of thing simple, but it is possible.. By calling reloadPages you can refresh the entire data source, calling viewControllers(forPageboyViewController:) and defaultPageIndex(forPageboyViewController) again.

In theory, you could handle this removal/addition behaviour by keeping a list of all view controllers in your PageboyViewController subclass and returning a subset of this list in viewControllers(forPageboyViewController:) according to your current state.

I do think that this is an interesting use-case, I'll raise it as an enhancement and see if I can provide support for this in a better way.

from pageboy.

andres-cianio avatar andres-cianio commented on June 9, 2024

Hi @msaps ! Thanks a lot for the super quick answer!! I really appreciate it!
I just managed to get it working :D and I think I mostly did the same you are suggesting.

Playing around with the demo I ended up making the following changes (in case you want to try it out, or somebody ends up here at some point):

  1. define a method addPage() in the PageVC. Virtually this method would add a new controller to an array of pages, but here I just increment numberOfPages by one (made it var) and then call reloadPages().
  2. add a button in ChildVC and a 'myDelegate' reference to the PageVC. When the button is tapped I call myDelegate.addPage
  3. when creating each controller, set the myDelegate reference to self.
  4. in func defaultPageIndex(forPageboyViewController pageboyViewController: PageboyViewController) -> PageboyViewController.PageIndex? instead of just returning nil, if the currentIndex is defined, I return PageIndex.atIndex(index: currentIndex); otherwise keep returning nil.

I'd tweak the whole solution to my specifics (ie an array of pages instead of creating them), but I think this works perfectly, and love your lib!

What do you think?

from pageboy.

andres-cianio avatar andres-cianio commented on June 9, 2024

It is working as expected with the explanation above... Closing 😃

from pageboy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.