react-native-navigation的迁移库

RNNControllerFactory.m 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #import "RNNControllerFactory.h"
  2. #import "RNN.h"
  3. #import "RCTRootView.h"
  4. @implementation RNNControllerFactory
  5. -(UIViewController *)createRootViewController:(NSDictionary *)layout
  6. {
  7. return [self fromTree:layout];
  8. }
  9. -(UIViewController*)fromTree:(NSDictionary*)node
  10. {
  11. NSString* nodeType = node[@"type"];
  12. NSString* nodeId = node[@"id"];
  13. NSArray* children = node[@"children"];
  14. NSDictionary* data = node[@"data"];
  15. if ([nodeType isEqualToString:@"Container"])
  16. {
  17. return [self createContainer:nodeId data:data];
  18. } else if([nodeType isEqualToString:@"ContainerStack"])
  19. {
  20. return [self createContainerStack:nodeId data:data children:children];
  21. }
  22. @throw @"unknown container type";
  23. }
  24. -(UIViewController*)createContainer:(NSString*)containerId data:(NSDictionary*)data
  25. {
  26. NSString* containerName = data[@"name"];
  27. RCTRootView *reactView = [[RCTRootView alloc] initWithBridge:RNN.instance.bridge
  28. moduleName:containerName
  29. initialProperties:@{@"containerId": containerId}];
  30. UIViewController* controller = [UIViewController new];
  31. controller.view = reactView;
  32. return controller;
  33. }
  34. -(UINavigationController*)createContainerStack:(NSString*)containerId data:(NSDictionary*)data children:(NSArray*)children
  35. {
  36. UINavigationController* vc = [[UINavigationController alloc] init];
  37. NSMutableArray* controllers = [NSMutableArray new];
  38. for (NSDictionary* node in children) {
  39. [controllers addObject:[self fromTree:node]];
  40. }
  41. [vc setViewControllers:controllers];
  42. return vc;
  43. }
  44. @end