rundfunk47 / stinsen

Coordinators in SwiftUI. Simple, powerful and elegant.
MIT License
905 stars 93 forks source link

TabView Functionality #56

Open ryangittings opened 2 years ago

ryangittings commented 2 years ago

Hey,

Firstly - thank you so much for the OS love, it's brilliant.

Secondly - I'm using a TabCoordinatable to power a TabView, but by doing so in SwiftUI you lose some default functionality like popping to the root on active tab tap, and scrolling to top on tab tap. As far as I'm aware there's no SwiftUI workaround, but there's a package that seems to do the trick:

https://github.com/NicholasBellucci/StatefulTabView

Cheers!

YuantongL commented 2 years ago

Hi, there are still work around - create a custom TabCoordinatable. There are some examples in this other thread where we talked about how to make a custom tabbar https://github.com/rundfunk47/stinsen/issues/42

Basically the idea is:

  1. Hide the system tabbar
  2. Make a class conform to TabCoordinatable
  3. Use func customize(_ view: AnyView) -> some View to use a view which you made yourself as a tab bar
  4. You then get full control of what needs to be displayed on the tab bar (because it's a SwiftUI View)
  5. You will be able to achieve anything (you got the button call back in coordinator now, you can pass it around)
ryangittings commented 2 years ago

Ah okay! I'm not 100% sure on this, but I'll see if I can hash something together.

Any idea how I'd get the stateful tab package above to work? I'd love to view some sample code or something, if some exists anywhere?

Thanks for all your help! 🙂

YuantongL commented 2 years ago

I don't have code example of the StatefulTabView, you could try use the func customize(_ view: AnyView) -> some View and implment the StatefulTabView there. Alternatively I think it is also possible to just not discard using of TabCoordinator since the StatefulTabView basically does the same thing, and use Stinsen in other places of the app.