react-native-navigation的迁移库

RNNModalManager.m 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #import "RNNModalManager.h"
  2. @interface RNNModalManager ()
  3. @property RNNStore *store;
  4. @end
  5. @implementation RNNModalManager
  6. -(instancetype)initWithStore:(RNNStore*)store {
  7. self = [super init];
  8. self.store = store;
  9. return self;
  10. }
  11. -(void)showModal:(UIViewController *)viewController {
  12. UIViewController *topVC = [self topPresentedVC];
  13. [topVC presentViewController:viewController animated:YES completion:nil];
  14. }
  15. -(void)dismissModal:(NSString *)containerId {
  16. [self.store.modalsToDismissArray addObject:containerId];
  17. [self removePendingNextModalIfOnTop];
  18. }
  19. #pragma mark - private
  20. -(void)removePendingNextModalIfOnTop {
  21. NSString *containerId = [self.store.modalsToDismissArray lastObject];
  22. UIViewController *modalToDismiss = [self.store findContainerForId:containerId];
  23. if(!modalToDismiss) {
  24. return;
  25. }
  26. if (modalToDismiss == [self topPresentedVC]) {
  27. [modalToDismiss dismissViewControllerAnimated:YES completion:^{
  28. [self.store.modalsToDismissArray removeObject:containerId];
  29. [self removePendingNextModalIfOnTop];
  30. }];
  31. }
  32. }
  33. -(UIViewController*)topPresentedVC {
  34. UIViewController *root = UIApplication.sharedApplication.delegate.window.rootViewController;
  35. while(root.presentedViewController) {
  36. root = root.presentedViewController;
  37. }
  38. return root;
  39. }
  40. @end