From 2affcd934fc44690143eb55620556d83230c9b6a Mon Sep 17 00:00:00 2001 From: Matthew Chen Date: Mon, 18 Sep 2017 15:47:59 -0400 Subject: [PATCH] Respond to CR. // FREEBIE --- .../ViewControllers/ProfileViewController.m | 5 +- .../SelectRecipientViewController.m | 2 +- Signal/src/util/UIImage+OWS.m | 2 + Signal/src/views/OWSFlatButton.swift | 54 +++++++------------ 4 files changed, 24 insertions(+), 39 deletions(-) diff --git a/Signal/src/ViewControllers/ProfileViewController.m b/Signal/src/ViewControllers/ProfileViewController.m index cc5ea43cc..d0cd9bad9 100644 --- a/Signal/src/ViewControllers/ProfileViewController.m +++ b/Signal/src/ViewControllers/ProfileViewController.m @@ -346,11 +346,12 @@ NSString *const kProfileView_LastPresentedDate = @"kProfileView_LastPresentedDat // The save button is only used in "registration" and "upgrade or nag" modes. if (self.hasUnsavedChanges) { self.saveButton.enabled = YES; - [self.saveButton setBackgroundColors:[UIColor ows_signalBrandBlueColor]]; + [self.saveButton setBackgroundColorsWithUpColor:[UIColor ows_signalBrandBlueColor]]; } else { self.saveButton.enabled = NO; [self.saveButton - setBackgroundColors:[[UIColor ows_signalBrandBlueColor] blendWithColor:[UIColor whiteColor] alpha:0.5f]]; + setBackgroundColorsWithUpColor:[[UIColor ows_signalBrandBlueColor] blendWithColor:[UIColor whiteColor] + alpha:0.5f]]; } } diff --git a/Signal/src/ViewControllers/SelectRecipientViewController.m b/Signal/src/ViewControllers/SelectRecipientViewController.m index a8b32b90b..eccd8c4b5 100644 --- a/Signal/src/ViewControllers/SelectRecipientViewController.m +++ b/Signal/src/ViewControllers/SelectRecipientViewController.m @@ -379,7 +379,7 @@ NSString *const kSelectRecipientViewControllerCellIdentifier = @"kSelectRecipien BOOL isEnabled = [self hasValidPhoneNumber]; self.phoneNumberButton.enabled = isEnabled; [self.phoneNumberButton - setBackgroundColors:(isEnabled ? [UIColor ows_signalBrandBlueColor] : [UIColor lightGrayColor])]; + setBackgroundColorsWithUpColor:(isEnabled ? [UIColor ows_signalBrandBlueColor] : [UIColor lightGrayColor])]; } #pragma mark - CountryCodeViewControllerDelegate diff --git a/Signal/src/util/UIImage+OWS.m b/Signal/src/util/UIImage+OWS.m index 1532f9f3a..536f6aaaf 100644 --- a/Signal/src/util/UIImage+OWS.m +++ b/Signal/src/util/UIImage+OWS.m @@ -170,6 +170,7 @@ + (UIImage *)imageWithColor:(UIColor *)color { + OWSAssert([NSThread isMainThread]); OWSAssert(color); return [self imageWithColor:color size:CGSizeMake(1.f, 1.f)]; @@ -177,6 +178,7 @@ + (UIImage *)imageWithColor:(UIColor *)color size:(CGSize)size { + OWSAssert([NSThread isMainThread]); OWSAssert(color); CGRect rect = CGRectMake(0.0f, 0.0f, size.width, size.height); diff --git a/Signal/src/views/OWSFlatButton.swift b/Signal/src/views/OWSFlatButton.swift index 348e28c8f..3c69f03ed 100644 --- a/Signal/src/views/OWSFlatButton.swift +++ b/Signal/src/views/OWSFlatButton.swift @@ -7,16 +7,24 @@ import Foundation @objc class OWSFlatButton: UIView { let TAG = "[OWSFlatButton]" - private var button: UIButton? + private let button: UIButton private var pressedBlock : (() -> Void)? private var upColor: UIColor? private var downColor: UIColor? + override var backgroundColor: UIColor? { + willSet { + owsFail("Use setBackgroundColors(upColor:) instead.") + } + } + init() { AssertIsOnMainThread() + button = UIButton(type:.custom) + super.init(frame:CGRect.zero) createContent() @@ -24,13 +32,14 @@ import Foundation @available(*, unavailable, message:"use default constructor instead.") required init?(coder aDecoder: NSCoder) { + button = UIButton(type:.custom) + super.init(coder: aDecoder) + owsFail("\(self.TAG) invalid constructor") } private func createContent() { - let button = UIButton(type:.custom) - self.button = button self.addSubview(button) button.addTarget(self, action:#selector(buttonPressed), for:.touchUpInside) button.autoPinWidthToSuperview() @@ -49,7 +58,7 @@ import Foundation button.setTitle(title:title, font: font, titleColor: titleColor ) - button.setBackgroundColors(backgroundColor) + button.setBackgroundColors(upColor:backgroundColor) button.useDefaultCornerRadius() button.setSize(width:width, height:height) button.addTarget(target:target, selector:selector) @@ -83,7 +92,7 @@ import Foundation button.setTitle(title:title, font: font, titleColor: titleColor ) - button.setBackgroundColors(backgroundColor) + button.setBackgroundColors(upColor:backgroundColor) button.useDefaultCornerRadius() button.addTarget(target:target, selector:selector) return button @@ -98,10 +107,6 @@ import Foundation public func setTitle(title: String, font: UIFont, titleColor: UIColor ) { - guard let button = self.button else { - owsFail("Missing button") - return - } button.setTitle(title, for: .normal) button.setTitleColor(titleColor, for: .normal) button.titleLabel!.font = font @@ -109,33 +114,21 @@ import Foundation public func setBackgroundColors(upColor: UIColor, downColor: UIColor ) { - guard let button = self.button else { - owsFail("Missing button") - return - } button.setBackgroundImage(UIImage(color:upColor), for: .normal) button.setBackgroundImage(UIImage(color:downColor), for: .highlighted) } - public func setBackgroundColors(_ backgroundColor: UIColor ) { - setBackgroundColors(upColor: backgroundColor, - downColor: backgroundColor.withAlphaComponent(0.7) ) + public func setBackgroundColors(upColor: UIColor ) { + setBackgroundColors(upColor: upColor, + downColor: upColor.withAlphaComponent(0.7) ) } public func setSize(width: CGFloat, height: CGFloat) { - guard let button = self.button else { - owsFail("Missing button") - return - } button.autoSetDimension(.width, toSize:width) button.autoSetDimension(.height, toSize:height) } public func useDefaultCornerRadius() { - guard let button = self.button else { - owsFail("Missing button") - return - } // To my eye, this radius tends to look right regardless of button size // (within reason) or device size. button.layer.cornerRadius = 5 @@ -143,19 +136,11 @@ import Foundation } public func setEnabled(_ isEnabled: Bool) { - guard let button = self.button else { - owsFail("Missing button") - return - } button.isEnabled = isEnabled } public func addTarget(target:Any, selector: Selector) { - guard let button = self.button else { - owsFail("Missing button") - return - } button.addTarget(target, action:selector, for:.touchUpInside) } @@ -168,9 +153,6 @@ import Foundation } internal func buttonPressed() { - guard let pressedBlock = pressedBlock else { - return - } - pressedBlock() + pressedBlock?() } }