mirror of
https://codeberg.org/comaps/comaps
synced 2025-12-20 05:13:58 +00:00
[ios] Fix search bar background for iOS 26
Signed-off-by: Yannik Bloscheck <git@yannikbloscheck.com>
This commit is contained in:
committed by
Yannik Bloscheck
parent
c310e3e3b1
commit
d541cfbf02
@@ -1,6 +1,10 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
extension UISearchBar {
|
extension UISearchBar {
|
||||||
@objc override func applyTheme() {
|
@objc override func applyTheme() {
|
||||||
|
if #available(iOS 26, *) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if styleName.isEmpty {
|
if styleName.isEmpty {
|
||||||
setStyle(.searchBar)
|
setStyle(.searchBar)
|
||||||
}
|
}
|
||||||
@@ -25,6 +29,10 @@ class UISearchBarRenderer: UIViewRenderer {
|
|||||||
class func render(_ control: UISearchBar, style: Style) {
|
class func render(_ control: UISearchBar, style: Style) {
|
||||||
super.render(control, style: style)
|
super.render(control, style: style)
|
||||||
|
|
||||||
|
if #available(iOS 26, *) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let searchTextField = control.searchTextField
|
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.
|
// 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 {
|
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)
|
@available(iOS, deprecated: 13.0)
|
||||||
private static let kiOS12DefaultSystemTextFieldHeight = 36
|
private static let kiOS12DefaultSystemTextFieldHeight = 36
|
||||||
|
|
||||||
@@ -91,27 +81,4 @@ class UISearchBarRenderer: UIViewRenderer {
|
|||||||
|
|
||||||
@available(iOS, deprecated: 13.0)
|
@available(iOS, deprecated: 13.0)
|
||||||
private static var searchBarBackgroundImage: UIImage?
|
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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user