react-native-navigation的迁移库

RNNNavigationStackManager.m 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #import "RNNNavigationStackManager.h"
  2. @implementation RNNNavigationStackManager {
  3. RNNStore *_store;
  4. }
  5. -(instancetype)initWithStore:(RNNStore*)store {
  6. self = [super init];
  7. _store = store;
  8. return self;
  9. }
  10. -(void)push:(UIViewController *)newTop onTop:(NSString *)containerId {
  11. UIViewController *vc = [_store findContainerForId:containerId];
  12. [[vc navigationController] pushViewController:newTop animated:YES];
  13. }
  14. -(void)pop:(NSString *)containerId {
  15. UIViewController* vc = [_store findContainerForId:containerId];
  16. UINavigationController* nvc = [vc navigationController];
  17. if ([nvc topViewController] == vc) {
  18. [nvc popViewControllerAnimated:YES];
  19. } else {
  20. NSMutableArray * vcs = nvc.viewControllers.mutableCopy;
  21. [vcs removeObject:vc];
  22. [nvc setViewControllers:vcs animated:YES];
  23. }
  24. [_store removeContainer:containerId];
  25. }
  26. -(void)popTo:(NSString*)toContainerId fromContainerId:(NSString*)fromContainerId {
  27. UIViewController *vc = [_store findContainerForId:fromContainerId];
  28. UINavigationController *nvc = [vc navigationController];
  29. UIViewController *toVC = [_store findContainerForId:toContainerId];
  30. if (vc && toVC) {
  31. NSArray *poppedVCs = [nvc popToViewController:toVC animated:YES];
  32. [self removePopedViewControllers:poppedVCs];
  33. }
  34. }
  35. -(void) popToRoot:(NSString*)containerId {
  36. UIViewController* vc = [_store findContainerForId:containerId];
  37. UINavigationController* nvc = [vc navigationController];
  38. NSArray* poppedVCs = [nvc popToRootViewControllerAnimated:YES];
  39. [self removePopedViewControllers:poppedVCs];
  40. }
  41. -(void)removePopedViewControllers:(NSArray*)viewControllers {
  42. for (UIViewController *popedVC in viewControllers) {
  43. [_store removeContainerByViewControllerInstance:popedVC];
  44. }
  45. }
  46. @end