react-native-navigation的迁移库

RNNBridgeModule.m 1.6KB

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