react-native-navigation的迁移库

RNNNavigationStackManager.m 1.6KB

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