react-native-navigation的迁移库

RNNOverlayManager.m 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. viewController.view.backgroundColor = [UIColor clearColor];
  14. [overlayWindow setWindowLevel:UIWindowLevelNormal];
  15. [overlayWindow setRootViewController:viewController];
  16. [overlayWindow makeKeyAndVisible];
  17. }
  18. - (void)dismissOverlay:(UIViewController*)viewController {
  19. UIWindow* overlayWindow = [self findWindowByRootViewController:viewController];
  20. [self detachOverlayWindow:overlayWindow];
  21. }
  22. #pragma mark - private
  23. - (void)detachOverlayWindow:(UIWindow *)overlayWindow {
  24. [overlayWindow setHidden:YES];
  25. [overlayWindow setRootViewController:nil];
  26. [overlayWindow resignKeyWindow];
  27. [self assignKeyWindow];
  28. [_overlayWindows removeObject:overlayWindow];
  29. }
  30. - (void)assignKeyWindow {
  31. NSArray* windows = [[[UIApplication sharedApplication].windows reverseObjectEnumerator] allObjects];
  32. for (UIWindow* window in windows) {
  33. if (window.rootViewController) {
  34. [window makeKeyAndVisible];
  35. return;
  36. }
  37. }
  38. }
  39. - (UIWindow *)findWindowByRootViewController:(UIViewController *)viewController {
  40. for (UIWindow* window in _overlayWindows) {
  41. if ([window.rootViewController isEqual:viewController]) {
  42. return window;
  43. }
  44. }
  45. return nil;
  46. }
  47. @end