react-native-navigation的迁移库

RNNBridgeModule.m 1.1KB

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