react-native-navigation的迁移库

RNNCommandsHandler.m 2.4KB

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