     
     func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {
         delegate?.searchBarTextDidBeginEditing(searchBar)
+        buttonType = dataSource?.buttonType(for: button, currentButtonType: buttonType)
     }
     
     func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {
         delegate?.searchBarTextDidEndEditing(searchBar)
+        buttonType = dataSource?.buttonType(for: button, currentButtonType: buttonType)
     }
     
     func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {

    @IBOutlet weak var separatorView: UIView!
    @IBOutlet weak var searchBar: UISearchBar!
    @IBOutlet weak var button: UIButton!
    
    weak var dataSource: SearchBarExtendedViewControllerDataSource?
    weak var delegate: SearchBarExtendedViewControllerDelegate?

        searchBar.returnKeyType = dataSource?.returnKeyType(for: searchBar) ?? .search
        searchBar.placeholder = dataSource?.placeholder(for: searchBar)
        separatorView.isHidden = dataSource?.isSeparatorViewHidden(above: searchBar) ?? false
        buttonType = dataSource?.buttonType(for: button, currentButtonType: buttonType)
        apply(theme: theme)
    }

