Skip to content

Commit

Permalink
Merge branch 'main' into bugfix/compatible_with_trouter_1
Browse files Browse the repository at this point in the history
  • Loading branch information
open-hippy authored Sep 1, 2023
2 parents 5ca2886 + 9a78a1b commit 56f0536
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 35 deletions.
2 changes: 1 addition & 1 deletion driver/js/include/driver/scope.h
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,7 @@ class Scope : public std::enable_shared_from_this<Scope> {
FOOTSTONE_CHECK(context);
auto weak_callback_wrapper = std::make_unique<WeakCallbackWrapper>([](void* callback_data, void* internal_data) {
auto class_template = reinterpret_cast<ClassTemplate<T>*>(callback_data);
auto holder_map = class_template->holder_map;
auto& holder_map = class_template->holder_map;
auto it = holder_map.find(internal_data);
if (it != holder_map.end()) {
holder_map.erase(it);
Expand Down
16 changes: 8 additions & 8 deletions driver/js/src/napi/jsc/jsc_ctx.cc
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ std::shared_ptr<CtxValue> JSCCtx::DefineClass(const string_view& name,
auto weak_callback_wrapper = constructor_data->weak_callback_wrapper;
if (weak_callback_wrapper) {
auto wrapper = reinterpret_cast<WeakCallbackWrapper*>(weak_callback_wrapper);
auto object_data_map = constructor_data->object_data_map;
auto& object_data_map = constructor_data->object_data_map;
wrapper->callback(wrapper->data, object_data_map[object]);
object_data_map.erase(object_data_map.find(object));
object_data_map.erase(object);
}
};
class_definition.hasInstance = [](JSContextRef ctx, JSObjectRef constructor, JSValueRef instance, JSValueRef* exception) -> bool {
Expand All @@ -287,7 +287,7 @@ std::shared_ptr<CtxValue> JSCCtx::DefineClass(const string_view& name,
auto constructor_prototype = reinterpret_cast<ConstructorData*>(constructor_private)->prototype;
auto constructor_prototype_value = std::static_pointer_cast<JSCCtxValue>(constructor_prototype)->value_;
auto instance_prototype = JSObjectGetPrototype(ctx, instance_object);

while (!JSValueIsNull(ctx, instance_prototype)) {
if (JSValueIsEqual(ctx, instance_prototype, constructor_prototype_value, exception)) {
return true;
Expand All @@ -298,7 +298,7 @@ std::shared_ptr<CtxValue> JSCCtx::DefineClass(const string_view& name,
}
instance_prototype = JSObjectGetPrototype(ctx, instance_prototype_object);
}

return false;
};
JSClassRef parent_class_ref = nullptr;
Expand Down Expand Up @@ -379,7 +379,7 @@ std::shared_ptr<CtxValue> JSCCtx::DefineClass(const string_view& name,
JSStringRelease(set_key_name);
JSStringRelease(define_property_name);
JSStringRelease(object_name);

if (parent_prototype_value) {
JSObjectSetPrototype(context_, prototype, parent_prototype_value);
}
Expand Down Expand Up @@ -897,14 +897,14 @@ std::shared_ptr<CtxValue> JSCCtx::CallFunction(const std::shared_ptr<CtxValue>&
SetException(std::make_shared<JSCCtxValue>(context_, exception));
return nullptr;
}

auto receiver_value = std::static_pointer_cast<JSCCtxValue>(receiver);
auto receiver_object = JSValueToObject(context_, receiver_value->value_, &exception);
if (exception) {
SetException(std::make_shared<JSCCtxValue>(context_, exception));
return nullptr;
}

if (argc <= 0) {
auto ret_value_ref = JSObjectCallAsFunction(context_, function_object, receiver_object, 0, nullptr, &exception);
if (exception) {
Expand Down Expand Up @@ -981,7 +981,7 @@ void JSCCtx::SaveConstructorData(std::unique_ptr<ConstructorData> constructor_da
JSCVM::SaveConstructorDataPtr(constructor_data.get());
holder[this][constructor_data->class_ref] = std::move(constructor_data);
}

std::shared_ptr<JSCCtxValue> JSCCtx::GetClassPrototype(JSClassRef ref) {
auto vm = vm_.lock();
FOOTSTONE_CHECK(vm);
Expand Down
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 56f0536

Please sign in to comment.