google / GoogleSignIn-iOS

Enables iOS and macOS apps to sign in with Google.
https://developers.google.com/identity/sign-in/ios
Apache License 2.0
455 stars 181 forks source link

Update SignInView.swift #404

Closed movsianikov closed 1 month ago

movsianikov commented 2 months ago

Fix issue with declaration of GoogleSignInButtonViewModel variable. Switching to @StateObject from @ObservedObject allows to customize the button using constructor, otherwise - the customization doesn't work.

google-cla[bot] commented 2 months ago

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

mdmathias commented 2 months ago

Can you clarify what you mean by "allows to customize the button using constructor, otherwise - the customization doesn't work?" I am not sure what you're fixing.

movsianikov commented 2 months ago

Can you clarify what you mean by "allows to customize the button using constructor, otherwise - the customization doesn't work?" I am not sure what you're fixing.

Hi @mdmathias , of course! Here you go:

  1. With the current approach this customization does NOT work: @ObservedObject private var vm = GoogleSignInButtonViewModel(scheme: .dark, style: .wide, state: .normal)
  2. In order to make it work (workaround), I've customized it in the init() method like this:
    init() {
        vm.style = .wide
        vm.scheme = .dark
    }
  3. But the correct way, since the instance of the GoogleSignInButtonViewModel created in the SignInView, would be to declare it as @StateObject, then the customization will work fine without init() method: @ObservedObject private var vm = GoogleSignInButtonViewModel(scheme: .dark, style: .wide, state: .normal)

Please let me know if you have any questions, comments, or concerns.

Thank you!

Best regards, MAKSYM OVSIANIKOV

mdmathias commented 2 months ago

@movsianikov I'm sorry! I still don't understand what you mean by the "customization" not working. In SignInView.swift, if you create the vm with a different scheme (e.g., .dark), then the button will be drawn with the dark blue background.

struct SignInView: View {
  @EnvironmentObject var authViewModel: AuthenticationViewModel
  @ObservedObject var vm = GoogleSignInButtonViewModel(scheme: .dark)
...
Screenshot 2024-05-03 at 9 17 49 AM
mdmathias commented 1 month ago

I am closing this pull request due to inactivity.