SignInView.swift 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. /*
  2. * Copyright 2021 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 SwiftUI
  17. import GoogleSignInSwift
  18. struct SignInView: View {
  19. @EnvironmentObject var authViewModel: AuthenticationViewModel
  20. @ObservedObject var vm = GoogleSignInButtonViewModel()
  21. var body: some View {
  22. VStack {
  23. HStack {
  24. VStack {
  25. GoogleSignInButton(viewModel: vm, action: authViewModel.signIn)
  26. .accessibilityIdentifier("GoogleSignInButton")
  27. .accessibility(hint: Text("Sign in with Google button."))
  28. .padding()
  29. VStack {
  30. HStack {
  31. Text("Button style:")
  32. .padding(.leading)
  33. Picker("", selection: $vm.style) {
  34. ForEach(GoogleSignInButtonStyle.allCases) { style in
  35. Text(style.rawValue.capitalized)
  36. .tag(GoogleSignInButtonStyle(rawValue: style.rawValue)!)
  37. }
  38. }
  39. Spacer()
  40. }
  41. HStack {
  42. Text("Button color:")
  43. .padding(.leading)
  44. Picker("", selection: $vm.scheme) {
  45. ForEach(GoogleSignInButtonColorScheme.allCases) { scheme in
  46. Text(scheme.rawValue.capitalized)
  47. .tag(GoogleSignInButtonColorScheme(rawValue: scheme.rawValue)!)
  48. }
  49. }
  50. Spacer()
  51. }
  52. HStack {
  53. Text("Button state:")
  54. .padding(.leading)
  55. Picker("", selection: $vm.state) {
  56. ForEach(GoogleSignInButtonState.allCases) { state in
  57. Text(state.rawValue.capitalized)
  58. .tag(GoogleSignInButtonState(rawValue: state.rawValue)!)
  59. }
  60. }
  61. Spacer()
  62. }
  63. }
  64. #if os(iOS)
  65. .pickerStyle(.segmented)
  66. #endif
  67. }
  68. }
  69. Spacer()
  70. }
  71. }
  72. }