react-native-navigation的迁移库

RNNBridgeModule.m 2.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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*)componentId options:(NSDictionary*)options resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  22. [_commandsHandler setOptions: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. }];
  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. }];
  40. }
  41. RCT_EXPORT_METHOD(popTo:(NSString*)componentId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  42. [_commandsHandler popTo:componentId completion:^{
  43. resolve(componentId);
  44. }];
  45. }
  46. RCT_EXPORT_METHOD(popToRoot:(NSString*)componentId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  47. [_commandsHandler popToRoot:componentId completion:^{
  48. resolve(componentId);
  49. }];
  50. }
  51. RCT_EXPORT_METHOD(showModal:(NSDictionary*)layout resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  52. [_commandsHandler showModal:layout completion:^{
  53. resolve(nil);
  54. }];
  55. }
  56. RCT_EXPORT_METHOD(dismissModal:(NSString*)componentId resolver:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  57. [_commandsHandler dismissModal:componentId completion:^{
  58. resolve(componentId);
  59. }];
  60. }
  61. RCT_EXPORT_METHOD(dismissAllModals:(RCTPromiseResolveBlock)resolve rejecter:(RCTPromiseRejectBlock)reject) {
  62. [_commandsHandler dismissAllModalsWithCompletion:^{
  63. resolve(nil);
  64. }];
  65. }
  66. @end