react-native-navigation的迁移库

RNNCommandsHandler.m 2.2KB

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