react-native-navigation的迁移库

RNNNavigationStackManager.m 1.6KB

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*)containerId {
  27. UIViewController *vc = [_store findContainerForId:containerId];
  28. if (vc) {
  29. UINavigationController *nvc = [vc navigationController];
  30. if(nvc) {
  31. NSArray *poppedVCs = [nvc popToViewController:vc animated:YES];
  32. [self removePopedViewControllers:poppedVCs];
  33. }
  34. }
  35. }
  36. -(void) popToRoot:(NSString*)containerId {
  37. UIViewController* vc = [_store findContainerForId:containerId];
  38. UINavigationController* nvc = [vc navigationController];
  39. NSArray* poppedVCs = [nvc popToRootViewControllerAnimated:YES];
  40. [self removePopedViewControllers:poppedVCs];
  41. }
  42. -(void)removePopedViewControllers:(NSArray*)viewControllers {
  43. for (UIViewController *popedVC in viewControllers) {
  44. [_store removeContainerByViewControllerInstance:popedVC];
  45. }
  46. }
  47. @end