Note 19-mar-2020: In the meantime, I went much deeper into the question how a scrollable tab view with animations can be realized using pure SwiftUI. I came up with a solution that is published on GitHub.

While the solution described in my previous article is working pretty well for the displayed tabs, it has a problem when the “More…” tab is used and a view controller from there is selected. In this case, the didSelect delegate function will not be called.

I’ll describe here a modification to the above solution that is also able to handle that situation.

ViewControllers instead of TabItems

First, we modify the IRTabBar so that it gets the required view controllers directly, instead of providing the tab bar items:

  1. This is what we had, we’re replacing that with
  2. this declaration.

As a consequence, we have to modify our makeUIViewController function so that it just takes the new property value, instead of creating the list of view controllers:

Next, we have to change the didSelect delegate function in our Coordinatoras well:

Here, we did two things:

  • First, we have to get the index for given view controller, in order to set the selectedIndex property accordingly.
  • Second, we have to check if the “More…” tab was selected. In this case, UIKit will deliver us a UINavigationController and a UITableViewController . We need to react on a table view event, so we set a delegate if necessary. this requires another property for the Coordinator.

Now, we have to add the handling of the table view events:

Because we do not know how many tab bar items are really shown on the device, we have to find it our indirectly but just taking the overall count of the available view controllers, and the number of entries just shown in the table view. The difference is to be added to the index path’s row count in order to get the selectedIndex value.

Adopting model and view

Obviously, we have to slighly modify the model and view in order to not provide items, but view controllers.

First, the MainSceneModel :

We replace the previous items property (1) with a lazy one for the view controllers (2).

Second, the MainSceneView :

Conclusion

With these modifications, you are able to react even on events of the “More…” action, in a SwiftUI setup.

I provided the sources on Github.

The Startup

Get smarter at building your thing. Join The Startup’s +794K followers.

Sign up for Top 10 Stories

By The Startup

Get smarter at building your thing. Subscribe to receive The Startup's top 10 most read stories — delivered straight into your inbox, once a week. Take a look.

By signing up, you will create a Medium account if you don’t already have one. Review our Privacy Policy for more information about our privacy practices.

Check your inbox
Medium sent you an email at to complete your subscription.

Gerhard Schneider

Written by

Helping companies and humans to evolve, and trying to be agile in an own product development.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +794K followers.

Gerhard Schneider

Written by

Helping companies and humans to evolve, and trying to be agile in an own product development.

The Startup

Get smarter at building your thing. Follow to join The Startup’s +8 million monthly readers & +794K followers.

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store