react-native-navigation的迁移库

RNNOverlayManager.m 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. #import "RNNOverlayManager.h"
  2. #import "RNNErrorHandler.h"
  3. @implementation RNNOverlayManager {
  4. NSMutableDictionary* _overlayDict;
  5. RNNStore* _store;
  6. }
  7. - (instancetype)initWithStore:(RNNStore *)store {
  8. self = [super init];
  9. _overlayDict = [[NSMutableDictionary alloc] init];
  10. _store = store;
  11. return self;
  12. }
  13. #pragma mark - public
  14. - (void)showOverlay:(RNNRootViewController *)viewController completion:(RNNTransitionCompletionBlock)completion {
  15. [self cacheOverlay:viewController];
  16. [[[UIApplication sharedApplication] keyWindow] addSubview:viewController.view];
  17. completion();
  18. }
  19. - (void)dismissOverlay:(NSString*)componentId completion:(RNNTransitionCompletionBlock)completion rejection:(RNNTransitionRejectionBlock)reject {
  20. RNNRootViewController* viewController = [_overlayDict objectForKey:componentId];
  21. if (viewController) {
  22. [self removeCachedOverlay:viewController];
  23. completion();
  24. } else {
  25. [RNNErrorHandler reject:reject withErrorCode:1010 errorDescription:@"ComponentId not found"];
  26. }
  27. }
  28. #pragma mark - private
  29. - (void)cacheOverlay:(RNNRootViewController*)viewController {
  30. [_overlayDict setObject:viewController forKey:viewController.componentId];
  31. }
  32. - (void)removeCachedOverlay:(RNNRootViewController*)viewController {
  33. [viewController.view removeFromSuperview];
  34. [_overlayDict removeObjectForKey:viewController.componentId];
  35. [_store removeComponent:viewController.componentId];
  36. }
  37. @end