react-native-navigation的迁移库

RNNReactRootViewCreator.m 1.5KB

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