GoogleSignInButtonViewModel.swift 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright 2022 Google LLC
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import Combine
  17. /// A view model for the SwiftUI sign-in button publishing changes for the
  18. /// button scheme, style, and state.
  19. @available(iOS 13.0, macOS 10.15, *)
  20. public class GoogleSignInButtonViewModel: ObservableObject {
  21. @Published public var scheme: GoogleSignInButtonColorScheme
  22. @Published public var style: GoogleSignInButtonStyle
  23. @Published public var state: GoogleSignInButtonState
  24. /// A computed property providing the button's size, colors, corner radius,
  25. /// and shadow based on this current view model's `SignInButtonStyle`.
  26. var buttonStyle: SwiftUIButtonStyle {
  27. return SwiftUIButtonStyle(style: style, state: state, scheme: scheme)
  28. }
  29. /// Creates instances of the SwiftUI sign-in button.
  30. /// - parameter scheme: An instance of `GoogleSignInButtonColorScheme`.
  31. /// - parameter style: An instance of `GoogleSignInButtonStyle`.
  32. /// - parameter state: An instance of `GoogleSignInButtonState`. Defaults to
  33. /// `.normal`.
  34. @available(iOS 13.0, macOS 10.15, *)
  35. public init(
  36. scheme: GoogleSignInButtonColorScheme,
  37. style: GoogleSignInButtonStyle,
  38. state: GoogleSignInButtonState = .normal) {
  39. self.scheme = scheme
  40. self.style = style
  41. self.state = state
  42. }
  43. }