react-native-navigation的迁移库

RNNBridgeModule.m 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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(setOptions:(NSString*)containerId options:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  22. [_commandsHandler setOptions:containerId options:options completion:^{
  23. resolve(containerId);
  24. }];
  25. }
  26. RCT_EXPORT_METHOD(push:(NSString*)containerId layout:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  27. [_commandsHandler push:containerId layout:layout completion:^{
  28. resolve(containerId);
  29. }];
  30. }
  31. RCT_EXPORT_METHOD(pop:(NSString*)containerId options:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  32. [_commandsHandler pop:containerId options:(NSDictionary*)options completion:^{
  33. resolve(containerId);
  34. }];
  35. }
  36. RCT_EXPORT_METHOD(popTo:(NSString*)containerId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  37. [_commandsHandler popTo:containerId completion:^{
  38. resolve(containerId);
  39. }];
  40. }
  41. RCT_EXPORT_METHOD(popToRoot:(NSString*)containerId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  42. [_commandsHandler popToRoot:containerId completion:^{
  43. resolve(containerId);
  44. }];
  45. }
  46. RCT_EXPORT_METHOD(showModal:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  47. [_commandsHandler showModal:layout completion:^{
  48. resolve(nil);
  49. }];
  50. }
  51. RCT_EXPORT_METHOD(dismissModal:(NSString*)containerId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  52. [_commandsHandler dismissModal:containerId completion:^{
  53. resolve(containerId);
  54. }];
  55. }
  56. RCT_EXPORT_METHOD(dismissAllModals:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  57. [_commandsHandler dismissAllModalsWithCompletion:^{
  58. resolve(nil);
  59. }];
  60. }
  61. @end