Skip to content

Commit 7adfeb5

Browse files
committed
Port changes from WordPressAuthenticator Woo Brand Update PR to project
When wordpress-mobile/WordPressAuthenticator-iOS#867 was merged, I had already started working on folding WordPressAuthenticator and didn't sync with the team about it. This commit picks all the changes from that PR and copies them in one go into the local version of the WordPressAuthenticator codebase.
1 parent e96144c commit 7adfeb5

File tree

3 files changed

+36
-22
lines changed

3 files changed

+36
-22
lines changed

WooCommerce/WordPressAuthenticator/Authenticator/WordPressAuthenticatorStyles.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ public struct WordPressAuthenticatorStyle {
107107
///
108108
public let prologueSecondaryButtonStyle: NUXButtonStyle?
109109

110+
/// Style: tertiary button on the prologue view
111+
/// When `nil` it will use the default link style
112+
/// Defaults to `nil`
113+
///
114+
public let prologueTertiaryButtonStyle: NUXButtonStyle?
115+
110116
/// Style: prologue top container child view controller
111117
/// When nil, `LoginProloguePageViewController` is displayed in the top container
112118
///
@@ -163,6 +169,7 @@ public struct WordPressAuthenticatorStyle {
163169
prologueButtonsBlurEffect: UIBlurEffect? = nil,
164170
prologuePrimaryButtonStyle: NUXButtonStyle? = nil,
165171
prologueSecondaryButtonStyle: NUXButtonStyle? = nil,
172+
prologueTertiaryButtonStyle: NUXButtonStyle? = nil,
166173
prologueTopContainerChildViewController: @autoclosure @escaping () -> UIViewController? = nil,
167174
statusBarStyle: UIStatusBarStyle = .lightContent,
168175
orDividerSeparatorColor: UIColor = .tertiaryLabel,
@@ -200,6 +207,7 @@ public struct WordPressAuthenticatorStyle {
200207
self.prologueButtonsBlurEffect = prologueButtonsBlurEffect
201208
self.prologuePrimaryButtonStyle = prologuePrimaryButtonStyle
202209
self.prologueSecondaryButtonStyle = prologueSecondaryButtonStyle
210+
self.prologueTertiaryButtonStyle = prologueTertiaryButtonStyle
203211
self.prologueTopContainerChildViewController = prologueTopContainerChildViewController
204212
self.statusBarStyle = statusBarStyle
205213
self.orDividerSeparatorColor = orDividerSeparatorColor
@@ -250,6 +258,10 @@ public struct WordPressAuthenticatorUnifiedStyle {
250258
/// Style: optional auth Prologue view background image
251259
public let prologueBackgroundImage: UIImage?
252260

261+
/// Style: optional resizing policy for the prologue background image
262+
///
263+
public let prologueBackgroundScaleMode: UIView.ContentMode
264+
253265
/// Style: optional blur effect for the buttons view
254266
public let prologueButtonsBlurEffect: UIBlurEffect?
255267

@@ -279,6 +291,7 @@ public struct WordPressAuthenticatorUnifiedStyle {
279291
prologueButtonsBackgroundColor: UIColor = .clear,
280292
prologueViewBackgroundColor: UIColor? = nil,
281293
prologueBackgroundImage: UIImage? = nil,
294+
prologueBackgroundScaleMode: UIView.ContentMode = .scaleToFill,
282295
prologueButtonsBlurEffect: UIBlurEffect? = nil,
283296
statusBarStyle: UIStatusBarStyle = .default,
284297
navBarBackgroundColor: UIColor,
@@ -295,6 +308,7 @@ public struct WordPressAuthenticatorUnifiedStyle {
295308
self.prologueButtonsBackgroundColor = prologueButtonsBackgroundColor
296309
self.prologueViewBackgroundColor = prologueViewBackgroundColor ?? viewControllerBackgroundColor
297310
self.prologueBackgroundImage = prologueBackgroundImage
311+
self.prologueBackgroundScaleMode = prologueBackgroundScaleMode
298312
self.prologueButtonsBlurEffect = prologueButtonsBlurEffect
299313
self.statusBarStyle = statusBarStyle
300314
self.navBarBackgroundColor = navBarBackgroundColor

WooCommerce/WordPressAuthenticator/NUX/Button/NUXStackedButtonsViewController.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,13 +150,18 @@ private extension NUXStackedButtonsViewController {
150150
buttons = []
151151
topStackView?.arrangedSubviews.forEach({ $0.removeFromSuperview() })
152152
bottomStackView?.arrangedSubviews.forEach({ $0.removeFromSuperview() })
153+
topStackView?.isHidden = true
154+
bottomStackView?.isHidden = true
155+
153156
for config in buttonConfigs {
154157
let button = NUXButton()
155158
switch config.stackView {
156159
case .top:
157160
topStackView?.addArrangedSubview(button)
161+
topStackView?.isHidden = false
158162
case .bottom:
159163
bottomStackView?.addArrangedSubview(button)
164+
bottomStackView?.isHidden = false
160165
}
161166
button.configure(withConfig: config.config, and: config.style)
162167
buttons.append(button)

WooCommerce/WordPressAuthenticator/Signin/LoginPrologueViewController.swift

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,6 @@ class LoginPrologueViewController: LoginViewController {
1212
var showCancel = false
1313

1414
@IBOutlet private weak var buttonContainerView: UIView!
15-
/// Blur effect on button container view
16-
///
17-
private var blurEffect: UIBlurEffect.Style {
18-
return .systemChromeMaterial
19-
}
2015

2116
/// Constraints on the button view container.
2217
/// Used to adjust the button width in unified views.
@@ -65,12 +60,10 @@ class LoginPrologueViewController: LoginViewController {
6560
topContainerView.pinSubviewToAllEdges(topContainerChildViewController.view)
6661
}
6762

63+
setupViewBackground()
6864
createButtonViewController()
6965

7066
defaultButtonViewMargin = buttonViewLeadingConstraint?.constant ?? 0
71-
if let backgroundImage = WordPressAuthenticator.shared.unifiedStyle?.prologueBackgroundImage {
72-
view.layer.contents = backgroundImage.cgImage
73-
}
7467
}
7568

7669
override func styleBackground() {
@@ -265,6 +258,7 @@ class LoginPrologueViewController: LoginViewController {
265258

266259
let primaryButtonStyle = WordPressAuthenticator.shared.style.prologuePrimaryButtonStyle
267260
let secondaryButtonStyle = WordPressAuthenticator.shared.style.prologueSecondaryButtonStyle
261+
let tertiaryButtonStyle = WordPressAuthenticator.shared.style.prologueTertiaryButtonStyle ?? NUXButtonStyle.linkButtonStyle
268262

269263
setButtonViewMargins(forWidth: view.frame.width)
270264
let displayStrings = WordPressAuthenticator.shared.displayStrings
@@ -323,7 +317,7 @@ class LoginPrologueViewController: LoginViewController {
323317
isPrimary: false,
324318
configureBodyFontForTitle: true,
325319
accessibilityIdentifier: "Prologue Site Creation Guide button",
326-
style: NUXButtonStyle.linkButtonStyle,
320+
style: tertiaryButtonStyle,
327321
onTap: siteCreationGuideCallback())
328322
}()
329323

@@ -385,26 +379,27 @@ class LoginPrologueViewController: LoginViewController {
385379
}
386380
}
387381

382+
private func setupViewBackground() {
383+
if let prologueViewBackgroundColor = WordPressAuthenticator.shared.unifiedStyle?.prologueViewBackgroundColor {
384+
view.backgroundColor = prologueViewBackgroundColor
385+
}
386+
387+
if let backgroundImage = WordPressAuthenticator.shared.unifiedStyle?.prologueBackgroundImage {
388+
let backgroundImageView = UIImageView(image: backgroundImage)
389+
backgroundImageView.contentMode = WordPressAuthenticator.shared.unifiedStyle?.prologueBackgroundScaleMode ?? .scaleAspectFill
390+
backgroundImageView.translatesAutoresizingMaskIntoConstraints = false
391+
view.insertSubview(backgroundImageView, at: 0)
392+
view.pinSubviewToAllEdges(backgroundImageView)
393+
}
394+
}
395+
388396
private func setButtonViewControllerBackground() {
389397
// Fallback to setting the button background color to clear so the blur effect blurs the Prologue background color.
390398
let buttonsBackgroundColor = WordPressAuthenticator.shared.unifiedStyle?.prologueButtonsBackgroundColor ?? .clear
391399
buttonViewController?.backgroundColor = buttonsBackgroundColor
392400
buttonBackgroundView?.backgroundColor = buttonsBackgroundColor
393401
stackedButtonsViewController?.backgroundColor = buttonsBackgroundColor
394402

395-
/// If host apps provide a background color for the prologue buttons:
396-
/// 1. Hide the blur effect
397-
/// 2. Set the background color of the view controller to prologueViewBackgroundColor
398-
let prologueViewBackgroundColor = WordPressAuthenticator.shared.unifiedStyle?.prologueViewBackgroundColor ?? .clear
399-
400-
guard prologueViewBackgroundColor.cgColor == buttonsBackgroundColor.cgColor else {
401-
buttonBlurEffectView.effect = UIBlurEffect(style: blurEffect)
402-
return
403-
}
404-
// do not set background color if we've set a background image earlier
405-
if WordPressAuthenticator.shared.unifiedStyle?.prologueBackgroundImage == nil {
406-
view.backgroundColor = prologueViewBackgroundColor
407-
}
408403
// if a blur effect for the buttons was passed, use it; otherwise hide the view.
409404
guard let blurEffect = WordPressAuthenticator.shared.unifiedStyle?.prologueButtonsBlurEffect else {
410405
buttonBlurEffectView.isHidden = true

0 commit comments

Comments
 (0)