GoogleSignInButtonViewModel.swift 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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`. Defaults to
  31. /// `.light`.
  32. /// - parameter style: An instance of `GoogleSignInButtonStyle`. Defaults to
  33. /// `.standard`.
  34. /// - parameter state: An instance of `GoogleSignInButtonState`. Defaults to
  35. /// `.normal`.
  36. @available(iOS 13.0, macOS 10.15, *)
  37. public init(
  38. scheme: GoogleSignInButtonColorScheme = .light,
  39. style: GoogleSignInButtonStyle = .standard,
  40. state: GoogleSignInButtonState = .normal) {
  41. self.scheme = scheme
  42. self.style = style
  43. self.state = state
  44. }
  45. }