react-native-navigation的迁移库

RNNBridgeModule.m 1.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. UIViewController *vc = [factory createLayout:layout];
  16. UIApplication.sharedApplication.delegate.window.rootViewController = vc;
  17. [UIApplication.sharedApplication.delegate.window makeKeyAndVisible];
  18. }
  19. RCT_EXPORT_METHOD(push:(NSString*)containerId layout:(NSDictionary*)layout)
  20. {
  21. [self assertReady];
  22. //TODO implement correctly
  23. RNNControllerFactory *factory = [[RNNControllerFactory alloc] initWithRootViewCreator:[RNNReactRootViewCreator new]];
  24. UIViewController *newVc = [factory createLayout:layout];
  25. id vc = [UIApplication.sharedApplication.delegate.window.rootViewController childViewControllers][0];
  26. [[vc navigationController]pushViewController:newVc animated:true];
  27. }
  28. RCT_EXPORT_METHOD(pop:(NSString*)containerId)
  29. {
  30. [self assertReady];
  31. //TODO implement correctly
  32. id vc = [UIApplication.sharedApplication.delegate.window.rootViewController childViewControllers][0];
  33. [[vc navigationController] popViewControllerAnimated:true];
  34. }
  35. - (void)assertReady
  36. {
  37. if (![RNN instance].isReadyToReceiveCommands) {
  38. @throw [NSException exceptionWithName:@"BridgeNotLoadedError" reason:@"Bridge not yet loaded! Send commands after Navigation.events().onAppLaunched() has been called." userInfo:nil];
  39. }
  40. }
  41. @end