eggswift / ESTabBarController

:octocat: ESTabBarController is a Swift model for customize UI, badge and adding animation to tabbar items. Support lottie!
MIT License
5.17k stars 578 forks source link

ESTabBarItem loses info #289

Open hypermats opened 8 months ago

hypermats commented 8 months ago

With the changes from https://github.com/eggswift/ESTabBarController/commit/c454e0569ea0ff135c9d8926d09b222cc0658f7c#diff-5abb945dc5865b317e84e001627a243f52e8b34f819e833d954e39b062fa38a1

The init function was changed to directly set properties on the contentView. This is problematic because the properties cannot be read. In our app it causes issues as we use the item tag and all items have tag 0 instead of the value we set in the init.

Repro example:

let item = ESTabBarItem(
            BounceTabBarItem(),
            title: "My Tab",
            image: .imageAsset,
            selectedImage: .activeImageAsset,
            tag: 7
        )
 print(item.tag) //prints 0. 7 is expected
 print(item.contentView.tag) // prints 7

The fix should be to go back to setting the contentView properties as a result of calling the setters on ESTabBarItem.

(A different question is how on earth we didn't update this library until recently and discovered this bug from 2020)

rafaelfrancisco-dev commented 8 months ago

I'll try to look into it. Do you have any PR to fix this by any chance ?

hypermats commented 8 months ago

Hi @rafaelfrancisco-dev .

I think the easiest fix is to revert the change to the init function and bring back the open func setTitle(_ title: String? = nil, image: UIImage? = nil, selectedImage: UIImage? = nil, tag: Int = 0) { function

If the calls are made to set the title, image, selectedImage and tag on self they are propagated to the contentView in didSet.

I don't have a PR ready, but I can probably create one. Not until earliest in the new year though.