react-native-navigation的迁移库

RNNModalManager.m 1.4KB

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