From 1dc4bf3a2d25780bc4fcb2fb83816c4e40b190b3 Mon Sep 17 00:00:00 2001 From: Dhruvil Date: Sat, 1 May 2021 09:34:10 +0530 Subject: [PATCH 1/3] Added SPM Support --- Package.swift | 34 +++++++++++++++++++ .../SearchTextFieldTests.swift | 18 ++++++++++ 2 files changed, 52 insertions(+) create mode 100644 Package.swift create mode 100644 Tests/SearchTextFieldTests/SearchTextFieldTests.swift diff --git a/Package.swift b/Package.swift new file mode 100644 index 0000000..7b20254 --- /dev/null +++ b/Package.swift @@ -0,0 +1,34 @@ +// swift-tools-version:5.3 +// The swift-tools-version declares the minimum version of Swift required to build this package. + +import PackageDescription + +let package = Package( + name: "SearchTextField", + platforms: [ + .iOS(.v9) + ], + products: [ + // Products define the executables and libraries a package produces, and make them visible to other packages. + .library( + name: "SearchTextField", + targets: ["SearchTextField"]), + ], + dependencies: [ + // Dependencies declare other packages that this package depends on. + // .package(url: /* package url */, from: "1.0.0"), + ], + targets: [ + // Targets are the basic building blocks of a package. A target can define a module or a test suite. + // Targets can depend on other targets in this package, and on products in packages this package depends on. + .target( + name: "SearchTextField", + dependencies: [], + path:"SearchTextField/Classes" + ), + .testTarget( + name: "SearchTextFieldTests", + dependencies: ["SearchTextField"], + path:"Tests") + ] +) diff --git a/Tests/SearchTextFieldTests/SearchTextFieldTests.swift b/Tests/SearchTextFieldTests/SearchTextFieldTests.swift new file mode 100644 index 0000000..202d9f2 --- /dev/null +++ b/Tests/SearchTextFieldTests/SearchTextFieldTests.swift @@ -0,0 +1,18 @@ +#if canImport(UIKit) + @testable import SearchTextField + import XCTest + + class SearchTextFieldTest: XCTestCase { + override func setUp() { + // add setup code + } + + override func tearDown() { + // add tear down code + } + + func testSearchTextField() { + // add test code + } + } +#endif From f459a1e600821a304d62126d17fe01aa46fb05e3 Mon Sep 17 00:00:00 2001 From: Ben Date: Sun, 15 Aug 2021 14:23:39 +0800 Subject: [PATCH 2/3] fix iOS 13 deprecated methods --- SearchTextField/Classes/SearchTextField.swift | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/SearchTextField/Classes/SearchTextField.swift b/SearchTextField/Classes/SearchTextField.swift index 9cf8f55..9efb3e5 100755 --- a/SearchTextField/Classes/SearchTextField.swift +++ b/SearchTextField/Classes/SearchTextField.swift @@ -144,7 +144,7 @@ open class SearchTextField: UITextField { fileprivate var timer: Timer? = nil fileprivate var placeholderLabel: UILabel? fileprivate static let cellIdentifier = "APSearchTextFieldCell" - fileprivate let indicator = UIActivityIndicatorView(style: .gray) + fileprivate let indicator = UIActivityIndicatorView(style: UIActivityIndicatorView.Style.medium) fileprivate var maxTableViewSize: CGFloat = 0 fileprivate var filteredResults = [SearchTextFieldItem]() @@ -530,7 +530,7 @@ open class SearchTextField: UITextField { // MARK: - Prepare for draw table result fileprivate func prepareDrawTableResult() { - guard let frame = self.superview?.convert(self.frame, to: UIApplication.shared.keyWindow) else { return } + guard let frame = self.superview?.convert(self.frame, to: UIApplication.shared.windows.first { $0.isKeyWindow }) else { return } if let keyboardFrame = keyboardFrame { var newFrame = frame newFrame.size.height += theme.cellHeight @@ -543,7 +543,8 @@ open class SearchTextField: UITextField { redrawSearchTableView() } else { - if self.center.y + theme.cellHeight > UIApplication.shared.keyWindow!.frame.size.height { + let key = UIApplication.shared.windows.first { $0.isKeyWindow } + if self.center.y + theme.cellHeight > key!.frame.size.height { direction = .up } else { direction = .down From 31376bed9659081ec97520831b00b0924ea0d32f Mon Sep 17 00:00:00 2001 From: Ben Date: Sun, 15 Aug 2021 14:29:20 +0800 Subject: [PATCH 3/3] fix crash when placeholder is empty string --- SearchTextField/Classes/SearchTextField.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/SearchTextField/Classes/SearchTextField.swift b/SearchTextField/Classes/SearchTextField.swift index 9efb3e5..6a389bf 100755 --- a/SearchTextField/Classes/SearchTextField.swift +++ b/SearchTextField/Classes/SearchTextField.swift @@ -253,7 +253,8 @@ open class SearchTextField: UITextField { placeholderLabel?.backgroundColor = UIColor.clear placeholderLabel?.lineBreakMode = .byClipping - if let placeholderColor = self.attributedPlaceholder?.attribute(NSAttributedString.Key.foregroundColor, at: 0, effectiveRange: nil) as? UIColor { + if let attributedPlaceholder = self.attributedPlaceholder, attributedPlaceholder.length > 0, + let placeholderColor = attributedPlaceholder.attribute(.foregroundColor, at: 0, effectiveRange: nil) as? UIColor { placeholderLabel?.textColor = placeholderColor } else { placeholderLabel?.textColor = UIColor ( red: 0.8, green: 0.8, blue: 0.8, alpha: 1.0 )