react-native-navigation的迁移库

RNNNavigationStackManager.m 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 toContainerId:(NSString*)toContainerId {
  27. UIViewController *vc = [_store findContainerForId:containerId];
  28. UINavigationController *nvc = [vc navigationController];
  29. UIViewController *toVC = [_store findContainerForId:toContainerId];
  30. if (vc && toVC) {
  31. [nvc popToViewController:toVC animated:YES];
  32. // TODO - remove the poped vcs from store
  33. }
  34. }
  35. -(void) popToRoot:(NSString*)containerId {
  36. UIViewController* vc = [_store findContainerForId:containerId];
  37. UINavigationController* nvc = [vc navigationController];
  38. [nvc popToRootViewControllerAnimated:YES];
  39. }
  40. @end