From b297775656126b1de19c56692725f6b3e477d02f Mon Sep 17 00:00:00 2001 From: Ryan Zulkoski Date: Thu, 17 Dec 2020 11:36:41 -0600 Subject: [PATCH 1/6] Fixed UISegmentedControl extension crash and improved efficiency. --- Sources/UIKit/AdaptableTextContainer.swift | 30 +++++++++++----------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/Sources/UIKit/AdaptableTextContainer.swift b/Sources/UIKit/AdaptableTextContainer.swift index b42292d3..89a4ca59 100644 --- a/Sources/UIKit/AdaptableTextContainer.swift +++ b/Sources/UIKit/AdaptableTextContainer.swift @@ -146,20 +146,20 @@ extension UISegmentedControl { // `UISegmentedControl` has terrible generics ([NSObject: AnyObject]? or [AnyHashable: Any]?) on /// `titleTextAttributes`, so use a helper in Swift 3+ - @nonobjc final func bon_titleTextAttributes(for state: UIControl.State) -> StyleAttributes { - let attributes = titleTextAttributes(for: state) ?? [:] - var result: StyleAttributes = [:] - for value in attributes { - #if swift(>=4.2) - result[value.key] = value - #else - guard let string = value.key as? StyleAttributes.Key else { - fatalError("Can not convert key \(value.key) to String") - } - result[string] = value - #endif - } - return result + @nonobjc final func bon_titleTextAttributes(for state: UIControl.State) -> StyleAttributes? { + guard let attributes = titleTextAttributes(for: state) else { return nil } + #if swift(>=4.2) + return attributes + #else + var result: StyleAttributes = [:] + for attribute in attributes { + guard let string = attribute.key as? StyleAttributes.Key else { + fatalError("Can not convert key \(attribute.key) to String") + } + result[string] = attribute.value + } + return result + #endif } /// Adapt `attributedTitle`, for all control states, to the specified trait collection. @@ -168,7 +168,7 @@ extension UISegmentedControl { @objc(bon_updateTextForTraitCollection:) public func adaptText(forTraitCollection traitCollection: UITraitCollection) { for state in UIControl.State.commonStates { - let attributes = bon_titleTextAttributes(for: state) + guard let attributes = bon_titleTextAttributes(for: state) else { continue } let newAttributes = NSAttributedString.adapt(attributes: attributes, to: traitCollection) setTitleTextAttributes(newAttributes, for: state) } From a3f88b40dfccdd754650025688dd28380feb5c71 Mon Sep 17 00:00:00 2001 From: Ryan Zulkoski Date: Thu, 17 Dec 2020 15:10:26 -0600 Subject: [PATCH 2/6] Update AdaptableTextContainer.swift Fixed whitespace by replacing tabs with spaces. --- Sources/UIKit/AdaptableTextContainer.swift | 28 +++++++++++----------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Sources/UIKit/AdaptableTextContainer.swift b/Sources/UIKit/AdaptableTextContainer.swift index 89a4ca59..487a8a7d 100644 --- a/Sources/UIKit/AdaptableTextContainer.swift +++ b/Sources/UIKit/AdaptableTextContainer.swift @@ -147,19 +147,19 @@ extension UISegmentedControl { // `UISegmentedControl` has terrible generics ([NSObject: AnyObject]? or [AnyHashable: Any]?) on /// `titleTextAttributes`, so use a helper in Swift 3+ @nonobjc final func bon_titleTextAttributes(for state: UIControl.State) -> StyleAttributes? { - guard let attributes = titleTextAttributes(for: state) else { return nil } - #if swift(>=4.2) - return attributes - #else - var result: StyleAttributes = [:] - for attribute in attributes { - guard let string = attribute.key as? StyleAttributes.Key else { - fatalError("Can not convert key \(attribute.key) to String") - } - result[string] = attribute.value - } - return result - #endif + guard let attributes = titleTextAttributes(for: state) else { return nil } + #if swift(>=4.2) + return attributes + #else + var result: StyleAttributes = [:] + for attribute in attributes { + guard let string = attribute.key as? StyleAttributes.Key else { + fatalError("Can not convert key \(attribute.key) to String") + } + result[string] = attribute.value + } + return result + #endif } /// Adapt `attributedTitle`, for all control states, to the specified trait collection. @@ -168,7 +168,7 @@ extension UISegmentedControl { @objc(bon_updateTextForTraitCollection:) public func adaptText(forTraitCollection traitCollection: UITraitCollection) { for state in UIControl.State.commonStates { - guard let attributes = bon_titleTextAttributes(for: state) else { continue } + guard let attributes = bon_titleTextAttributes(for: state) else { continue } let newAttributes = NSAttributedString.adapt(attributes: attributes, to: traitCollection) setTitleTextAttributes(newAttributes, for: state) } From 620f623d6024a966cc5d7ee0c52e6aeb1c778e37 Mon Sep 17 00:00:00 2001 From: Ryan Zulkoski Date: Thu, 17 Dec 2020 17:22:00 -0600 Subject: [PATCH 3/6] Reverted change to public signature of bon_titleTextAttributes(for:). --- Sources/UIKit/AdaptableTextContainer.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/UIKit/AdaptableTextContainer.swift b/Sources/UIKit/AdaptableTextContainer.swift index 89a4ca59..978e283e 100644 --- a/Sources/UIKit/AdaptableTextContainer.swift +++ b/Sources/UIKit/AdaptableTextContainer.swift @@ -146,8 +146,8 @@ extension UISegmentedControl { // `UISegmentedControl` has terrible generics ([NSObject: AnyObject]? or [AnyHashable: Any]?) on /// `titleTextAttributes`, so use a helper in Swift 3+ - @nonobjc final func bon_titleTextAttributes(for state: UIControl.State) -> StyleAttributes? { - guard let attributes = titleTextAttributes(for: state) else { return nil } + @nonobjc final func bon_titleTextAttributes(for state: UIControl.State) -> StyleAttributes { + let attributes = titleTextAttributes(for: state) ?? [:] #if swift(>=4.2) return attributes #else @@ -168,7 +168,7 @@ extension UISegmentedControl { @objc(bon_updateTextForTraitCollection:) public func adaptText(forTraitCollection traitCollection: UITraitCollection) { for state in UIControl.State.commonStates { - guard let attributes = bon_titleTextAttributes(for: state) else { continue } + let attributes = bon_titleTextAttributes(for: state) let newAttributes = NSAttributedString.adapt(attributes: attributes, to: traitCollection) setTitleTextAttributes(newAttributes, for: state) } From c0fe6bb4ebbd41ad2d1de218860d07a10862e4d4 Mon Sep 17 00:00:00 2001 From: Ryan Zulkoski Date: Fri, 18 Dec 2020 09:44:33 -0600 Subject: [PATCH 4/6] Fixed error in UISegmentedControl.bon_titleTextAttributes(for:) and added UnitTest for segmented control. --- Sources/UIKit/AdaptableTextContainer.swift | 2 +- Tests/UIKitBonMotTests.swift | 25 +++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/Sources/UIKit/AdaptableTextContainer.swift b/Sources/UIKit/AdaptableTextContainer.swift index 99c00ee1..d9eb2a36 100644 --- a/Sources/UIKit/AdaptableTextContainer.swift +++ b/Sources/UIKit/AdaptableTextContainer.swift @@ -147,7 +147,7 @@ extension UISegmentedControl { // `UISegmentedControl` has terrible generics ([NSObject: AnyObject]? or [AnyHashable: Any]?) on /// `titleTextAttributes`, so use a helper in Swift 3+ @nonobjc final func bon_titleTextAttributes(for state: UIControl.State) -> StyleAttributes { - let attributes = titleTextAttributes(for: state) + let attributes = titleTextAttributes(for: state) ?? [:] #if swift(>=4.2) return attributes #else diff --git a/Tests/UIKitBonMotTests.swift b/Tests/UIKitBonMotTests.swift index 59446739..2f02871f 100644 --- a/Tests/UIKitBonMotTests.swift +++ b/Tests/UIKitBonMotTests.swift @@ -119,7 +119,30 @@ class UIKitBonMotTests: XCTestCase { } } - func writeTestSegmentedControl() {} + func testSegmentedControl() { + let segmentedControl = UISegmentedControl() + // Make sure the test is valid and the title text attributes are not defined for the normal state + XCTAssertNil(segmentedControl.titleTextAttributes(for: .normal)) + + segmentedControl.insertSegment(withTitle: ".", at: 0, animated: false) + + // Assign the title text attributes for the normal state and ensure original values match + segmentedControl.setTitleTextAttributes(adaptiveStyle.attributes, for: .normal) + + var attributes = segmentedControl.titleTextAttributes(for: .normal) + XCTAssertEqual(attributes?[.font] as? UIFont, expectedFont) + BONAssertColor(inAttributes: attributes, key: .foregroundColor, color: adaptiveStyle.color!) + BONAssert(attributes: attributes, query: { $0.pointSize }, float: expectedFont.pointSize) + + // Update the trait collection and ensure the font grows. + if #available(iOS 10.0, tvOS 10.0, *) { + segmentedControl.adaptText(forTraitCollection: UITraitCollection(preferredContentSizeCategory: UIContentSizeCategory.extraLarge)) + attributes = segmentedControl.titleTextAttributes(for: .normal) + BONAssert(attributes: attributes, query: { $0.pointSize }, float: expectedFont.pointSize + 2) + BONAssertColor(inAttributes: attributes, key: .foregroundColor, color: adaptiveStyle.color!) + } + } + func writeTestNavigationBar() {} func writeTestToolbar() {} func writeTestViewController() {} From e8ef86a2b373bcc28c20ebc7005403d2687f06be Mon Sep 17 00:00:00 2001 From: Ryan Zulkoski Date: Fri, 18 Dec 2020 11:08:46 -0600 Subject: [PATCH 5/6] Reverting back to returning optional StyleAttributes from UISegmentedControl extension method bon_titleTextAttributes(for:) since it is internal API. --- Sources/UIKit/AdaptableTextContainer.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Sources/UIKit/AdaptableTextContainer.swift b/Sources/UIKit/AdaptableTextContainer.swift index d9eb2a36..487a8a7d 100644 --- a/Sources/UIKit/AdaptableTextContainer.swift +++ b/Sources/UIKit/AdaptableTextContainer.swift @@ -146,8 +146,8 @@ extension UISegmentedControl { // `UISegmentedControl` has terrible generics ([NSObject: AnyObject]? or [AnyHashable: Any]?) on /// `titleTextAttributes`, so use a helper in Swift 3+ - @nonobjc final func bon_titleTextAttributes(for state: UIControl.State) -> StyleAttributes { - let attributes = titleTextAttributes(for: state) ?? [:] + @nonobjc final func bon_titleTextAttributes(for state: UIControl.State) -> StyleAttributes? { + guard let attributes = titleTextAttributes(for: state) else { return nil } #if swift(>=4.2) return attributes #else @@ -168,7 +168,7 @@ extension UISegmentedControl { @objc(bon_updateTextForTraitCollection:) public func adaptText(forTraitCollection traitCollection: UITraitCollection) { for state in UIControl.State.commonStates { - let attributes = bon_titleTextAttributes(for: state) + guard let attributes = bon_titleTextAttributes(for: state) else { continue } let newAttributes = NSAttributedString.adapt(attributes: attributes, to: traitCollection) setTitleTextAttributes(newAttributes, for: state) } From 6753df1bd9f33678f9b774cd8f05c25798095c3b Mon Sep 17 00:00:00 2001 From: Ryan Zulkoski Date: Sun, 24 Jan 2021 15:10:00 -0600 Subject: [PATCH 6/6] Disabled social_media_url in podspec to fix builds --- BonMot.podspec | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/BonMot.podspec b/BonMot.podspec index 1ed795ac..bbc65f69 100644 --- a/BonMot.podspec +++ b/BonMot.podspec @@ -10,7 +10,8 @@ Pod::Spec.new do |s| s.license = 'MIT' s.author = { "Zev Eisenberg" => "zev@zeveisenberg.com" } s.source = { :git => "https://github.com/Rightpoint/BonMot.git", :tag => s.version.to_s } - s.social_media_url = 'https://twitter.com/ZevEisenberg' + # Setting the twitter url is causing builds to fail due to not being able to reach twitter. + # s.social_media_url = 'https://twitter.com/ZevEisenberg' s.requires_arc = true s.ios.deployment_target = '10.0'