GoogleSignInButtonViewModel.swift 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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) && !arch(i386)
  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. @MainActor
  28. var buttonStyle: SwiftUIButtonStyle {
  29. return SwiftUIButtonStyle(style: style, state: state, scheme: scheme)
  30. }
  31. /// Creates instances of the SwiftUI sign-in button.
  32. /// - parameter scheme: An instance of `GoogleSignInButtonColorScheme`. Defaults to
  33. /// `.light`.
  34. /// - parameter style: An instance of `GoogleSignInButtonStyle`. Defaults to
  35. /// `.standard`.
  36. /// - parameter state: An instance of `GoogleSignInButtonState`. Defaults to
  37. /// `.normal`.
  38. @available(iOS 13.0, macOS 10.15, *)
  39. public init(
  40. scheme: GoogleSignInButtonColorScheme = .light,
  41. style: GoogleSignInButtonStyle = .standard,
  42. state: GoogleSignInButtonState = .normal) {
  43. self.scheme = scheme
  44. self.style = style
  45. self.state = state
  46. }
  47. }
  48. #endif // !arch(arm) && !arch(i386)