react-native-navigation的迁移库

RNNOverlayManager.m 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #import "RNNOverlayManager.h"
  2. #import "RNNOverlayWindow.h"
  3. @implementation RNNOverlayManager
  4. - (instancetype)init {
  5. self = [super init];
  6. _overlayWindows = [[NSMutableArray alloc] init];
  7. return self;
  8. }
  9. #pragma mark - public
  10. - (void)showOverlay:(UIViewController *)viewController {
  11. UIWindow* overlayWindow = [[RNNOverlayWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  12. [_overlayWindows addObject:overlayWindow];
  13. [overlayWindow setWindowLevel:UIWindowLevelNormal];
  14. [overlayWindow setRootViewController:viewController];
  15. [overlayWindow makeKeyAndVisible];
  16. }
  17. - (void)dismissOverlay:(UIViewController*)viewController {
  18. UIWindow* overlayWindow = [self findWindowByRootViewController:viewController];
  19. [self detachOverlayWindow:overlayWindow];
  20. }
  21. #pragma mark - private
  22. - (void)detachOverlayWindow:(UIWindow *)overlayWindow {
  23. [overlayWindow setHidden:YES];
  24. [overlayWindow setRootViewController:nil];
  25. [overlayWindow resignKeyWindow];
  26. [self assignKeyWindow];
  27. [_overlayWindows removeObject:overlayWindow];
  28. }
  29. - (void)assignKeyWindow {
  30. NSArray* windows = [[[UIApplication sharedApplication].windows reverseObjectEnumerator] allObjects];
  31. for (UIWindow* window in windows) {
  32. if (window.rootViewController) {
  33. [window makeKeyAndVisible];
  34. return;
  35. }
  36. }
  37. }
  38. - (UIWindow *)findWindowByRootViewController:(UIViewController *)viewController {
  39. for (UIWindow* window in _overlayWindows) {
  40. if ([window.rootViewController isEqual:viewController]) {
  41. return window;
  42. }
  43. }
  44. return nil;
  45. }
  46. @end