GoogleSignInButtonViewModel.swift 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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. #if !arch(arm)
  17. import Combine
  18. /// A view model for the SwiftUI sign-in button publishing changes for the
  19. /// button scheme, style, and state.
  20. @available(iOS 13.0, macOS 10.15, *)
  21. public class GoogleSignInButtonViewModel: ObservableObject {
  22. @Published public var scheme: GoogleSignInButtonColorScheme
  23. @Published public var style: GoogleSignInButtonStyle
  24. @Published public var state: GoogleSignInButtonState
  25. /// A computed property providing the button's size, colors, corner radius,
  26. /// and shadow based on this current view model's `SignInButtonStyle`.
  27. var buttonStyle: SwiftUIButtonStyle {
  28. return SwiftUIButtonStyle(style: style, state: state, scheme: scheme)
  29. }
  30. /// Creates instances of the SwiftUI sign-in button.
  31. /// - parameter scheme: An instance of `GoogleSignInButtonColorScheme`. Defaults to
  32. /// `.light`.
  33. /// - parameter style: An instance of `GoogleSignInButtonStyle`. Defaults to
  34. /// `.standard`.
  35. /// - parameter state: An instance of `GoogleSignInButtonState`. Defaults to
  36. /// `.normal`.
  37. @available(iOS 13.0, macOS 10.15, *)
  38. public init(
  39. scheme: GoogleSignInButtonColorScheme = .light,
  40. style: GoogleSignInButtonStyle = .standard,
  41. state: GoogleSignInButtonState = .normal) {
  42. self.scheme = scheme
  43. self.style = style
  44. self.state = state
  45. }
  46. }
  47. #endif // !arch(arm)