Skip to content
This repository was archived by the owner on Feb 5, 2025. It is now read-only.

Commit e5247b2

Browse files
[Woo Brand Update] Add more customization options to the prologue (#867)
2 parents 52ce5e6 + 74b8c9f commit e5247b2

File tree

4 files changed

+38
-23
lines changed

4 files changed

+38
-23
lines changed

CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ _None._
1818
1919
### New Features
2020
21-
_None._
21+
- Allow setting both a color and an image as prologue background simultaneously [#867]
22+
- Add support for customizing the tertiary button style on the prologue screen [#867]
2223
2324
### Bug Fixes
2425

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

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)

WordPressAuthenticator/Signin/LoginPrologueViewController.swift

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

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

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

64+
setupViewBackground()
6965
createButtonViewController()
7066

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

7770
override func styleBackground() {
@@ -266,6 +259,7 @@ class LoginPrologueViewController: LoginViewController {
266259

267260
let primaryButtonStyle = WordPressAuthenticator.shared.style.prologuePrimaryButtonStyle
268261
let secondaryButtonStyle = WordPressAuthenticator.shared.style.prologueSecondaryButtonStyle
262+
let tertiaryButtonStyle = WordPressAuthenticator.shared.style.prologueTertiaryButtonStyle ?? NUXButtonStyle.linkButtonStyle
269263

270264
setButtonViewMargins(forWidth: view.frame.width)
271265
let displayStrings = WordPressAuthenticator.shared.displayStrings
@@ -324,7 +318,7 @@ class LoginPrologueViewController: LoginViewController {
324318
isPrimary: false,
325319
configureBodyFontForTitle: true,
326320
accessibilityIdentifier: "Prologue Site Creation Guide button",
327-
style: NUXButtonStyle.linkButtonStyle,
321+
style: tertiaryButtonStyle,
328322
onTap: siteCreationGuideCallback())
329323
}()
330324

@@ -386,26 +380,27 @@ class LoginPrologueViewController: LoginViewController {
386380
}
387381
}
388382

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

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

0 commit comments

Comments
 (0)