|
|
@@ -22,16 +22,19 @@ 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
|
|
|
@@ -39,6 +42,29 @@ public struct GoogleSignInButton: View {
|
|
|
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 {
|