findTopMostViewController

private fun findTopMostViewController(rootViewController: UIViewController?): UIViewController?(source)

Recursively traverses the view controller hierarchy to find the visible controller.

It handles:

  • Presented View Controllers (Modals)

  • UINavigationController (Visible Child)

  • UITabBarController (Selected Child)

Return

The top-most visible UIViewController.

Parameters

rootViewController

The starting point for the search, typically the key window's root.