react-native-navigation的迁移库

RNNNavigationStackManager.m 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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 *popedVCs = [nvc popToViewController:toVC animated:YES];
  32. for (UIViewController *popedVC in popedVCs) {
  33. [_store removeContainerByViewControllerInstance:popedVC];
  34. }
  35. }
  36. }
  37. -(void) popToRoot:(NSString*)containerId {
  38. UIViewController* vc = [_store findContainerForId:containerId];
  39. UINavigationController* nvc = [vc navigationController];
  40. [nvc popToRootViewControllerAnimated:YES];
  41. }
  42. @end