react-native-navigation的迁移库

RNNCommandsHandler.m 1.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #import "RNNCommandsHandler.h"
  2. #import "RNNModalManager.h"
  3. #import "RNNNavigationStackManager.h"
  4. @implementation RNNCommandsHandler {
  5. RNNControllerFactory *_controllerFactory;
  6. RNNStore *_store;
  7. RNNNavigationStackManager* _navigationStackManager;
  8. RNNModalManager* _modalManager;
  9. }
  10. -(instancetype) initWithStore:(RNNStore*)store controllerFactory:(RNNControllerFactory*)controllerFactory {
  11. self = [super init];
  12. _store = store;
  13. _controllerFactory = controllerFactory;
  14. _navigationStackManager = [[RNNNavigationStackManager alloc] initWithStore:_store];
  15. _modalManager = [[RNNModalManager alloc] initWithStore:_store];
  16. return self;
  17. }
  18. #pragma mark - public
  19. -(void) setRoot:(NSDictionary*)layout {
  20. [self assertReady];
  21. UIViewController *vc = [_controllerFactory createLayoutAndSaveToStore:layout];
  22. UIApplication.sharedApplication.delegate.window.rootViewController = vc;
  23. [UIApplication.sharedApplication.delegate.window makeKeyAndVisible];
  24. }
  25. -(void) push:(NSString*)containerId layout:(NSDictionary*)layout {
  26. [self assertReady];
  27. UIViewController *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
  28. [_navigationStackManager push:newVc onTop:containerId];
  29. }
  30. -(void) pop:(NSString*)containerId {
  31. [self assertReady];
  32. [_navigationStackManager pop:containerId];
  33. }
  34. -(void) showModal:(NSDictionary*)layout {
  35. [self assertReady];
  36. UIViewController *newVc = [_controllerFactory createLayoutAndSaveToStore:layout];
  37. [_modalManager showModal:newVc];
  38. }
  39. -(void) dismissModal:(NSString*)containerId {
  40. [self assertReady];
  41. [_modalManager dismissModal:containerId];
  42. }
  43. -(void) dismissAllModals {
  44. [self assertReady];
  45. [_modalManager dismissAllModals];
  46. }
  47. #pragma mark - private
  48. -(void) assertReady {
  49. if (!_store.isReadyToReceiveCommands) {
  50. @throw [NSException exceptionWithName:@"BridgeNotLoadedError" reason:@"Bridge not yet loaded! Send commands after Navigation.events().onAppLaunched() has been called." userInfo:nil];
  51. }
  52. }
  53. @end