Переглянути джерело

Adds segmented controls to sample to preview button styling

Fixes 125
Matthew Mathias 3 роки тому
батько
коміт
f5b7bb92b7

+ 9 - 3
GoogleSignInSwift/Sources/GoogleSignInButtonStyling.swift

@@ -51,29 +51,35 @@ let googleImageName = "google"
 ///
 /// The minimum size of the button depends on the language used for text.
 @available(iOS 13.0, macOS 10.15, *)
-public enum GoogleSignInButtonStyle {
+public enum GoogleSignInButtonStyle: String, Identifiable, CaseIterable {
   case standard
   case wide
   case icon
+
+  public var id: String { rawValue }
 }
 
 // MARK: - Button Color Scheme
 
 /// The color schemes supported by the sign-in button.
 @available(iOS 13.0, macOS 10.15, *)
-public enum GoogleSignInButtonColorScheme {
+public enum GoogleSignInButtonColorScheme: String, Identifiable, CaseIterable {
   case dark
   case light
+
+  public var id: String { rawValue }
 }
 
 // MARK: - Button State
 
 /// The state of the sign-in button.
 @available(iOS 13.0, macOS 10.15, *)
-public enum GoogleSignInButtonState {
+public enum GoogleSignInButtonState: String, Identifiable, CaseIterable {
   case normal
   case disabled
   case pressed
+
+  public var id: String { rawValue }
 }
 
 // MARK: - Colors

+ 42 - 3
Samples/Swift/DaysUntilBirthday/Shared/Views/SignInView.swift

@@ -19,13 +19,52 @@ import GoogleSignInSwift
 
 struct SignInView: View {
   @EnvironmentObject var authViewModel: AuthenticationViewModel
+  @ObservedObject var vm = GoogleSignInButtonViewModel()
 
   var body: some View {
     VStack {
       HStack {
-        GoogleSignInButton(action: authViewModel.signIn)
-          .accessibility(hint: Text("Sign in with Google button."))
-          .padding()
+        VStack {
+          GoogleSignInButton(viewModel: vm, action: authViewModel.signIn)
+            .accessibility(hint: Text("Sign in with Google button."))
+            .padding()
+          VStack {
+            HStack {
+              Text("Button style:")
+                .padding(.leading)
+              Picker("Select button style", selection: $vm.style) {
+                ForEach(GoogleSignInButtonStyle.allCases) { style in
+                  Text(style.rawValue.capitalized)
+                    .tag(GoogleSignInButtonStyle(rawValue: style.rawValue)!)
+                }
+              }
+              Spacer()
+            }
+            HStack {
+              Text("Button color:")
+                .padding(.leading)
+              Picker("Select button color", selection: $vm.scheme) {
+                ForEach(GoogleSignInButtonColorScheme.allCases) { scheme in
+                  Text(scheme.rawValue.capitalized)
+                    .tag(GoogleSignInButtonColorScheme(rawValue: scheme.rawValue)!)
+                }
+              }
+              Spacer()
+            }
+            HStack {
+              Text("Button state:")
+                .padding(.leading)
+              Picker("Select button state", selection: $vm.state) {
+                ForEach(GoogleSignInButtonState.allCases) { state in
+                  Text(state.rawValue.capitalized)
+                    .tag(GoogleSignInButtonState(rawValue: state.rawValue)!)
+                }
+              }
+              Spacer()
+            }
+          }
+          .pickerStyle(.automatic)
+        }
       }
       Spacer()
     }