-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from SwiftfulThinking/google
- Loading branch information
Showing
11 changed files
with
182 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
Sources/SwiftfulFirebaseAuth/Core/SignInWithGoogleButtonView.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
// | ||
// SignInWithGoogleButtonView.swift | ||
// | ||
// | ||
// Created by Nicholas Sarno on 11/6/23. | ||
// | ||
|
||
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 struct SignInWithGoogleButtonView: 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 init( | ||
type: ASAuthorizationAppleIDButton.ButtonType = .signIn, | ||
backgroundColor: Color = .black, | ||
borderColor: Color = .black, | ||
foregroundColor: Color = .white, | ||
cornerRadius: CGFloat = 10 | ||
) { | ||
self.cornerRadius = cornerRadius | ||
self.backgroundColor = backgroundColor | ||
self.borderColor = borderColor | ||
self.foregroundColor = foregroundColor | ||
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: 6) { | ||
Image("GoogleIcon", bundle: .module) | ||
.resizable() | ||
.scaledToFit() | ||
.frame(width: 16, height: 16) | ||
|
||
Text("\(buttonText) Google") | ||
.font(.system(size: 20)) | ||
.fontWeight(.medium) | ||
} | ||
.foregroundColor(foregroundColor) | ||
} | ||
.padding(.vertical, 1) | ||
.disabled(true) | ||
} | ||
} | ||
|
||
#Preview("SignInWithGoogleButtonView") { | ||
SignInWithGoogleButtonView() | ||
.frame(height: 60) | ||
.padding() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
6 changes: 6 additions & 0 deletions
6
Sources/SwiftfulFirebaseAuth/Support/Assets.xcassets/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
Sources/SwiftfulFirebaseAuth/Support/Assets.xcassets/GoogleIcon.imageset/Contents.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"images" : [ | ||
{ | ||
"filename" : "GoogleIcon.png", | ||
"idiom" : "universal" | ||
} | ||
], | ||
"info" : { | ||
"author" : "xcode", | ||
"version" : 1 | ||
}, | ||
"properties" : { | ||
"template-rendering-intent" : "template" | ||
} | ||
} |
Binary file added
BIN
+1.52 KB
...SwiftfulFirebaseAuth/Support/Assets.xcassets/GoogleIcon.imageset/GoogleIcon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.