UIWindow+FLEX.m 1014 B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // UIWindow+FLEX.m
  3. // FLEX
  4. //
  5. // Created by Kevin Bradley on 12/23/20.
  6. // Copyright © 2020 Flipboard. All rights reserved.
  7. //
  8. #import "UIWindow+FLEX.h"
  9. @implementation UIWindow (FLEX)
  10. - (UIViewController *)visibleViewController {
  11. UIViewController *rootViewController = self.rootViewController;
  12. return [UIWindow getVisibleViewControllerFrom:rootViewController];
  13. }
  14. + (UIViewController *) getVisibleViewControllerFrom:(UIViewController *) vc {
  15. if ([vc isKindOfClass:[UINavigationController class]]) {
  16. return [UIWindow getVisibleViewControllerFrom:[((UINavigationController *) vc) visibleViewController]];
  17. } else if ([vc isKindOfClass:[UITabBarController class]]) {
  18. return [UIWindow getVisibleViewControllerFrom:[((UITabBarController *) vc) selectedViewController]];
  19. } else {
  20. if (vc.presentedViewController) {
  21. return [UIWindow getVisibleViewControllerFrom:vc.presentedViewController];
  22. } else {
  23. return vc;
  24. }
  25. }
  26. }
  27. @end