react-native-navigation的迁移库

RNNOverlayManager.m 1.6KB

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)showOverlayWindow:(RNNOverlayWindow *)overlayWindow {
  11. overlayWindow.previousWindow = [UIApplication sharedApplication].keyWindow;
  12. [_overlayWindows addObject:overlayWindow];
  13. overlayWindow.rootViewController.view.backgroundColor = [UIColor clearColor];
  14. [overlayWindow setWindowLevel:UIWindowLevelNormal];
  15. [overlayWindow setHidden: NO];
  16. }
  17. - (void)showOverlayWindowAsKeyWindow:(RNNOverlayWindow *)overlayWindow {
  18. [self showOverlayWindow:overlayWindow];
  19. [overlayWindow makeKeyWindow];
  20. }
  21. - (void)dismissOverlay:(UIViewController*)viewController {
  22. RNNOverlayWindow* overlayWindow = [self findWindowByRootViewController:viewController];
  23. [self detachOverlayWindow:overlayWindow];
  24. }
  25. - (void)dismissAllOverlays {
  26. for (RNNOverlayWindow* overlayWindow in [_overlayWindows reverseObjectEnumerator]) {
  27. [self detachOverlayWindow:overlayWindow];
  28. }
  29. }
  30. #pragma mark - private
  31. - (void)detachOverlayWindow:(RNNOverlayWindow *)overlayWindow {
  32. [overlayWindow.previousWindow makeKeyWindow];
  33. [overlayWindow setHidden:YES];
  34. [overlayWindow setRootViewController:nil];
  35. [_overlayWindows removeObject:overlayWindow];
  36. }
  37. - (RNNOverlayWindow *)findWindowByRootViewController:(UIViewController *)viewController {
  38. for (RNNOverlayWindow* window in _overlayWindows) {
  39. if ([window.rootViewController isEqual:viewController]) {
  40. return window;
  41. }
  42. }
  43. return nil;
  44. }
  45. @end