Skip to content

Commit

Permalink
refactor(ios): minor update of UIManager and ShadowView
Browse files Browse the repository at this point in the history
  • Loading branch information
wwwcg committed Oct 12, 2024
1 parent 09092a2 commit 26a9d93
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 18 deletions.
35 changes: 18 additions & 17 deletions renderer/native/ios/renderer/HippyUIManager.mm
Original file line number Diff line number Diff line change
Expand Up @@ -201,16 +201,16 @@ @interface HippyUIManager() {
NSHashTable<id<HippyComponent>> *_componentTransactionListeners;

std::mutex _renderQueueLock;
NSMutableDictionary<NSString *, id> *_viewManagers;
NSArray<Class> *_extraComponents;

NSMutableArray<Class<HippyImageProviderProtocol>> *_imageProviders;
}


/// All managed ViewManagers
@property (atomic, strong) NSMutableDictionary<NSString *, id> *viewManagers;
/// All extra components
@property (atomic, strong) NSArray<Class> *extraComponents;

@end


@implementation HippyUIManager

@synthesize domManager = _domManager;
Expand Down Expand Up @@ -675,36 +675,37 @@ - (void)updateView:(nonnull NSNumber *)componentTag

- (__kindof HippyViewManager *)viewManagerForViewName:(NSString *)viewName {
HippyBridge *strongBridge = self.bridge;
if (!_viewManagers) {
_viewManagers = [NSMutableDictionary dictionary];
if (_extraComponents) {
for (Class cls in _extraComponents) {
if (!self.viewManagers) {
NSMutableDictionary *viewManagers = [NSMutableDictionary dictionary];
if (self.extraComponents) {
for (Class cls in self.extraComponents) {
NSString *viewName = viewNameFromViewManagerClass(cls);
HippyAssert(![_viewManagers objectForKey:viewName],
HippyAssert(![viewManagers objectForKey:viewName],
@"duplicated component %@ for class %@ and %@", viewName,
NSStringFromClass(cls),
NSStringFromClass([_viewManagers objectForKey:viewName]));
[_viewManagers setObject:cls forKey:viewName];
NSStringFromClass([viewManagers objectForKey:viewName]));
[viewManagers setObject:cls forKey:viewName];
}
}
NSArray<Class> *classes = HippyGetViewManagerClasses(strongBridge);
NSMutableDictionary *defaultViewManagerClasses = [NSMutableDictionary dictionaryWithCapacity:[classes count]];
for (Class cls in classes) {
NSString *viewName = viewNameFromViewManagerClass(cls);
if ([_viewManagers objectForKey:viewName]) {
if ([viewManagers objectForKey:viewName]) {
continue;
}
[defaultViewManagerClasses setObject:cls forKey:viewName];
}
[_viewManagers addEntriesFromDictionary:defaultViewManagerClasses];
[viewManagers addEntriesFromDictionary:defaultViewManagerClasses];
self.viewManagers = viewManagers;
}
// Get and instantiate the class
id object = [_viewManagers objectForKey:viewName];
id object = [self.viewManagers objectForKey:viewName];
if (object_isClass(object)) {
HippyViewManager *viewManager = [object new];
viewManager.bridge = strongBridge;
NSAssert([viewManager isKindOfClass:[HippyViewManager class]], @"Must be a HippyViewManager instance");
[_viewManagers setObject:viewManager forKey:viewName];
[self.viewManagers setObject:viewManager forKey:viewName];
object = viewManager;
}
return object;
Expand Down Expand Up @@ -1125,7 +1126,7 @@ - (void)dispatchFunction:(const std::string &)functionName
}

- (void)registerExtraComponent:(NSArray<Class> *)extraComponents {
_extraComponents = extraComponents;
self.extraComponents = extraComponents;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ - (instancetype)init {
if ((self = [super init])) {
_propagationLifecycle = NativeRenderUpdateLifecycleUninitialized;
_frame = CGRectMake(0, 0, NAN, NAN);
_objectSubviews = [NSMutableArray arrayWithCapacity:8];
_objectSubviews = [NSMutableArray array];
_confirmedLayoutDirection = hippy::Direction::Inherit;
_layoutDirection = hippy::Direction::Inherit;
}
Expand Down

0 comments on commit 26a9d93

Please sign in to comment.