react-native-navigation的迁移库

RNNModalManager.m 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. -(void)dismissAllModals {
  20. UIViewController *root = UIApplication.sharedApplication.delegate.window.rootViewController;
  21. [root dismissViewControllerAnimated:YES completion:nil];
  22. [self.store.modalsToDismissArray removeAllObjects];
  23. }
  24. #pragma mark - private
  25. -(void)removePendingNextModalIfOnTop {
  26. NSString *containerId = [self.store.modalsToDismissArray lastObject];
  27. UIViewController *modalToDismiss = [self.store findContainerForId:containerId];
  28. if(!modalToDismiss) {
  29. return;
  30. }
  31. if (modalToDismiss == [self topPresentedVC]) {
  32. [modalToDismiss dismissViewControllerAnimated:YES completion:^{
  33. [self.store.modalsToDismissArray removeObject:containerId];
  34. [self removePendingNextModalIfOnTop];
  35. }];
  36. }
  37. }
  38. -(UIViewController*)topPresentedVC {
  39. UIViewController *root = UIApplication.sharedApplication.delegate.window.rootViewController;
  40. while(root.presentedViewController) {
  41. root = root.presentedViewController;
  42. }
  43. return root;
  44. }
  45. @end