Skip to content

Commit

Permalink
[Feature] Add SignInWithPhoneButtonView
Browse files Browse the repository at this point in the history
  • Loading branch information
swiftfulthinking-llc committed Apr 23, 2024
1 parent c86fd0c commit 9b6cace
Show file tree
Hide file tree
Showing 7 changed files with 163 additions and 73 deletions.
2 changes: 1 addition & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ let package = Package(
.product(name: "GoogleSignInSwift", package: "GoogleSignIn-iOS")
],
resources: [
.process("Assets")
.process("Support/Assets")
]
),
.testTarget(
Expand Down
16 changes: 4 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,8 @@ Firebase docs: https://firebase.google.com/docs/auth/ios/apple

### 3. Add Apple Button (optional)
```swift
SignInWithAppleButtonView(
type: .signUp,
style: .black,
cornerRadius: 10
)
.frame(height: 50)
SignInWithAppleButtonView()
.frame(height: 50)
```

### 4. Sign in
Expand Down Expand Up @@ -115,12 +111,8 @@ Firebase docs: https://firebase.google.com/docs/auth/ios/google-signin

### 4. Add Google Button (optional)
```swift
SignInWithGoogleButtonView(
type: .signUp,
style: .black,
cornerRadius: 10
)
.frame(height: 50)
SignInWithGoogleButtonView()
.frame(height: 50)
```

### 5. Sign in
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// ASAuthorizationAppleIDButton.swift
//
//
// Created by Nick Sarno on 4/22/24.
//

import Foundation
import SwiftUI
import AuthenticationServices

extension ASAuthorizationAppleIDButton.Style {
var backgroundColor: Color {
switch self {
case .white:
return .white
case .whiteOutline:
return .white
default:
return .black
}
}

var foregroundColor: Color {
switch self {
case .white:
return .black
case .whiteOutline:
return .black
default:
return .white
}
}

var borderColor: Color {
switch self {
case .white:
return .white
case .whiteOutline:
return .black
default:
return .black
}
}
}

extension ASAuthorizationAppleIDButton.ButtonType {
var buttonText: String {
switch self {
case .signIn:
return "Sign in with"
case .continue:
return "Continue with"
case .signUp:
return "Sign up with"
default:
return "Sign in with"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,6 @@ private struct SignInWithAppleButtonViewRepresentable: UIViewRepresentable {
style: .white, cornerRadius: 30)
.frame(height: 50)
.background(Color.red)

SignInWithGoogleButtonView(
type: .signIn,
style: .white, cornerRadius: 30)
.frame(height: 50)
.background(Color.red)
}
.padding(40)
}
Expand Down
62 changes: 8 additions & 54 deletions Sources/SwiftfulFirebaseAuth/Core/SignInWithGoogleButtonView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,54 +9,8 @@ import Foundation
import SwiftUI
import AuthenticationServices

fileprivate extension ASAuthorizationAppleIDButton.Style {
var backgroundColor: Color {
switch self {
case .white:
return .white
case .whiteOutline:
return .white
default:
return .black
}
}

var foregroundColor: Color {
switch self {
case .white:
return .black
case .whiteOutline:
return .black
default:
return .white
}
}

var borderColor: Color {
switch self {
case .white:
return .white
case .whiteOutline:
return .black
default:
return .black
}
}
}

fileprivate extension ASAuthorizationAppleIDButton.ButtonType {
var buttonText: String {
switch self {
case .signIn:
return "Sign in with"
case .continue:
return "Continue with"
case .signUp:
return "Sign up with"
default:
return "Sign in with"
}
}
public extension Color {
static let googleRed = Color("GoogleRed", bundle: Bundle.module)
}

public struct SignInWithGoogleButtonView: View {
Expand All @@ -66,7 +20,7 @@ public struct SignInWithGoogleButtonView: View {
private var borderColor: Color
private var buttonText: String
private var cornerRadius: CGFloat

public init(
type: ASAuthorizationAppleIDButton.ButtonType = .signIn,
style: ASAuthorizationAppleIDButton.Style = .black,
Expand All @@ -81,8 +35,8 @@ public struct SignInWithGoogleButtonView: View {

public init(
type: ASAuthorizationAppleIDButton.ButtonType = .signIn,
backgroundColor: Color = .black,
borderColor: Color = .black,
backgroundColor: Color = .googleRed,
borderColor: Color = .googleRed,
foregroundColor: Color = .white,
cornerRadius: CGFloat = 10
) {
Expand All @@ -102,14 +56,14 @@ public struct SignInWithGoogleButtonView: View {
.fill(backgroundColor)
.padding(0.8)

HStack(spacing: 6) {
HStack(spacing: 8) {
Image("GoogleIcon", bundle: .module)
.resizable()
.scaledToFit()
.frame(width: 16, height: 16)

Text("\(buttonText) Google")
.font(.system(size: 20))
.font(.system(size: 21))
.fontWeight(.medium)
}
.foregroundColor(foregroundColor)
Expand All @@ -120,7 +74,7 @@ public struct SignInWithGoogleButtonView: View {
}

#Preview("SignInWithGoogleButtonView") {
SignInWithGoogleButtonView()
SignInWithGoogleButtonView(backgroundColor: .googleRed)
.frame(height: 60)
.padding()
}
70 changes: 70 additions & 0 deletions Sources/SwiftfulFirebaseAuth/Core/SignInWithPhoneButtonView.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// SignInWithPhoneButtonView.swift
//
//
// Created by Nick Sarno on 4/22/24.
//

import SwiftUI
import SwiftUI
import AuthenticationServices

public struct SignInWithPhoneButtonView: View {

private var backgroundColor: Color
private var foregroundColor: Color
private var borderColor: Color
private var buttonText: String
private var cornerRadius: CGFloat

public init(
type: ASAuthorizationAppleIDButton.ButtonType = .signIn,
style: ASAuthorizationAppleIDButton.Style = .black,
cornerRadius: CGFloat = 10
) {
self.cornerRadius = cornerRadius
self.backgroundColor = style.backgroundColor
self.foregroundColor = style.foregroundColor
self.borderColor = style.borderColor
self.buttonText = type.buttonText
}

public var body: some View {
ZStack {
RoundedRectangle(cornerRadius: cornerRadius)
.fill(borderColor)

RoundedRectangle(cornerRadius: cornerRadius)
.fill(backgroundColor)
.padding(0.8)

HStack(spacing: 8) {
Image(systemName: "phone.fill")
.resizable()
.scaledToFit()
.frame(width: 16, height: 16)

Text("\(buttonText) Phone")
.font(.system(size: 21))
.fontWeight(.medium)
}
.foregroundColor(foregroundColor)
}
.padding(.vertical, 1)
.disabled(true)
}
}

#Preview("SignInWithGoogleButtonView") {
VStack {
SignInWithAppleButtonView()
.frame(height: 60)
.padding()
SignInWithGoogleButtonView()
.frame(height: 60)
.padding()
SignInWithPhoneButtonView()
.frame(height: 60)
.padding()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"colors" : [
{
"color" : {
"color-space" : "srgb",
"components" : {
"alpha" : "1.000",
"blue" : "0x35",
"green" : "0x43",
"red" : "0xEA"
}
},
"idiom" : "universal"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}

0 comments on commit 9b6cace

Please sign in to comment.