react-native-navigation的迁移库

RNNBridgeModule.m 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. RCTExecuteOnMainQueue(^{
  19. [self->_commandsHandler setRoot:layout commandId:commandId completion:^{
  20. resolve(layout);
  21. }];
  22. });
  23. }
  24. RCT_EXPORT_METHOD(mergeOptions:(NSString*)componentId options:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  25. RCTExecuteOnMainQueue(^{
  26. [self->_commandsHandler mergeOptions:componentId options:options completion:^{
  27. resolve(componentId);
  28. }];
  29. });
  30. }
  31. RCT_EXPORT_METHOD(setDefaultOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  32. RCTExecuteOnMainQueue(^{
  33. [self->_commandsHandler setDefaultOptions:options completion:^{
  34. resolve(nil);
  35. }];
  36. });
  37. }
  38. RCT_EXPORT_METHOD(push:(NSString*)commandId componentId:(NSString*)componentId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  39. RCTExecuteOnMainQueue(^{
  40. [self->_commandsHandler push:componentId commandId:commandId layout:layout completion:^{
  41. resolve(componentId);
  42. } rejection:reject];
  43. });
  44. }
  45. RCT_EXPORT_METHOD(pop:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  46. RCTExecuteOnMainQueue(^{
  47. [self->_commandsHandler pop:componentId commandId:commandId mergeOptions:(NSDictionary*)options completion:^{
  48. resolve(componentId);
  49. } rejection:reject];
  50. });
  51. }
  52. RCT_EXPORT_METHOD(setStackRoot:(NSString*)commandId componentId:(NSString*)componentId children:(NSArray*)children resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  53. RCTExecuteOnMainQueue(^{
  54. [self->_commandsHandler setStackRoot:componentId commandId:commandId children:children completion:^{
  55. resolve(componentId);
  56. } rejection:reject];
  57. });
  58. }
  59. RCT_EXPORT_METHOD(popTo:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  60. RCTExecuteOnMainQueue(^{
  61. [self->_commandsHandler popTo:componentId commandId:commandId mergeOptions:options completion:^{
  62. resolve(componentId);
  63. } rejection:reject];
  64. });
  65. }
  66. RCT_EXPORT_METHOD(popToRoot:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  67. RCTExecuteOnMainQueue(^{
  68. [self->_commandsHandler popToRoot:componentId commandId:commandId mergeOptions:options completion:^{
  69. resolve(componentId);
  70. } rejection:reject];
  71. });
  72. }
  73. RCT_EXPORT_METHOD(showModal:(NSString*)commandId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  74. RCTExecuteOnMainQueue(^{
  75. [self->_commandsHandler showModal:layout commandId:commandId completion:^(NSString *componentId) {
  76. resolve(componentId);
  77. }];
  78. });
  79. }
  80. RCT_EXPORT_METHOD(dismissModal:(NSString*)commandId componentId:(NSString*)componentId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  81. RCTExecuteOnMainQueue(^{
  82. [self->_commandsHandler dismissModal:componentId commandId:commandId mergeOptions:options completion:^{
  83. resolve(componentId);
  84. } rejection:reject];
  85. });
  86. }
  87. RCT_EXPORT_METHOD(dismissAllModals:(NSString*)commandId mergeOptions:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  88. RCTExecuteOnMainQueue(^{
  89. [self->_commandsHandler dismissAllModals:options commandId:commandId completion:^{
  90. resolve(nil);
  91. }];
  92. });
  93. }
  94. RCT_EXPORT_METHOD(showOverlay:(NSString*)commandId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  95. RCTExecuteOnMainQueue(^{
  96. [self->_commandsHandler showOverlay:layout commandId:commandId completion:^{
  97. resolve(layout[@"id"]);
  98. }];
  99. });
  100. }
  101. RCT_EXPORT_METHOD(dismissOverlay:(NSString*)commandId componentId:(NSString*)componentId resolve:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  102. RCTExecuteOnMainQueue(^{
  103. [self->_commandsHandler dismissOverlay:componentId commandId:commandId completion:^{
  104. resolve(@(1));
  105. } rejection:reject];
  106. });
  107. }
  108. RCT_EXPORT_METHOD(getLaunchArgs:(NSString*)commandId :(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  109. NSArray* args = [[NSProcessInfo processInfo] arguments];
  110. resolve(args);
  111. }
  112. RCT_EXPORT_METHOD(getNavigationConstants:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  113. RCTExecuteOnMainQueue(^{
  114. resolve([Constants getConstants]);
  115. });
  116. }
  117. @end