Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 29 additions & 3 deletions GoogleSignInSwift/Sources/GoogleSignInButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,49 @@ import CoreGraphics
/// A Google Sign In button to be used in SwiftUI.
@available(iOS 13.0, macOS 10.15, *)
public struct GoogleSignInButton: View {
@ObservedObject var viewModel: GoogleSignInButtonViewModel
/// An object containing the styling information needed to create the button.
@ObservedObject public var viewModel: GoogleSignInButtonViewModel
private let action: () -> Void
private let fontLoaded: Bool

/// Creates an instance of the Google Sign-In button for use in SwiftUI
/// - parameter viewModel: An instance of `GoogleSignInButtonViewModel`
/// containing information on the button's scheme, style, and state.
/// containing information on the button's scheme, style, and state.
/// Defaults to `GoogleSignInButtonViewModel` with its standard defaults.
/// - parameter action: A closure to use as the button's action upon press.
/// - seealso: Refer to `GoogleSignInButtonViewModel.swift` for its defaults.
public init(
viewModel: GoogleSignInButtonViewModel,
viewModel: GoogleSignInButtonViewModel = GoogleSignInButtonViewModel(),
action: @escaping () -> Void
) {
self.viewModel = viewModel
self.action = action
self.fontLoaded = Font.loadCGFont()
}

/// A convenience initializer to create a Google Sign-In button in SwiftUI
/// with scheme, style, and state.
/// - parameter scheme: The `GoogleSignInButtonColorScheme` to use. Defaults
/// to `.light`.
/// - parameter style: The `GoogleSignInButtonStyle` to use. Defaults to
/// `.standard`.
/// - parameter state: The `GoogleSignInButtonState` to use. Defaults to
/// `.normal`.
/// - parameter action: A closure to use as the button's action upon press.
public init(
scheme: GoogleSignInButtonColorScheme = .light,
style: GoogleSignInButtonStyle = .standard,
state: GoogleSignInButtonState = .normal,
action: @escaping () -> Void
) {
let vm = GoogleSignInButtonViewModel(
scheme: scheme,
style: style,
state: state
)
self.init(viewModel: vm, action: action)
}

public var body: some View {
Button(action: action) {
switch viewModel.style {
Expand Down
10 changes: 6 additions & 4 deletions GoogleSignInSwift/Sources/GoogleSignInButtonViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,16 @@ public class GoogleSignInButtonViewModel: ObservableObject {
}

/// Creates instances of the SwiftUI sign-in button.
/// - parameter scheme: An instance of `GoogleSignInButtonColorScheme`.
/// - parameter style: An instance of `GoogleSignInButtonStyle`.
/// - parameter scheme: An instance of `GoogleSignInButtonColorScheme`. Defaults to
/// `.light`.
Comment thread
mdmathias marked this conversation as resolved.
Outdated
/// - parameter style: An instance of `GoogleSignInButtonStyle`. Defaults to
/// `.standard`.
/// - parameter state: An instance of `GoogleSignInButtonState`. Defaults to
/// `.normal`.
@available(iOS 13.0, macOS 10.15, *)
public init(
scheme: GoogleSignInButtonColorScheme,
style: GoogleSignInButtonStyle,
scheme: GoogleSignInButtonColorScheme = .light,
style: GoogleSignInButtonStyle = .standard,
state: GoogleSignInButtonState = .normal) {
self.scheme = scheme
self.style = style
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,7 @@ struct SignInView: View {
var body: some View {
VStack {
HStack {
let buttonViewModel = GoogleSignInButtonViewModel(
scheme: .light,
style: .standard
)
GoogleSignInButton(
viewModel: buttonViewModel,
action: authViewModel.signIn
)
GoogleSignInButton(action: authViewModel.signIn)
.accessibility(hint: Text("Sign in with Google button."))
.padding()
}
Expand Down