Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expose view controller background colors for styling by host apps #18

Merged
merged 11 commits into from
Aug 7, 2018
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

import UIKit
import Gridicons

// MARK: - WordPress Authenticator Styles
//
Expand Down Expand Up @@ -41,9 +42,17 @@ public struct WordPressAuthenticatorStyle {
///
public let subheadlineColor: UIColor

/// Style: Login screen background colors
///
public let viewControllerBackgroundColor: UIColor

/// Style: nav bar logo
///
public let navBarImage: UIImage

/// Designated initializer
///
public init(primaryNormalBackgroundColor: UIColor, primaryNormalBorderColor: UIColor, primaryHighlightBackgroundColor: UIColor, primaryHighlightBorderColor: UIColor, secondaryNormalBackgroundColor: UIColor, secondaryNormalBorderColor: UIColor, secondaryHighlightBackgroundColor: UIColor, secondaryHighlightBorderColor: UIColor, disabledBackgroundColor: UIColor, disabledBorderColor: UIColor, primaryTitleColor: UIColor, secondaryTitleColor: UIColor, disabledTitleColor: UIColor, subheadlineColor: UIColor) {
public init(primaryNormalBackgroundColor: UIColor, primaryNormalBorderColor: UIColor, primaryHighlightBackgroundColor: UIColor, primaryHighlightBorderColor: UIColor, secondaryNormalBackgroundColor: UIColor, secondaryNormalBorderColor: UIColor, secondaryHighlightBackgroundColor: UIColor, secondaryHighlightBorderColor: UIColor, disabledBackgroundColor: UIColor, disabledBorderColor: UIColor, primaryTitleColor: UIColor, secondaryTitleColor: UIColor, disabledTitleColor: UIColor, subheadlineColor: UIColor, viewControllerBackgroundColor: UIColor, navBarImage: UIImage) {
self.primaryNormalBackgroundColor = primaryNormalBackgroundColor
self.primaryNormalBorderColor = primaryNormalBorderColor
self.primaryHighlightBackgroundColor = primaryHighlightBackgroundColor
Expand All @@ -58,6 +67,8 @@ public struct WordPressAuthenticatorStyle {
self.secondaryTitleColor = secondaryTitleColor
self.disabledTitleColor = disabledTitleColor
self.subheadlineColor = subheadlineColor
self.viewControllerBackgroundColor = viewControllerBackgroundColor
self.navBarImage = navBarImage
}
}

Expand All @@ -76,6 +87,9 @@ public extension WordPressAuthenticatorStyle {
primaryTitleColor: UIColor.white,
secondaryTitleColor: WPStyleGuide.darkGrey(),
disabledTitleColor: WPStyleGuide.greyLighten30(),
subheadlineColor: WPStyleGuide.wordPressBlue())
subheadlineColor: WPStyleGuide.wordPressBlue(),
viewControllerBackgroundColor: WPStyleGuide.lightGrey(),
navBarImage: Gridicon.iconOfType(.mySites)
)
}
}
2 changes: 1 addition & 1 deletion WordPressAuthenticator/NUX/NUXViewControllerBase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ extension NUXViewControllerBase where Self: UIViewController, Self: UIViewContro
/// Adds the WP logo to the nav controller
///
public func addWordPressLogoToNavController() {
let image = Gridicon.iconOfType(.mySites)
let image = WordPressAuthenticator.shared.style.navBarImage
let imageView = UIImageView(image: image.imageWithTintColor(UIColor.white))
navigationItem.titleView = imageView
}
Expand Down
17 changes: 5 additions & 12 deletions WordPressAuthenticator/Signin/Login.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@
</connections>
</containerView>
</subviews>
<color key="backgroundColor" red="0.95294117649999999" green="0.96470588239999999" blue="0.97254901959999995" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="6cw-FO-hjb" firstAttribute="leading" secondItem="EnO-7f-1yO" secondAttribute="leading" id="7Z8-mD-FWN"/>
<constraint firstAttribute="trailing" secondItem="G3G-Ap-6ix" secondAttribute="trailing" id="96a-eB-JlD"/>
Expand Down Expand Up @@ -320,7 +319,6 @@
</variation>
</view>
</subviews>
<color key="backgroundColor" red="0.95294117649999999" green="0.96470588239999999" blue="0.97254901959999995" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="ozJ-hT-OEw" firstAttribute="top" secondItem="bn3-aC-RIM" secondAttribute="bottom" id="S6n-FZ-9Yc"/>
<constraint firstAttribute="trailing" secondItem="ozJ-hT-OEw" secondAttribute="trailing" id="Uuo-bm-Be2"/>
Expand Down Expand Up @@ -547,7 +545,6 @@
</variation>
</view>
</subviews>
<color key="backgroundColor" red="0.95294117649999999" green="0.96470588239999999" blue="0.97254901959999995" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="Ktl-It-Kmo" firstAttribute="top" secondItem="dSZ-FR-Cdo" secondAttribute="bottom" id="1qL-V5-NRd"/>
<constraint firstItem="dSZ-FR-Cdo" firstAttribute="leading" secondItem="HTO-Y8-god" secondAttribute="leadingMargin" constant="-20" id="E8T-56-rvq"/>
Expand Down Expand Up @@ -721,7 +718,6 @@
</variation>
</view>
</subviews>
<color key="backgroundColor" red="0.95294117649999999" green="0.96470588239999999" blue="0.97254901959999995" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="7OQ-0t-1zq" firstAttribute="centerX" secondItem="tEh-Nj-xof" secondAttribute="centerX" id="1g8-p2-jnJ"/>
<constraint firstItem="7OQ-0t-1zq" firstAttribute="top" secondItem="dAs-4b-ACP" secondAttribute="bottom" id="6Lb-n5-RrE"/>
Expand Down Expand Up @@ -885,7 +881,6 @@
</variation>
</view>
</subviews>
<color key="backgroundColor" red="0.95294117649999999" green="0.96470588239999999" blue="0.97254901959999995" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstAttribute="trailingMargin" secondItem="hTY-xb-H5h" secondAttribute="trailing" constant="-20" id="23h-QU-eyB"/>
<constraint firstItem="hTY-xb-H5h" firstAttribute="centerX" secondItem="cm5-76-st7" secondAttribute="centerX" id="PRb-I7-O07"/>
Expand Down Expand Up @@ -983,7 +978,6 @@
</connections>
</button>
</subviews>
<color key="backgroundColor" red="0.95294117649999999" green="0.96470588239999999" blue="0.97254901959999995" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="B6x-b7-hU9" firstAttribute="width" secondItem="HnR-5a-suO" secondAttribute="width" id="AAB-N8-Iyv"/>
<constraint firstAttribute="trailingMargin" secondItem="Mq6-n0-6iO" secondAttribute="trailing" constant="20" id="CoO-Ax-hqg"/>
Expand Down Expand Up @@ -1133,7 +1127,6 @@
</variation>
</view>
</subviews>
<color key="backgroundColor" red="0.95294117649999999" green="0.96470588239999999" blue="0.97254901959999995" alpha="1" colorSpace="calibratedRGB"/>
<constraints>
<constraint firstItem="a59-c7-WBk" firstAttribute="centerX" secondItem="CvY-vN-fn9" secondAttribute="centerX" id="R8E-Gd-gVZ"/>
<constraint firstItem="a59-c7-WBk" firstAttribute="leading" secondItem="CvY-vN-fn9" secondAttribute="leadingMargin" constant="-20" id="atB-bL-5qa"/>
Expand Down Expand Up @@ -1182,10 +1175,10 @@
<inferredMetricsTieBreakers>
<segue reference="kRR-qz-Hu2"/>
<segue reference="ySQ-EM-6JI"/>
<segue reference="sIC-Hv-FJw"/>
<segue reference="1xT-tL-sp6"/>
<segue reference="iD4-VS-n3M"/>
<segue reference="EmH-Av-vhT"/>
<segue reference="HMT-Z5-QHr"/>
<segue reference="nCA-u7-fKm"/>
<segue reference="D3h-Su-Jwk"/>
<segue reference="swV-lc-6gI"/>
<segue reference="gD5-d0-X3t"/>
<segue reference="aSC-hU-lzE"/>
</inferredMetricsTieBreakers>
</document>
6 changes: 6 additions & 0 deletions WordPressAuthenticator/Signin/Login2FAViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class Login2FAViewController: LoginViewController, NUXKeyboardResponder, UITextF
override func viewDidLoad() {
super.viewDidLoad()

styleBackground()
localizeControls()
configureTextFields()
configureSubmitButton(animating: false)
Expand Down Expand Up @@ -82,6 +83,11 @@ class Login2FAViewController: LoginViewController, NUXKeyboardResponder, UITextF

// MARK: Configuration Methods

/// Styles the view's background color. Defaults to WPStyleGuide.lightGrey()
///
@objc func styleBackground() {
view.backgroundColor = WordPressAuthenticator.shared.style.viewControllerBackgroundColor
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move this snippet to the base class?


/// Assigns localized strings to various UIControl defined in the storyboard.
///
Expand Down
8 changes: 8 additions & 0 deletions WordPressAuthenticator/Signin/LoginEmailViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ open class LoginEmailViewController: LoginViewController, NUXKeyboardResponder {
override open func viewDidLoad() {
super.viewDidLoad()

styleBackground()
localizeControls()
setupOnePasswordButtonIfNeeded()
addGoogleButton()
Expand Down Expand Up @@ -97,6 +98,13 @@ open class LoginEmailViewController: LoginViewController, NUXKeyboardResponder {
}


/// Styles the view's background color. Defaults to WPStyleGuide.lightGrey()
///
private func styleBackground() {
view.backgroundColor = WordPressAuthenticator.shared.style.viewControllerBackgroundColor
}


Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here!

/// Assigns localized strings to various UIControl defined in the storyboard.
///
func localizeControls() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class LoginLinkRequestViewController: LoginViewController {
override func viewDidLoad() {
super.viewDidLoad()

styleBackground()
localizeControls()

let email = loginFields.username
Expand All @@ -50,6 +51,12 @@ class LoginLinkRequestViewController: LoginViewController {

// MARK: - Configuration

/// Styles the view's background color. Defaults to WPStyleGuide.lightGrey()
///
@objc func styleBackground() {
view.backgroundColor = WordPressAuthenticator.shared.style.viewControllerBackgroundColor
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaaand same here!

/// Assigns localized strings to various UIControl defined in the storyboard.
///
@objc func localizeControls() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class LoginPrologueViewController: LoginViewController {

// MARK: - Lifecycle Methods

override func viewDidLoad() {
super.viewDidLoad()
styleBackground()
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
configureButtonVC()
Expand Down Expand Up @@ -55,6 +60,10 @@ class LoginPrologueViewController: LoginViewController {
}
}

private func styleBackground() {
view.backgroundColor = WordPressAuthenticator.shared.style.viewControllerBackgroundColor
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaaand same here!

private func configureButtonVC() {
guard let buttonViewController = buttonViewController else {
return
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class LoginSelfHostedViewController: LoginViewController, NUXKeyboardResponder {
override func viewDidLoad() {
super.viewDidLoad()

styleBackground()
configureHeader()
localizeControls()
setupOnePasswordButtonIfNeeded()
Expand Down Expand Up @@ -72,6 +73,11 @@ class LoginSelfHostedViewController: LoginViewController, NUXKeyboardResponder {

// MARK: - Setup and Configuration

/// Styles the view's background color. Defaults to WPStyleGuide.lightGrey()
///
private func styleBackground() {
view.backgroundColor = WordPressAuthenticator.shared.style.viewControllerBackgroundColor
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaaand same here!


/// Assigns localized strings to various UIControl defined in the storyboard.
///
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ class LoginSiteAddressViewController: LoginViewController, NUXKeyboardResponder

override func viewDidLoad() {
super.viewDidLoad()

styleBackground()
localizeControls()
}

Expand Down Expand Up @@ -64,6 +66,12 @@ class LoginSiteAddressViewController: LoginViewController, NUXKeyboardResponder
// MARK: Setup and Configuration


/// Styles the view's background color. Defaults to WPStyleGuide.lightGrey()
///
@objc func styleBackground() {
view.backgroundColor = WordPressAuthenticator.shared.style.viewControllerBackgroundColor
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaaand same here!

/// Assigns localized strings to various UIControl defined in the storyboard.
///
@objc func localizeControls() {
Expand Down
7 changes: 7 additions & 0 deletions WordPressAuthenticator/Signin/LoginWPComViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class LoginWPComViewController: LoginViewController, NUXKeyboardResponder {
override func viewDidLoad() {
super.viewDidLoad()

styleBackground()
localizeControls()
setupOnePasswordButtonIfNeeded()
}
Expand Down Expand Up @@ -118,6 +119,12 @@ class LoginWPComViewController: LoginViewController, NUXKeyboardResponder {
emailLabel?.text = loginFields.username
}

/// Styles the view's background color. Defaults to WPStyleGuide.lightGrey()
///
@objc func styleBackground() {
view.backgroundColor = WordPressAuthenticator.shared.style.viewControllerBackgroundColor
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aaaand same here!

@objc func localizeControls() {
if let service = loginFields.meta.socialService, service == SocialServiceName.google {
instructionLabel?.text = NSLocalizedString("To proceed with this Google account, please first log in with your WordPress.com password. This will only be asked once.", comment: "")
Expand Down