New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customize the generated viewController FIRAuthUI.authUI().authViewController() #87

Closed
jerydarkside opened this Issue Jul 18, 2016 · 6 comments

Comments

Projects
None yet
4 participants
@jerydarkside

jerydarkside commented Jul 18, 2016

Details:

  1. Swift:
  2. iOS 9:
  3. Firebase UI Version: 0.4.0

Explanation of your issue

There is no easy way to customize the first view controller of FIRAuthUI.authUI()
If I try to add a background like that:

 let authUI = FIRAuthUI.authUI()
 authUI?.delegate = self

 let googleAuthUI = FIRGoogleAuthUI(clientID: ".......")
 authUI?.signInProviders = [googleAuthUI!]

let authViewController = authUI?.authViewController()
let backgroundImageView = UIImageView(image: UIImage(named: "background"))
authViewController?.view.insertSubview(backgroundImageView, atIndex: 0)

self.presentViewController(authViewController!, animated: true, completion: nil)

my background is hidden behind a tableview generated by authViewController.

capture d ecran 2016-07-19 a 01 14 06

In one of Firebase conf (https://youtu.be/0ucjYG_JrEE?t=39m14s), they talk about subclassing in iOS to customize the generated view controllers. But I can't find in the SDK where to do that.

I've been searching for quite a while. Can you help me?

Thank you

(If there is a more elegant way, I would like to avoid to loop through all viewController subviews to detect the tableView and make its background transparent)

@ch40w31

This comment has been minimized.

Show comment
Hide comment
@ch40w31

ch40w31 Jul 18, 2016

Contributor

FIRAuthUI has a delegate method called authPickerViewControllerForAuthUI:. You can implement that method to provide an instance of your subclass of FIRAuthPickerViewController. It should be much easier to customize the first screen in the subclass.

Note that authUI?.authViewController() itself is not the first screen. It's the UINavigationController that wraps all view controllers rather.

Contributor

ch40w31 commented Jul 18, 2016

FIRAuthUI has a delegate method called authPickerViewControllerForAuthUI:. You can implement that method to provide an instance of your subclass of FIRAuthPickerViewController. It should be much easier to customize the first screen in the subclass.

Note that authUI?.authViewController() itself is not the first screen. It's the UINavigationController that wraps all view controllers rather.

@jerydarkside

This comment has been minimized.

Show comment
Hide comment
@jerydarkside

jerydarkside Jul 18, 2016

Ah yes! Thank you! That's exactly what I've been searching!

jerydarkside commented Jul 18, 2016

Ah yes! Thank you! That's exactly what I've been searching!

@shugums

This comment has been minimized.

Show comment
Hide comment
@shugums

shugums Sep 8, 2016

Could you possibly explain how to do this in more detail? I created a subclass ofFIRAuthPickerViewController. I am just not sure how to provide FIRAuthUI with an instance of the subclass by implementing the delegate method authPickerViewControllerForAuthUI (taken from Auth Documentation). Essentially, where do I place the below provided code? Thanks!

func authPickerViewControllerForAuthUI(authUI: FIRAuthUI) -> FIRAuthPickerViewController {
   return  CustomAuthPickerViewController(authUI: authUI)
}

shugums commented Sep 8, 2016

Could you possibly explain how to do this in more detail? I created a subclass ofFIRAuthPickerViewController. I am just not sure how to provide FIRAuthUI with an instance of the subclass by implementing the delegate method authPickerViewControllerForAuthUI (taken from Auth Documentation). Essentially, where do I place the below provided code? Thanks!

func authPickerViewControllerForAuthUI(authUI: FIRAuthUI) -> FIRAuthPickerViewController {
   return  CustomAuthPickerViewController(authUI: authUI)
}
@morganchen12

This comment has been minimized.

Show comment
Hide comment
@morganchen12

morganchen12 Sep 8, 2016

Contributor

That code goes on any object conforming to FIRAuthUIDelegate. Then, before instantiating your auth flow, set the FIRAuthUI delegate to your delegate object.

delegate is a bit of a misnomer, later on we should rename this to dataSource and split this method out of the delegate protocol.

Contributor

morganchen12 commented Sep 8, 2016

That code goes on any object conforming to FIRAuthUIDelegate. Then, before instantiating your auth flow, set the FIRAuthUI delegate to your delegate object.

delegate is a bit of a misnomer, later on we should rename this to dataSource and split this method out of the delegate protocol.

@shugums

This comment has been minimized.

Show comment
Hide comment
@shugums

shugums Sep 8, 2016

Follow up question (new to swift/xcode):

The object you are referencing that should conform to the FIRAuthUIDelegate should be the subclassed FIRAuthPickerViewController controller? And if that’s true, then what are the functions that need to be passed in a delegate object for this controller to that it can be set to the FIRAuthUI? If we are loading this file as the initial root controller in the app delegate do we set that equal to the authUI?.authViewController()? Should it take the custom class that we have created or should we call the reference to the name of the custom class?

Thanks in advance!

shugums commented Sep 8, 2016

Follow up question (new to swift/xcode):

The object you are referencing that should conform to the FIRAuthUIDelegate should be the subclassed FIRAuthPickerViewController controller? And if that’s true, then what are the functions that need to be passed in a delegate object for this controller to that it can be set to the FIRAuthUI? If we are loading this file as the initial root controller in the app delegate do we set that equal to the authUI?.authViewController()? Should it take the custom class that we have created or should we call the reference to the name of the custom class?

Thanks in advance!

@morganchen12

This comment has been minimized.

Show comment
Hide comment
@morganchen12

morganchen12 Sep 8, 2016

Contributor

Any type can conform to FIRAuthUIDelegate. To set the delegate on the FIRAuthUI instance, assuming you're using the default FIRAuthUI instance:

let authDelegate = /* instantiate your auth delegate object */
FIRAuthUI.defaultAuthUI().delegate = authDelegate

Which type in particular you want your delegate to be is up to you.

Contributor

morganchen12 commented Sep 8, 2016

Any type can conform to FIRAuthUIDelegate. To set the delegate on the FIRAuthUI instance, assuming you're using the default FIRAuthUI instance:

let authDelegate = /* instantiate your auth delegate object */
FIRAuthUI.defaultAuthUI().delegate = authDelegate

Which type in particular you want your delegate to be is up to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment