From d541cfbf02588ebee9e27ec094b88a6e1ec53811 Mon Sep 17 00:00:00 2001 From: Yannik Bloscheck Date: Thu, 4 Sep 2025 13:11:53 +0200 Subject: [PATCH] [ios] Fix search bar background for iOS 26 Signed-off-by: Yannik Bloscheck --- .../Theme/Renderers/UISearchBarRenderer.swift | 49 +++---------------- 1 file changed, 8 insertions(+), 41 deletions(-) diff --git a/iphone/Maps/Core/Theme/Renderers/UISearchBarRenderer.swift b/iphone/Maps/Core/Theme/Renderers/UISearchBarRenderer.swift index 1cd18d3ce..ab41df47e 100644 --- a/iphone/Maps/Core/Theme/Renderers/UISearchBarRenderer.swift +++ b/iphone/Maps/Core/Theme/Renderers/UISearchBarRenderer.swift @@ -1,6 +1,10 @@ import Foundation extension UISearchBar { @objc override func applyTheme() { + if #available(iOS 26, *) { + return; + } + if styleName.isEmpty { setStyle(.searchBar) } @@ -25,6 +29,10 @@ class UISearchBarRenderer: UIViewRenderer { class func render(_ control: UISearchBar, style: Style) { super.render(control, style: style) + if #available(iOS 26, *) { + return; + } + let searchTextField = control.searchTextField // Default search bar implementation adds the grey transparent image for background. This code removes it and updates the corner radius. This is not working on iPad designed for mac. if !ProcessInfo.processInfo.isiOSAppOnMac { @@ -65,24 +73,6 @@ class UISearchBarRenderer: UIViewRenderer { } } - //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 font = style.font { - UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).font = font - } - if let fontColor = style.fontColor { - UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).defaultTextAttributes = [.foregroundColor: fontColor] - UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).textColor = fontColor - UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).leftView?.tintColor = fontColor - UITextField.appearance(whenContainedInInstancesOf: [UISearchBar.self]).tintColor = fontColor - } - } - } - @available(iOS, deprecated: 13.0) private static let kiOS12DefaultSystemTextFieldHeight = 36 @@ -91,27 +81,4 @@ class UISearchBarRenderer: UIViewRenderer { @available(iOS, deprecated: 13.0) private static var searchBarBackgroundImage: UIImage? - - // Draws the background image for the UITextField using the default system's text field height. - // This approach is used only for iOS 12. - @available(iOS, deprecated: 13.0) - private static func getSearchBarBackgroundImage(color: UIColor) -> UIImage? { - if color != searchBarBackgroundColor { - let size = CGSize(width: kiOS12DefaultSystemTextFieldHeight, height: kiOS12DefaultSystemTextFieldHeight) - UIGraphicsBeginImageContextWithOptions(size, false, 0.0) - guard let context = UIGraphicsGetCurrentContext() else { return nil } - let rect = CGRect(origin: .zero, size: size) - let cornerRadius = CGFloat(8) - let path = UIBezierPath(roundedRect: rect, byRoundingCorners: [.topLeft, .topRight, .bottomLeft, .bottomRight], cornerRadii: CGSize(width: cornerRadius, height: cornerRadius)) - context.addPath(path.cgPath) - context.setFillColor(color.cgColor) - context.fillPath() - let image = UIGraphicsGetImageFromCurrentImageContext() - UIGraphicsEndImageContext() - searchBarBackgroundImage = image - searchBarBackgroundColor = color - return image - } - return searchBarBackgroundImage - } }