react-native-navigation的迁移库

RNNOverlayManager.m 1.3KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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 makeKeyAndVisible];
  16. }
  17. - (void)dismissOverlay:(UIViewController*)viewController {
  18. RNNOverlayWindow* overlayWindow = [self findWindowByRootViewController:viewController];
  19. [overlayWindow.previousWindow makeKeyWindow];
  20. [self detachOverlayWindow:overlayWindow];
  21. }
  22. #pragma mark - private
  23. - (void)detachOverlayWindow:(UIWindow *)overlayWindow {
  24. [overlayWindow setHidden:YES];
  25. [overlayWindow setRootViewController:nil];
  26. [_overlayWindows removeObject:overlayWindow];
  27. }
  28. - (RNNOverlayWindow *)findWindowByRootViewController:(UIViewController *)viewController {
  29. for (RNNOverlayWindow* window in _overlayWindows) {
  30. if ([window.rootViewController isEqual:viewController]) {
  31. return window;
  32. }
  33. }
  34. return nil;
  35. }
  36. @end