react-native-navigation的迁移库

RNNReactComponentRegistry.m 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #import "RNNReactComponentRegistry.h"
  2. @interface RNNReactComponentRegistry () {
  3. id<RNNRootViewCreator> _creator;
  4. NSMutableDictionary* _componentStore;
  5. }
  6. @end
  7. @implementation RNNReactComponentRegistry
  8. - (instancetype)initWithCreator:(id<RNNRootViewCreator>)creator {
  9. self = [super init];
  10. _creator = creator;
  11. _componentStore = [NSMutableDictionary new];
  12. return self;
  13. }
  14. - (RNNReactView *)createComponentIfNotExists:(RNNComponentOptions *)component parentComponentId:(NSString *)parentComponentId reactViewReadyBlock:(RNNReactViewReadyCompletionBlock)reactViewReadyBlock {
  15. NSMutableDictionary* parentComponentDict = [self componentsForParentId:parentComponentId];
  16. RNNReactView* reactView = [parentComponentDict objectForKey:component.componentId.get];
  17. if (!reactView) {
  18. reactView = (RNNReactView *)[_creator createRootViewFromComponentOptions:component reactViewReadyBlock:reactViewReadyBlock];
  19. [parentComponentDict setObject:reactView forKey:component.componentId.get];
  20. } else if (reactViewReadyBlock) {
  21. reactViewReadyBlock();
  22. }
  23. return reactView;
  24. }
  25. - (NSMutableDictionary *)componentsForParentId:(NSString *)parentComponentId {
  26. if (!_componentStore[parentComponentId]) {
  27. [_componentStore setObject:[NSMutableDictionary new] forKey:parentComponentId];;
  28. }
  29. return [_componentStore objectForKey:parentComponentId];;
  30. }
  31. - (void)removeComponent:(NSString *)componentId {
  32. if ([_componentStore objectForKey:componentId]) {
  33. [_componentStore removeObjectForKey:componentId];
  34. }
  35. }
  36. - (void)clean {
  37. [_componentStore removeAllObjects];
  38. }
  39. @end