Skip to content

Commit

Permalink
Merge branch 'main' into dev/contextname
Browse files Browse the repository at this point in the history
  • Loading branch information
open-hippy authored Aug 31, 2023
2 parents 92c9018 + 6ba3474 commit 2aae793
Showing 1 changed file with 11 additions and 26 deletions.
37 changes: 11 additions & 26 deletions renderer/native/ios/renderer/NativeRenderImpl.mm
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,9 @@ @interface NativeRenderImpl() {
// Keyed by viewName
NSMutableDictionary<NSString *, NativeRenderComponentData *> *_componentDataByName;

NSMutableSet<id<NativeRenderComponentProtocol>> *_componentTransactionListeners;
// Listeners such as ScrollView/ListView etc. witch will listen to start layout event
// The implementation here needs to be improved to provide a registration mechanism.
NSHashTable<id<NativeRenderComponentProtocol>> *_componentTransactionListeners;

std::weak_ptr<DomManager> _domManager;
std::mutex _renderQueueLock;
Expand Down Expand Up @@ -209,7 +211,7 @@ - (void)initContext {
_viewRegistry = [[NativeRenderComponentMap alloc] init];
_viewRegistry.requireInMainThread = YES;
_pendingUIBlocks = [NSMutableArray new];
_componentTransactionListeners = [NSMutableSet new];
_componentTransactionListeners = [NSHashTable weakObjectsHashTable];
_componentDataByName = [NSMutableDictionary dictionaryWithCapacity:64];
NativeRenderScreenScale();
NativeRenderScreenSize();
Expand All @@ -222,7 +224,7 @@ - (void)invalidate {
NativeRenderImpl *strongSelf = weakSelf;
if (strongSelf) {
strongSelf->_viewRegistry = nil;
strongSelf->_componentTransactionListeners = nil;
[strongSelf->_componentTransactionListeners removeAllObjects];
[[NSNotificationCenter defaultCenter] removeObserver:strongSelf];
}
});
Expand Down Expand Up @@ -431,18 +433,14 @@ - (void)setFrame:(CGRect)frame forRootView:(UIView *)view {
*/
- (void)purgeChildren:(NSArray<id<NativeRenderComponentProtocol>> *)children
onRootTag:(NSNumber *)rootTag
fromRegistry:(NativeRenderComponentMap *)componentMap {
NSMutableDictionary<NSNumber *, __kindof id<NativeRenderComponentProtocol>> *registry = [componentMap componentsForRootTag:rootTag];
fromRegistry:(NSMutableDictionary<NSNumber *, __kindof id<NativeRenderComponentProtocol>> *)registry {
for (id<NativeRenderComponentProtocol> child in children) {
NativeRenderTraverseViewNodes(registry[child.componentTag], ^(id<NativeRenderComponentProtocol> subview) {
NSAssert(![subview isNativeRenderRootView], @"Root views should not be unregistered");
if ([subview respondsToSelector:@selector(invalidate)]) {
[subview performSelector:@selector(invalidate)];
}
[registry removeObjectForKey:subview.componentTag];
if (registry == (NSMutableDictionary<NSNumber *, id<NativeRenderComponentProtocol>> *)self->_viewRegistry) {
[self->_componentTransactionListeners removeObject:subview];
}
});
}
}
Expand All @@ -458,21 +456,6 @@ - (void)purgeViewsFromComponentTags:(NSArray<NSNumber *> *)componentTags onRootT
}
}
- (void)purgeChildren:(NSArray<id<NativeRenderComponentProtocol>> *)children fromRegistry:(NSMutableDictionary<NSNumber *, id<NativeRenderComponentProtocol>> *)registry {
for (id<NativeRenderComponentProtocol> child in children) {
NativeRenderTraverseViewNodes(registry[child.componentTag], ^(id<NativeRenderComponentProtocol> subview) {
NSAssert(![subview isNativeRenderRootView], @"Root views should not be unregistered");
if ([subview respondsToSelector:@selector(invalidate)]) {
[subview performSelector:@selector(invalidate)];
}
[registry removeObjectForKey:subview.componentTag];
if (registry == (NSMutableDictionary<NSNumber *, id<NativeRenderComponentProtocol>> *)self->_viewRegistry) {
[self->_componentTransactionListeners removeObject:subview];
}
});
}
}
- (void)removeChildren:(NSArray<id<NativeRenderComponentProtocol>> *)children fromContainer:(id<NativeRenderComponentProtocol>)container {
for (id<NativeRenderComponentProtocol> removedChild in children) {
[container removeNativeRenderSubview:removedChild];
Expand Down Expand Up @@ -838,14 +821,15 @@ - (void)deleteRenderNodesIds:(std::vector<std::shared_ptr<hippy::DomNode>> &&)no
#endif
std::lock_guard<std::mutex> lock([self renderQueueLock]);
NSNumber *rootTag = @(strongRootNode->GetId());
NSMutableDictionary *currentRegistry = [_renderObjectRegistry componentsForRootTag:rootTag];
for (auto dom_node : nodes) {
int32_t tag = dom_node->GetRenderInfo().id;
NativeRenderObjectView *renderObject = [_renderObjectRegistry componentForTag:@(tag) onRootTag:rootTag];
NativeRenderObjectView *renderObject = [currentRegistry objectForKey:@(tag)];
[renderObject dirtyPropagation:NativeRenderUpdateLifecycleLayoutDirtied];
if (renderObject) {
[renderObject removeFromNativeRenderSuperview];
[self purgeChildren:@[renderObject] onRootTag:rootTag fromRegistry:_renderObjectRegistry];
[self purgeChildren:@[renderObject] onRootTag:rootTag fromRegistry:currentRegistry];
}
}
__weak NativeRenderImpl *weakSelf = self;
Expand All @@ -870,7 +854,8 @@ - (void)deleteRenderNodesIds:(std::vector<std::shared_ptr<hippy::DomNode>> &&)no
[view removeFromNativeRenderSuperview];
[views addObject:view];
}
[strongSelf purgeChildren:views onRootTag:rootTag fromRegistry:strongSelf->_viewRegistry];
NSMutableDictionary *currentViewRegistry = [strongSelf->_viewRegistry componentsForRootTag:rootTag];
[strongSelf purgeChildren:views onRootTag:rootTag fromRegistry:currentViewRegistry];
for (UIView *view in parentViews) {
[view clearSortedSubviews];
[view didUpdateNativeRenderSubviews];
Expand Down

0 comments on commit 2aae793

Please sign in to comment.