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

Highlight and sizing issues with action button (“hijack” item) #198

Closed zygoat closed 1 year ago

zygoat commented 5 years ago

In implementing an action-style (button) item in my tab bar, I've observed a couple of problems with size and user interaction that I've had to work around in a subclass:

  1. the button does not indicate a highlight state during touch down.
  2. the icon is drawn at the default tab bar item size, rather than the icon's natural size.

These problems are corrected with the following subclass:

class LargeTabBarContentView: ESTabBarItemContentView {
    override func highlightAnimation(animated: Bool, completion: (() -> Void)?) {
        imageView.tintColor = highlightIconColor
        completion?()
    }

    override func dehighlightAnimation(animated: Bool, completion: (() -> Void)?) {
        imageView.tintColor = iconColor
        completion?()
    }

    override func updateLayout() {
        super.updateLayout()
        imageView.sizeToFit()
        imageView.center = center
    }
}

The lack of highlighting seems to be an obvious bug.

The lack of natural button resizing would be better controlled through a flag (e.g. sizeToFitIcon or such) rather than need a layout override.

eggswift commented 5 years ago

Set BasicTabBarItemContentView's renderingMode propertie to alwaysOriginal. You can see the surprise~

zygoat commented 5 years ago

Can you elaborate? I presume you mean ESTabBarItemContentView (there is no such class as BasicTabBarItemContentView). Even so, setting renderingMode = .alwaysOriginal seems to have no such effect—the icon is still drawn small, and is receives no highlight colour.