From 17c627d701f91ded3b02a975a9f63abae50ce1e6 Mon Sep 17 00:00:00 2001 From: Alexander Boriskov Date: Mon, 27 Jan 2020 19:32:04 +0300 Subject: [PATCH] [iOS] Fixed crash in UISearchBar style --- .../Maps/Core/Theme/Core/StyleManager.swift | 2 ++ iphone/Maps/Core/Theme/GlobalStyleSheet.swift | 2 +- .../Theme/Renderers/UISearchBarRenderer.swift | 28 +++++++++++-------- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/iphone/Maps/Core/Theme/Core/StyleManager.swift b/iphone/Maps/Core/Theme/Core/StyleManager.swift index 1511f9d61a..950ac859fd 100644 --- a/iphone/Maps/Core/Theme/Core/StyleManager.swift +++ b/iphone/Maps/Core/Theme/Core/StyleManager.swift @@ -36,6 +36,8 @@ listener.applyTheme() } } + + UISearchBarRenderer.setAppearance() } private func updateView(_ view: UIView?) { diff --git a/iphone/Maps/Core/Theme/GlobalStyleSheet.swift b/iphone/Maps/Core/Theme/GlobalStyleSheet.swift index ad77f53161..78cb3e004f 100644 --- a/iphone/Maps/Core/Theme/GlobalStyleSheet.swift +++ b/iphone/Maps/Core/Theme/GlobalStyleSheet.swift @@ -31,7 +31,7 @@ class GlobalStyleSheet: IStyleSheet { theme.add(styleName: "SearchBar") { (s) -> (Void) in s.backgroundColor = colors.white s.barTintColor = colors.primary - s.tintColor = colors.blackPrimaryText + s.tintColor = UIColor.white s.fontColor = colors.blackSecondaryText } diff --git a/iphone/Maps/Core/Theme/Renderers/UISearchBarRenderer.swift b/iphone/Maps/Core/Theme/Renderers/UISearchBarRenderer.swift index 97fb7d5ac8..c24b5a89ae 100644 --- a/iphone/Maps/Core/Theme/Renderers/UISearchBarRenderer.swift +++ b/iphone/Maps/Core/Theme/Renderers/UISearchBarRenderer.swift @@ -13,23 +13,29 @@ extension UISearchBar { class UISearchBarRenderer: UIViewRenderer { class func render(_ control: UISearchBar, style: Style) { super.render(control, style: style) - if let backgroundColor = style.backgroundColor { - control.searchTextField.backgroundColor = backgroundColor - } if let barTintColor = style.barTintColor { control.barTintColor = barTintColor } if let tintColor = style.tintColor { control.tintColor = tintColor - if let image = control.searchTextField.leftView as? UIImageView { - image.tintColor = tintColor + } + } + + //fix for iOS 12 and below + class func setAppearance() { + for style in StyleManager.shared.getStyle("SearchBar") { + if let backgroundColor = style.backgroundColor { + UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).backgroundColor = backgroundColor + } + if let tintColor = style.tintColor { + UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).leftView?.tintColor = tintColor + } + if let font = style.font { + UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).font = font + } + if let fontColor = style.fontColor { + UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).textColor = fontColor } - } - if let font = style.font { - control.searchTextField.font = font - } - if let fontColor = style.fontColor { - control.searchTextField.textColor = fontColor } } }