react-native-navigation的迁移库

RNNOverlayManager.m 1.2KB

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