react-native-navigation的迁移库

RNNBridgeModule.m 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. #import "RNNBridgeModule.h"
  2. #import "Constants.h"
  3. @implementation RNNBridgeModule {
  4. RNNCommandsHandler* _commandsHandler;
  5. }
  6. @synthesize bridge = _bridge;
  7. RCT_EXPORT_MODULE();
  8. - (dispatch_queue_t)methodQueue {
  9. return dispatch_get_main_queue();
  10. }
  11. -(instancetype)initWithCommandsHandler:(RNNCommandsHandler *)commandsHandler {
  12. self = [super init];
  13. _commandsHandler = commandsHandler;
  14. return self;
  15. }
  16. #pragma mark - JS interface
  17. RCT_EXPORT_METHOD(setRoot:(NSString*)commandId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  18. [_commandsHandler setRoot:layout commandId:commandId completion:^{
  19. resolve(layout);
  20. }];
  21. }
  22. RCT_EXPORT_METHOD(mergeOptions:(NSString*)componentId options:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  23. [_commandsHandler mergeOptions:componentId options:options completion:^{
  24. resolve(componentId);
  25. }];
  26. }
  27. RCT_EXPORT_METHOD(setDefaultOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  28. [_commandsHandler setDefaultOptions:options completion:^{
  29. resolve(nil);
  30. }];
  31. }
  32. RCT_EXPORT_METHOD(push:(NSString*)commandId componentId:(NSString*)componentId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  33. [_commandsHandler push:componentId commandId:commandId layout:layout completion:^{
  34. resolve(componentId);
  35. } rejection:reject];
  36. }
  37. RCT_EXPORT_METHOD(pop:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  38. [_commandsHandler pop:componentId commandId:commandId mergeOptions:(NSDictionary*)options completion:^{
  39. resolve(componentId);
  40. } rejection:reject];
  41. }
  42. RCT_EXPORT_METHOD(setStackRoot:(NSString*)commandId componentId:(NSString*)componentId children:(NSArray*)children resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  43. [_commandsHandler setStackRoot:componentId commandId:commandId children:children completion:^{
  44. resolve(componentId);
  45. } rejection:reject];
  46. }
  47. RCT_EXPORT_METHOD(popTo:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  48. [_commandsHandler popTo:componentId commandId:commandId mergeOptions:options completion:^{
  49. resolve(componentId);
  50. } rejection:reject];
  51. }
  52. RCT_EXPORT_METHOD(popToRoot:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  53. [_commandsHandler popToRoot:componentId commandId:commandId mergeOptions:options completion:^{
  54. resolve(componentId);
  55. } rejection:reject];
  56. }
  57. RCT_EXPORT_METHOD(showModal:(NSString*)commandId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  58. [_commandsHandler showModal:layout commandId:commandId completion:^(NSString *componentId) {
  59. resolve(componentId);
  60. }];
  61. }
  62. RCT_EXPORT_METHOD(dismissModal:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  63. [_commandsHandler dismissModal:componentId commandId:commandId mergeOptions:options completion:^{
  64. resolve(componentId);
  65. } rejection:reject];
  66. }
  67. RCT_EXPORT_METHOD(dismissAllModals:(NSString*)commandId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  68. [_commandsHandler dismissAllModals:options commandId:commandId completion:^{
  69. resolve(nil);
  70. }];
  71. }
  72. RCT_EXPORT_METHOD(showOverlay:(NSString*)commandId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  73. [_commandsHandler showOverlay:layout commandId:commandId completion:^{
  74. resolve(layout[@"id"]);
  75. }];
  76. }
  77. RCT_EXPORT_METHOD(dismissOverlay:(NSString*)commandId componentId:(NSString*)componentId resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  78. [_commandsHandler dismissOverlay:componentId commandId:commandId completion:^{
  79. resolve(@(1));
  80. } rejection:reject];
  81. }
  82. RCT_EXPORT_METHOD(getLaunchArgs:(NSString*)commandId :(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  83. NSArray* args = [[NSProcessInfo processInfo] arguments];
  84. resolve(args);
  85. }
  86. RCT_EXPORT_METHOD(getNavigationConstants:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  87. resolve([Constants getConstants]);
  88. }
  89. @end