✨ Refactor Tab Bar to abstract styles away from functional logic
Summary
We allow users to select between Xcode and Native styled tabs. Currently we have our TabBar view written in such a way where tab style conditions are sprinkled throughout the functional tab logic. We should instead simplify this by abstracting styles away from functional tab logic so that we can easily switch out tab style. This will allow us to eventually create additional tab styles.
Description
Right now we just have two styles, Xcode-style tabs, and Native-style tabs, but we will likely offer more in the future. The goal here is to separate tab styling from logic so we can easily swap out different styles.
Currently, we have logic and styles tightly coupled along with many ternary statements littered throughout that look something like this...
prefs.preferences.general.tabBarStyle == .native ? ... : ...
Introducing yet another tab style would make this near-impossible to read.
This is why it is important that we separate concerns here so this can be more readable and maintainable.
Additional considerations
We may use a technique used in SwiftUI quite a bit. You can apply a .menuStyle modifier, passing in the style you'd like to apply to the Menu view for example, to get the menu look different.
Likewise, you also have the .buttonStyle modifier that can be applied to the Button view.
There is also .formStyle modifier that can be applied to the Form view that not only styles the form itself like .menuStyle and .buttonStyle, but also styles the controls within it.
For each of these three modifiers, there are a few styles that come default with SwiftUI, or you can create additional styles.
This article explains it all pretty well. I think we would want to replicate this behavior for our use-case.
Is this being worked on @austincondiff? 🙂 I was looking into the source code yesterday and thought this might be an interesting challenge to tackle, unless progress has been made since the PR was closed.
Kind of related to this: it has a very nice look and feel and could probably be made into a library, like the source editor etc. I haven't found a tabbar component for SwiftUI really. This would probably require it be made a bit more general probably so it's not as closely tied to the editor (at least the naming)? If it's of interest I can have a look at making it more general as well in preparation for moving it to another repo 👍
I don’t think it needs to be moved to another repo. We just need to make it style-able and separate the display logic from the functional logic a bit more.
Currently there is logic interspersed thought for Xcode styled tabs and native styled tabs. We need pull these out and add each as its own tab theme, making Xcode the default.