-
Notifications
You must be signed in to change notification settings - Fork 11
NUXButton configurable using UIAppearance #10
Conversation
…nges like `FancyButton` does
Removes NUXSubmitButton class. Removes button background assets and generates button background images.
… consistent) in NUXButton
jleandroperez
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mindgraffiti Few comments, looking great!
| var frm = activityIndicator.frame | ||
| frm.origin.x = (frame.width - frm.width) / 2.0 | ||
| frm.origin.y = (frame.height - frm.height) / 2.0 | ||
| activityIndicator.frame = frm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
activityIndicator.frame = frm.integral
Reason: floating positions don't really exist (the screen requires integer coordinates). Anything that has a comma value results in a blurry view.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is confusing. x, y, and frame all accept CGFloat values. Why do they make it like that if they really want ints?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mindgraffiti actually, my explanation was wrong. Lemme rephrase: positions are expressed in terms of Points, not Pixels. The problem is:
- Non Retina Devices: PositionX = 0.5 maps to
half a pixel in the X axis - @2x Devices: PositionX = 0.5 maps to
one pixel - @3x Devices: Position X = 0.5 maps to
one pixel and a half
Any "Pixel Position" that's not integral, when rendered, gets antialias applied. Which is why you usually wanna avoid non integral positions (because they may look blurry).
Exception is: when you're actually calculating things, so it maps to integral pixels. Sometimes you may wanna draw a line 1 pixel width, and there are super simple ways to do so.
| static let normalBackgroundColor = UIColor.white | ||
| static let normalBorderColor = WPStyleGuide.greyLighten20() | ||
| static let highlightBackgroundColor = WPStyleGuide.greyLighten20() | ||
| static let highlightBorderColor = highlightBackgroundColor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mindgraffiti shouldn't all of the values here come from the new Style struct? (Primary.*Color / Secondary.*Color)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
| struct Title { | ||
| static let primaryColor = UIColor.white | ||
| static let secondaryColor = WPStyleGuide.darkGrey() | ||
| static let disabledColor = WPStyleGuide.greyLighten30() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment as above: Shouldn't these come from the new Style struct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
|
|
||
| /// Alternative logins highlight color | ||
| /// | ||
| let highlightColor: UIColor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please set linkColor and highlightColor as public, otherwise they won't be accessible from outside the framework.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
| } | ||
|
|
||
| public extension WordPressAuthenticatorStyle { | ||
| static var defaultStyle: WordPressAuthenticatorStyle { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mindgraffiti please set to public
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
| /// Initializes the WordPressAuthenticator with the specified Configuration. | ||
| /// | ||
| public static func initialize(configuration: WordPressAuthenticatorConfiguration) { | ||
| public static func initialize(configuration: WordPressAuthenticatorConfiguration, style: WordPressAuthenticatorStyle) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mindgraffiti Can we have style: WordPressAuthenticatorStyle = .defaultStyle ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
| import WordPressUI | ||
|
|
||
| /// A protocol for an element that can display a UIActivityIndicatorView | ||
| @objc public protocol ActivityIndicatorButton { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mindgraffiti since the protocol ActivityIndicatorButton isn't really used anywhere (there are no ivars / vars anywhere with that specific Type), can we nuke it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
| fileprivate let maxFontSize: CGFloat = 22 | ||
| @objc open class NUXButton: UIButton, ActivityIndicatorButton { | ||
| @objc var isAnimating: Bool { | ||
| get { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mindgraffiti you can drop the get { } block. If a property is readOnly, you can just do something like this:
var isAnimating: Bool {
return activityIndicator.isAnimating
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
| @@ -1,20 +1,5 @@ | |||
| PODS: | |||
| - 1PasswordExtension (1.8.5) | |||
| - AFNetworking (3.2.1): | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any idea why the Podfile changes so much without Podfile changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, that's due to all the mucking about I did with making some of the pods local. I think I need to pull the original Podfile and Podfile.lock and overwrite the changes made in my PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've been working on nuking AFNetworking (with Sergio) during last Hack Week, from WordPressKit. This change is just (or should be!!) a side effect of running pod install.
No need to bring back the old Podfile.lock, this is a beautiful thing actually!!! (one less dependency).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, got it. 👍
nheagy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm really interested to see how these work in WPiOS—code cleanup in that area sounds great.
I think we should holdoff on merging this until the WPiOS implementation is available. Let me know if you think otherwise.
| /// A stylized button used by Login controllers. It also can display a `UIActivityIndicatorView`. | ||
| @objc open class NUXButton: NUXSubmitButton { | ||
| // MARK: - Configuration | ||
| fileprivate let horizontalInset: CGFloat = 20 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where'd these config values go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They moved to here: https://github.com/wordpress-mobile/WordPressUI-iOS/blob/develop/WordPressUI/Extensions/UIImage%2BAssets.swift#L87
The NUXButton was using the same sizing and configurations as FancyButton, so I moved the definitions out of FancyButton and into the UIImage+Assets extension. This PR has more details wordpress-mobile/WordPressUI-iOS#8
Agreed! I want to thoroughly test this now that the |
…to their own files. Rely on WordPressAuthenticatorStyle defaults instead of styling NUXButton directly
jleandroperez
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mindgraffiti looks great!! few nipticky comments. I'll get to testing the WCiOS Integration PR!!
| super.traitCollectionDidChange(previousTraitCollection) | ||
| if previousTraitCollection?.preferredContentSizeCategory != traitCollection.preferredContentSizeCategory { | ||
| titleLabel?.font = WPStyleGuide.mediumWeightFont(forStyle: .subheadline) | ||
| titleLabel?.textColor = WPStyleGuide.wordPressBlue() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mindgraffiti since Woo is using this, shouldn't we probably grab this one from the Style struct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
| @@ -1,20 +1,5 @@ | |||
| PODS: | |||
| - 1PasswordExtension (1.8.5) | |||
| - AFNetworking (3.2.1): | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've been working on nuking AFNetworking (with Sergio) during last Hack Week, from WordPressKit. This change is just (or should be!!) a side effect of running pod install.
No need to bring back the old Podfile.lock, this is a beautiful thing actually!!! (one less dependency).
| } | ||
| } | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
❤️ this change!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
| setBackgroundImage(highlightedImage, for: .highlighted) | ||
| setBackgroundImage(disabledImage, for: .disabled) | ||
|
|
||
| activityIndicator.activityIndicatorViewStyle = .gray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps this should go into configureActivityIndicator() (since it's not really a Background?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
| frm.origin.x = (frame.width - frm.width) / 2.0 | ||
| frm.origin.y = (frame.height - frm.height) / 2.0 | ||
| activityIndicator.frame = frm.integral | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!! but now that i realize about it: why not just Autolayout? (centerXAnchor / centerYAnchor)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm drawing the line here. Need to get this PR closed. :)
…ethod, ... ...use WordPressAuthenticator styles for titleLabel `traitCollectionDidChange`
jleandroperez
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mindgraffiti looking great overall!!. Added just one important comment. Switching to WPiOS testing as of now, will get back to this one in a bit
|
|
||
| /// Setup: shorter reference for style | ||
| /// | ||
| private let style = WordPressAuthenticator.shared.style |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
typealias Style = WordPressAuthenticator.shared.style
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Error: Static var 'shared' is not a member type of 'WordPressAuthenticator'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhhhhhhh right, it's not a type!!!. My apologies!!. Only alternative is having this as a calculated property. But "meh", really no difference in there.
Sorry about the fuzz!!
| } | ||
|
|
||
| override open func configureBorderColor() { | ||
| struct Metrics { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one should be private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
| } | ||
| configureBackgrounds() | ||
| configureTitleColors() | ||
| activityIndicator.activityIndicatorViewStyle = .gray |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You probably wanna move these three lines (configureBackgrounds, configureTitleColors and configureActivityIndicator) elsewhere. Perhaps to awakeFromNib.
Reason: Each time you call this, configureBackgrounds will re-add the activityIndicator as a subview. This should probably print a warning or so, but it's something we should run just once.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️
nheagy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, @mindgraffiti let's go!
![]()
|
Thank you for helping me out with the |
Resubmitting #7 (by @mindgraffiti)
Not sure how the former one got closed (apparently, happened automatically after i've deleted
new-woo-apis).I'm pasting, below, the former PR's description.
⚠️ The secondary button's default configurations have not been tested against the original button designs for WPiOS. Since it's branched from fully tested and compatible ✅new-woo-apisit isn't compatible with WPiOS just yet and was breaking when I attempted to test the secondary button.This PR makes the NUXButton configurable using UIAppearance. To run a full test, check out the WCiOS PR instructions.