@@ -22,23 +22,49 @@ import CoreGraphics
2222/// A Google Sign In button to be used in SwiftUI.
2323@available ( iOS 13 . 0 , macOS 10 . 15 , * )
2424public struct GoogleSignInButton : View {
25- @ObservedObject var viewModel : GoogleSignInButtonViewModel
25+ /// An object containing the styling information needed to create the button.
26+ @ObservedObject public var viewModel : GoogleSignInButtonViewModel
2627 private let action : ( ) -> Void
2728 private let fontLoaded : Bool
2829
2930 /// Creates an instance of the Google Sign-In button for use in SwiftUI
3031 /// - parameter viewModel: An instance of `GoogleSignInButtonViewModel`
31- /// containing information on the button's scheme, style, and state.
32+ /// containing information on the button's scheme, style, and state.
33+ /// Defaults to `GoogleSignInButtonViewModel` with its standard defaults.
3234 /// - parameter action: A closure to use as the button's action upon press.
35+ /// - seealso: Refer to `GoogleSignInButtonViewModel.swift` for its defaults.
3336 public init (
34- viewModel: GoogleSignInButtonViewModel ,
37+ viewModel: GoogleSignInButtonViewModel = GoogleSignInButtonViewModel ( ) ,
3538 action: @escaping ( ) -> Void
3639 ) {
3740 self . viewModel = viewModel
3841 self . action = action
3942 self . fontLoaded = Font . loadCGFont ( )
4043 }
4144
45+ /// A convenience initializer to create a Google Sign-In button in SwiftUI
46+ /// with scheme, style, and state.
47+ /// - parameter scheme: The `GoogleSignInButtonColorScheme` to use. Defaults
48+ /// to `.light`.
49+ /// - parameter style: The `GoogleSignInButtonStyle` to use. Defaults to
50+ /// `.standard`.
51+ /// - parameter state: The `GoogleSignInButtonState` to use. Defaults to
52+ /// `.normal`.
53+ /// - parameter action: A closure to use as the button's action upon press.
54+ public init (
55+ scheme: GoogleSignInButtonColorScheme = . light,
56+ style: GoogleSignInButtonStyle = . standard,
57+ state: GoogleSignInButtonState = . normal,
58+ action: @escaping ( ) -> Void
59+ ) {
60+ let vm = GoogleSignInButtonViewModel (
61+ scheme: scheme,
62+ style: style,
63+ state: state
64+ )
65+ self . init ( viewModel: vm, action: action)
66+ }
67+
4268 public var body : some View {
4369 Button ( action: action) {
4470 switch viewModel. style {
0 commit comments