react-native-navigation的迁移库

RNNOverlayManager.m 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #import "RNNOverlayManager.h"
  2. #import "RNNErrorHandler.h"
  3. #import "RNNOverlayWindow.h"
  4. @implementation RNNOverlayManager {
  5. NSMutableDictionary* _overlayDict;
  6. RNNStore* _store;
  7. RNNOverlayWindow *_overlayWindow;
  8. }
  9. - (instancetype)initWithStore:(RNNStore *)store {
  10. self = [super init];
  11. _overlayDict = [[NSMutableDictionary alloc] init];
  12. _store = store;
  13. return self;
  14. }
  15. #pragma mark - public
  16. - (void)showOverlay:(RNNRootViewController *)viewController completion:(RNNTransitionCompletionBlock)completion {
  17. [self cacheOverlay:viewController];
  18. _overlayWindow = [[RNNOverlayWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
  19. [_overlayWindow setWindowLevel:UIWindowLevelNormal];
  20. [_overlayWindow setRootViewController:viewController];
  21. [_overlayWindow makeKeyAndVisible];
  22. completion();
  23. }
  24. - (void)dismissOverlay:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)reject {
  25. RNNRootViewController* viewController = [_overlayDict objectForKey:componentId];
  26. if (viewController) {
  27. [self removeCachedOverlay:viewController];
  28. completion();
  29. } else {
  30. [RNNErrorHandler reject:reject withErrorCode:1010 errorDescription:@"ComponentId not found"];
  31. }
  32. }
  33. #pragma mark - private
  34. - (void)cacheOverlay:(RNNRootViewController*)viewController {
  35. [_overlayDict setObject:viewController forKey:viewController.componentId];
  36. }
  37. - (void)removeCachedOverlay:(RNNRootViewController*)viewController {
  38. [_overlayWindow setRootViewController:nil];
  39. [_overlayWindow resignKeyWindow];
  40. _overlayWindow = nil;
  41. [_overlayDict removeObjectForKey:viewController.componentId];
  42. [_store removeComponent:viewController.componentId];
  43. }
  44. @end