react-native-navigation的迁移库

RNNBridgeModule.m 1.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. RCT_EXPORT_METHOD(pop:(NSString*)containerId)
  25. {
  26. [self assertReady];
  27. //TODO implement correctly
  28. id vc = [UIApplication.sharedApplication.delegate.window.rootViewController childViewControllers][0];
  29. [[vc navigationController] popViewControllerAnimated:true];
  30. }
  31. -(void)assertReady
  32. {
  33. if (!RNN.instance.isReadyToReceiveCommands) {
  34. @throw [NSException exceptionWithName:@"BridgeNotLoadedError" reason:@"Bridge not yet loaded! Send commands after Navigation.events().onAppLaunched() has been called." userInfo:nil];
  35. }
  36. }
  37. @end