react-native-navigation的迁移库

RNNBridgeModule.m 3.4KB

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