react-native-navigation的迁移库

RNNLayoutManager.m 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #import "RNNLayoutManager.h"
  2. #import "RNNLayoutProtocol.h"
  3. #import "UIViewController+LayoutProtocol.h"
  4. @implementation RNNLayoutManager
  5. + (UIViewController *)findComponentForId:(NSString *)componentId {
  6. for (UIWindow* window in UIApplication.sharedApplication.windows) {
  7. UIViewController* result = [self findChildComponentForParent:window.rootViewController ForId:componentId];
  8. if (result) {
  9. return result;
  10. }
  11. }
  12. return nil;
  13. }
  14. + (UIViewController *)findChildComponentForParent:(UIViewController *)parentViewController ForId:(NSString *)componentId {
  15. if ([parentViewController.layoutInfo.componentId isEqualToString:componentId]) {
  16. return parentViewController;
  17. }
  18. if (parentViewController.presentedViewController) {
  19. if ([parentViewController.presentedViewController.layoutInfo.componentId isEqualToString:componentId]) {
  20. return parentViewController.presentedViewController;
  21. }
  22. UIViewController* modalResult = [self findChildComponentForParent:parentViewController.presentedViewController ForId:componentId];
  23. if (modalResult) {
  24. return modalResult;
  25. }
  26. }
  27. for (UIViewController* childVC in parentViewController.childViewControllers) {
  28. UIViewController* result = [self findChildComponentForParent:childVC ForId:componentId];
  29. if (result) {
  30. return result;
  31. }
  32. }
  33. return nil;
  34. }
  35. @end