onl1ner / TabBar

📱 TabBar – highly customizable tab bar (i.e. TabView) for your SwiftUI application.
MIT License
421 stars 45 forks source link

Unable to dynamically change the tabItem icon when tab is selected #13

Closed tedLHMstr closed 1 year ago

tedLHMstr commented 1 year ago

Is there a way of changing the icon name with respect to the selection state variable? Example: When "Home" tab is selected, I want to use SF-icon "house.fill", otherwise "house".

onl1ner commented 1 year ago

Hello, @tedLHMstr!

Yes, you can change the style of your TabItem with the respect to the selection, there is a isSelected: Bool parameter that is passed to your implementation of TabItemStyle protocol.

Hope it helps :)

tedLHMstr commented 1 year ago

Thank you for your answer @onl1ner!

Do you propose something like this: Image(systemName: isSelected ? "\(icon).fill" : icon)

What I was referring to was to control it in the "Item"-enum, which would be suitable since you sometimes want to display a totally different icon :)

onl1ner commented 1 year ago

I see, that's a good idea to add another function to the TabItemStyle protocol where you will be able to obtain an Item-type parameter.

Will give it a look in my free time, but if you can implement it, PR would be appreciated :)

Leaving this issue opened till the feature is implemented

onl1ner commented 1 year ago

Hello, @tedLHMstr!

You can now provide a selected icon name using selectedIcon parameter in the entity that conforms to Tabbable protocol, then you could use this parameter in the function tabItem(icon:selectedIcon:title:isSelected:) of TabItemStyle protocol.

Make sure that you have updated library to 1.3.0 version. If you will have a problem feel free to reopen this issue