SignInView.swift 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. .accessibility(hint: Text("Sign in with Google button."))
  27. .padding()
  28. VStack {
  29. HStack {
  30. Text("Button style:")
  31. .padding(.leading)
  32. Picker("", selection: $vm.style) {
  33. ForEach(GoogleSignInButtonStyle.allCases) { style in
  34. Text(style.rawValue.capitalized)
  35. .tag(GoogleSignInButtonStyle(rawValue: style.rawValue)!)
  36. }
  37. }
  38. Spacer()
  39. }
  40. HStack {
  41. Text("Button color:")
  42. .padding(.leading)
  43. Picker("", selection: $vm.scheme) {
  44. ForEach(GoogleSignInButtonColorScheme.allCases) { scheme in
  45. Text(scheme.rawValue.capitalized)
  46. .tag(GoogleSignInButtonColorScheme(rawValue: scheme.rawValue)!)
  47. }
  48. }
  49. Spacer()
  50. }
  51. HStack {
  52. Text("Button state:")
  53. .padding(.leading)
  54. Picker("", selection: $vm.state) {
  55. ForEach(GoogleSignInButtonState.allCases) { state in
  56. Text(state.rawValue.capitalized)
  57. .tag(GoogleSignInButtonState(rawValue: state.rawValue)!)
  58. }
  59. }
  60. Spacer()
  61. }
  62. }
  63. #if os(iOS)
  64. .pickerStyle(.segmented)
  65. #endif
  66. }
  67. }
  68. Spacer()
  69. }
  70. }
  71. }