Firebaseui-ios: Suggestion: Allow Custom AuthPickerViewController to access authViewController Navigation Controller

Created on 27 Jun 2017  路  3Comments  路  Source: firebase/FirebaseUI-iOS

For my project I wanted to make some changes to the navigation bar of the auth view, but wanted to keep all my UI customisation in my customised FUIAuthPickerViewController.

Unfortunately, as of right now, accessing the navigation controller from the AuthPicker through self.navigationController doesn't appear to work properly (any changes are not visible in the UI) . At the same time there doesn't seem to be any easy way to access the AuthPicker of a given authViewController once it has been added which makes the whole thing even more tricky.

To be fair I am relatively new to iOS development so maybe i'm just missing something obvious but in order to work around this I ended up having to store the authViewController in a semi-static way and then access and customise it in the viewWillAppear of my AuthPicker. This seems very iffy in comparison to the more normal way of just being able to use self.navigationController.

I don't know if this is something many people would want, and i've managed to work around it but it feels like it would be nice if there was some way to access the auth UI's navigation controller easily, either through self.navigationController or some kind of custom implementation.

Another option would be making it easy to access the AuthPicker controller from the authViewController (eg. authViewController.picker) since then i could just call a function on my picker and manually pass in the authViewController later.

my workaround code in case someone finds this while trying to solve the same problem i was:
```
override func viewWillAppear(_ animated: Bool){
customiseNavigationController(UserManager.getInstance().authViewController!)
}

func customiseNavigationController(_ nav: UINavigationController){
    nav.navigationBar.setBackgroundImage(UIImage(), for: .default)
    nav.navigationBar.shadowImage = UIImage()
    nav.navigationBar.isTranslucent = true
    nav.title = ""
}

`

feature request question

Most helpful comment

@Seekerofpie I see what you mean.
Can you please try to access self.navigationController in viewWillAppear:

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];

  //update state of all UI elements (e g disable 'Next' buttons)
  [self updateEmailValue:_emailTextField];
  self.navigationController.navigationBar.hidden = NO;
  self.navigationController.navigationBar.barTintColor = [UIColor redColor];
  self.navigationController.navigationBar.translucent = YES;
  self.title = @"test";
}

We are setting all fields after custom controller's viewDidLoad is called.
As well if you need to have access to picker you can pass it as an argument to your custom Controller during initialization

I'm going to change logic of view initialization later.

@Seekerofpie please let me know if workaround with self.navigationController and viewWillAppear: worked for you.

All 3 comments

@Seekerofpie I see what you mean.
Can you please try to access self.navigationController in viewWillAppear:

- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];

  //update state of all UI elements (e g disable 'Next' buttons)
  [self updateEmailValue:_emailTextField];
  self.navigationController.navigationBar.hidden = NO;
  self.navigationController.navigationBar.barTintColor = [UIColor redColor];
  self.navigationController.navigationBar.translucent = YES;
  self.title = @"test";
}

We are setting all fields after custom controller's viewDidLoad is called.
As well if you need to have access to picker you can pass it as an argument to your custom Controller during initialization

I'm going to change logic of view initialization later.

@Seekerofpie please let me know if workaround with self.navigationController and viewWillAppear: worked for you.

Yep self.navigationController does work in viewWillAppear. Thanks for the tip! kicking myself that i didn't try that now :)

FUIAuth.authViewController() returns an UINavigationController. So this is the best and easiest way to accomplish what. you want:

guard let authUI = FUIAuth.defaultAuthUI() else { return }
let authController = authUI.authViewController()
authController.navigationBar.barTintColor = .red

Also, you can use UIAppearence.

In your application:didFinishLaunchingWithOptions: do:

UINavigationBar.appearance().barTintColor = .red

The main problem is I still cannot find a way to change the color of GoogleSignIn / FacebookSignIn / TwitterSignIn pages' color. Any ideas?

Was this page helpful?
0 / 5 - 0 ratings