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

Commit 5711bfa

Browse files
committed
Merge branch 'develop'
2 parents 8ab7b3d + 7e75969 commit 5711bfa

File tree

6 files changed

+67
-10
lines changed

6 files changed

+67
-10
lines changed

WordPressAuthenticator.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Pod::Spec.new do |s|
22
s.name = "WordPressAuthenticator"
3-
s.version = "1.8.0-beta.2"
3+
s.version = "1.8.0-beta.3"
44
s.summary = "WordPressAuthenticator implements an easy and elegant way to authenticate your WordPress Apps."
55

66
s.description = <<-DESC

WordPressAuthenticator/Authenticator/WordPressAuthenticatorConfiguration.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ public struct WordPressAuthenticatorConfiguration {
5656
/// and verified.
5757
///
5858
let showLoginOptionsFromSiteAddress: Bool
59+
60+
/// Flag indicating if the Sign In With Apple option should be displayed.
61+
///
62+
let enableSignInWithApple: Bool
5963

6064
/// Designated Initializer
6165
///
@@ -70,7 +74,8 @@ public struct WordPressAuthenticatorConfiguration {
7074
googleLoginScheme: String,
7175
userAgent: String,
7276
showNewLoginFlow: Bool = false,
73-
showLoginOptionsFromSiteAddress: Bool = false) {
77+
showLoginOptionsFromSiteAddress: Bool = false,
78+
enableSignInWithApple: Bool = false) {
7479

7580
self.wpcomClientId = wpcomClientId
7681
self.wpcomSecret = wpcomSecret
@@ -84,5 +89,6 @@ public struct WordPressAuthenticatorConfiguration {
8489
self.userAgent = userAgent
8590
self.showNewLoginFlow = showNewLoginFlow
8691
self.showLoginOptionsFromSiteAddress = showLoginOptionsFromSiteAddress
92+
self.enableSignInWithApple = enableSignInWithApple
8793
}
8894
}

WordPressAuthenticator/Extensions/WPStyleGuide+Login.swift

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import WordPressShared
22
import WordPressUI
33
import Gridicons
4+
import AuthenticationServices
45

56
final class SubheadlineButton: UIButton {
67
override func traitCollectionDidChange(_ previousTraitCollection: UITraitCollection?) {
@@ -16,7 +17,10 @@ final class SubheadlineButton: UIButton {
1617
extension WPStyleGuide {
1718

1819
private struct Constants {
19-
static let buttonMinHeight: CGFloat = 40.0
20+
// This matches the button height in NUXButtonView.storyboard
21+
static let buttonMinHeight: CGFloat = 50.0
22+
23+
static let textButtonMinHeight: CGFloat = 40.0
2024
static let googleIconOffset: CGFloat = -1.0
2125
static let domainsIconPaddingToRemove: CGFloat = 2.0
2226
static let domainsIconSize = CGSize(width: 18, height: 18)
@@ -112,6 +116,24 @@ extension WPStyleGuide {
112116
return textButton(normal: attrStrNormal, highlighted: attrStrHighlight, font: font)
113117
}
114118

119+
/// Creates a button for Apple Sign-in
120+
///
121+
/// - Returns: A properly styled UIControl
122+
///
123+
124+
class func appleLoginButton() -> UIControl {
125+
#if XCODE11
126+
if #available(iOS 13.0, *) {
127+
let appleButton = ASAuthorizationAppleIDButton(authorizationButtonType: .continue, authorizationButtonStyle: .black)
128+
appleButton.translatesAutoresizingMaskIntoConstraints = false
129+
appleButton.heightAnchor.constraint(greaterThanOrEqualToConstant: Constants.buttonMinHeight).isActive = true
130+
return appleButton
131+
}
132+
#endif
133+
134+
return UIControl()
135+
}
136+
115137
/// Creates a button for Self-hosted Login
116138
///
117139
/// - Returns: A properly styled UIButton
@@ -189,7 +211,7 @@ extension WPStyleGuide {
189211
// for the titleLabel's height.
190212
button.titleLabel?.topAnchor.constraint(equalTo: button.topAnchor, constant: Constants.verticalLabelSpacing).isActive = true
191213
button.titleLabel?.bottomAnchor.constraint(equalTo: button.bottomAnchor, constant: -Constants.verticalLabelSpacing).isActive = true
192-
button.heightAnchor.constraint(greaterThanOrEqualToConstant: Constants.buttonMinHeight).isActive = true
214+
button.heightAnchor.constraint(greaterThanOrEqualToConstant: Constants.textButtonMinHeight).isActive = true
193215

194216

195217
button.setAttributedTitle(normalString, for: .normal)

WordPressAuthenticator/Signin/LoginPrologueLoginMethodViewController.swift

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class LoginPrologueLoginMethodViewController: NUXViewController {
1111
open var emailTapped: (() -> Void)?
1212
open var googleTapped: (() -> Void)?
1313
open var selfHostedTapped: (() -> Void)?
14+
open var appleTapped: (() -> Void)?
1415

1516
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
1617
super.prepare(for: segue, sender: sender)
@@ -34,15 +35,14 @@ class LoginPrologueLoginMethodViewController: NUXViewController {
3435
guard let buttonViewController = buttonViewController else {
3536
return
3637
}
37-
38-
let wordpressTitle = NSLocalizedString("Continue with WordPress.com", comment: "Button title. Tapping begins our normal log in process.")
39-
let googleTitle = NSLocalizedString("Continue with Google", comment: "Button title. Tapping begins log in using Google.")
4038

39+
let wordpressTitle = NSLocalizedString("Continue with WordPress.com", comment: "Button title. Tapping begins our normal log in process.")
4140
buttonViewController.setupTopButton(title: wordpressTitle, isPrimary: false, accessibilityIdentifier: "Log in with Email Button") { [weak self] in
4241
self?.dismiss(animated: true)
4342
self?.emailTapped?()
4443
}
4544

45+
let googleTitle = NSLocalizedString("Continue with Google", comment: "Button title. Tapping begins log in using Google.")
4646
buttonViewController.setupBottomButton(title: googleTitle, isPrimary: false, accessibilityIdentifier: "Log in with Google Button") { [weak self] in
4747
defer {
4848
WordPressAuthenticator.track(.loginSocialButtonClick)
@@ -58,6 +58,16 @@ class LoginPrologueLoginMethodViewController: NUXViewController {
5858
selfHostedLoginButton.addTarget(self, action: #selector(handleSelfHostedButtonTapped), for: .touchUpInside)
5959
}
6060

61+
if WordPressAuthenticator.shared.configuration.enableSignInWithApple {
62+
#if XCODE11
63+
if #available(iOS 13.0, *) {
64+
let appleButton = WPStyleGuide.appleLoginButton()
65+
appleButton.addTarget(self, action: #selector(handleAppleButtonTapped), for: .touchDown)
66+
buttonViewController.stackView?.insertArrangedSubview(appleButton, at: 0)
67+
}
68+
#endif
69+
}
70+
6171
buttonViewController.backgroundColor = WordPressAuthenticator.shared.style.viewControllerBackgroundColor
6272
}
6373

@@ -70,4 +80,9 @@ class LoginPrologueLoginMethodViewController: NUXViewController {
7080
selfHostedTapped?()
7181
}
7282

83+
@objc func handleAppleButtonTapped() {
84+
dismiss(animated: true)
85+
appleTapped?()
86+
}
87+
7388
}

WordPressAuthenticator/Signin/LoginPrologueViewController.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,10 @@ class LoginPrologueViewController: LoginViewController {
6666
vc.selfHostedTapped = { [weak self] in
6767
self?.performSegue(withIdentifier: NUXViewController.SegueIdentifier.showSelfHostedLogin.rawValue, sender: self)
6868
}
69-
69+
vc.appleTapped = { [weak self] in
70+
self?.appleTapped()
71+
}
72+
7073
vc.modalPresentationStyle = .custom
7174
}
7275
}
@@ -110,4 +113,9 @@ class LoginPrologueViewController: LoginViewController {
110113
WordPressAuthenticator.track(.signupButtonTapped)
111114
performSegue(withIdentifier: NUXViewController.SegueIdentifier.showSignupMethod.rawValue, sender: self)
112115
}
116+
117+
private func appleTapped() {
118+
print("Login Prologue: Apple tapped.")
119+
}
120+
113121
}

WordPressAuthenticator/Signin/LoginSiteAddressViewController.swift

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,11 +277,18 @@ class LoginSiteAddressViewController: LoginViewController, NUXKeyboardResponder
277277
vc.googleTapped = { [weak self] in
278278
self?.performSegue(withIdentifier: .showGoogle, sender: self)
279279
}
280+
vc.appleTapped = { [weak self] in
281+
self?.appleTapped()
282+
}
280283

281284
vc.modalPresentationStyle = .custom
282285
}
283286
}
284-
287+
288+
private func appleTapped() {
289+
print("Login Site Address: Apple tapped.")
290+
}
291+
285292
/// Whether the form can be submitted.
286293
///
287294
@objc func canSubmit() -> Bool {
@@ -322,7 +329,6 @@ class LoginSiteAddressViewController: LoginViewController, NUXKeyboardResponder
322329
}
323330
}
324331

325-
326332
@IBAction func handleSubmitButtonTapped(_ sender: UIButton) {
327333
validateForm()
328334
}

0 commit comments

Comments
 (0)