react-native-navigation的迁移库

RNNReactRootViewCreator.m 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #import "RNNReactRootViewCreator.h"
  2. #import "RNNReactView.h"
  3. #import "RNNComponentRootView.h"
  4. @implementation RNNReactRootViewCreator {
  5. RCTBridge *_bridge;
  6. RNNEventEmitter* _eventEmitter;
  7. }
  8. - (instancetype)initWithBridge:(RCTBridge*)bridge eventEmitter:(RNNEventEmitter*)eventEmitter {
  9. self = [super init];
  10. _bridge = bridge;
  11. _eventEmitter = eventEmitter;
  12. return self;
  13. }
  14. - (RNNReactView*)createRootView:(NSString*)name rootViewId:(NSString*)rootViewId ofType:(RNNComponentType)componentType reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
  15. [self verifyRootViewId:rootViewId];
  16. return [[[self resolveComponentViewClass:componentType] alloc] initWithBridge:_bridge
  17. moduleName:name
  18. initialProperties:@{@"componentId": rootViewId}
  19. eventEmitter:_eventEmitter
  20. reactViewReadyBlock:reactViewReadyBlock];
  21. }
  22. - (Class)resolveComponentViewClass:(RNNComponentType)componentType {
  23. switch (componentType) {
  24. case RNNComponentTypeTopBarTitle:
  25. return RNNReactTitleView.class;
  26. case RNNComponentTypeTopBarButton:
  27. return RNNReactButtonView.class;
  28. case RNNComponentTypeTopBarBackground:
  29. return RNNReactBackgroundView.class;
  30. case RNNComponentTypeComponent:
  31. default:
  32. return RNNComponentRootView.class;
  33. }
  34. }
  35. - (void)verifyRootViewId:(NSString *)rootViewId {
  36. if (!rootViewId) {
  37. @throw [NSException exceptionWithName:@"MissingViewId" reason:@"Missing view id" userInfo:nil];
  38. }
  39. }
  40. @end