react-native-navigation的迁移库

RNNBridgeModule.m 1.7KB

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