react-native-navigation的迁移库

RNNBridgeModule.m 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #import "RNNBridgeModule.h"
  2. #import "RNN.h"
  3. #import "RNNControllerFactory.h"
  4. #import "RNNReactRootViewCreator.h"
  5. #import "RNNStore.h"
  6. @implementation RNNBridgeModule
  7. RCT_EXPORT_MODULE();
  8. - (dispatch_queue_t)methodQueue
  9. {
  10. return dispatch_get_main_queue();
  11. }
  12. RCT_EXPORT_METHOD(setRoot:(NSDictionary*)layout)
  13. {
  14. [self assertReady];
  15. RNNControllerFactory *factory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new] store:[RNN instance].store];
  16. UIViewController *vc = [factory createLayout:layout];
  17. UIApplication.sharedApplication.delegate.window.rootViewController = vc;
  18. [UIApplication.sharedApplication.delegate.window makeKeyAndVisible];
  19. }
  20. RCT_EXPORT_METHOD(push:(NSString*)containerId layout:(NSDictionary*)layout)
  21. {
  22. [self assertReady];
  23. //TODO implement correctly
  24. RNNControllerFactory *factory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new] store:[RNN instance].store];
  25. UIViewController *newVc = [factory createLayout:layout];
  26. id vc = [[RNN instance].store findContainerForId:containerId];
  27. [[vc navigationController]pushViewController:newVc animated:true];
  28. }
  29. RCT_EXPORT_METHOD(pop:(NSString*)containerId)
  30. {
  31. [self assertReady];
  32. //TODO implement correctly
  33. id vc = [UIApplication.sharedApplication.delegate.window.rootViewController childViewControllers][0];
  34. [[vc navigationController] popViewControllerAnimated:true];
  35. }
  36. - (void)assertReady
  37. {
  38. if (![RNN instance].isReadyToReceiveCommands) {
  39. @throw [NSException exceptionWithName:@"BridgeNotLoadedError" reason:@"Bridge not yet loaded! Send commands after Navigation.events().onAppLaunched() has been called." userInfo:nil];
  40. }
  41. }
  42. @end