diff --git a/src/render/native/components/component.hpp b/src/render/native/components/component.hpp index 2fb86339..4507e25d 100644 --- a/src/render/native/components/component.hpp +++ b/src/render/native/components/component.hpp @@ -284,7 +284,7 @@ void NativeComponentMaskInit (JSContext* ctx, JSValue ns); #define WRAPPED_JS_CLOSE_COMPONENT(COMPONENT,COMPONENT_NAME) \ static JSValue NativeCompCloseComponent(JSContext *ctx, JSValueConst this_val, int argc, JSValueConst *argv) { \ COMP_REF* s = (COMP_REF*)JS_GetOpaque(this_val, COMPONENT##ClassID); \ - lv_obj_del_async(((BasicComponent*)(s->comp))->instance); \ + delete (BasicComponent*)(s->comp); \ return JS_UNDEFINED; \ } \ \ diff --git a/src/render/native/core/basic/comp.cpp b/src/render/native/core/basic/comp.cpp index 7d26e20a..d6dd92a3 100644 --- a/src/render/native/core/basic/comp.cpp +++ b/src/render/native/core/basic/comp.cpp @@ -45,9 +45,7 @@ void BasicComponent::insertChildBefore(void *child) { } }; -void BasicComponent::removeChild(void* child) { - lv_obj_del_async((static_cast(child))->instance); -}; +void BasicComponent::removeChild(void* child) {}; void BasicComponent::appendChild (void* child) { static_cast(child)->parent_instance = this->instance; @@ -86,7 +84,7 @@ void BasicComponent::setTransition (JSContext* ctx, JSValue obj, lv_style_t* sty lv_style_prop_t* old_transProps = this->trans_props_map[type]; this->trans_props_map[type] = (lv_style_prop_t*)malloc((len + 1) * sizeof(lv_style_prop_t)); - + JSValue props = JS_GetPropertyUint32(ctx, obj, 1); int32_t prop_key; for(int i=0; i < len; i++) { @@ -255,8 +253,13 @@ BasicComponent::~BasicComponent () { if (ptr2) { free((lv_coord_t*)(ptr2)); } - // do not del here, remove child will do the action - // lv_obj_del(this->instance); + + for(auto &style : style_map) { + lv_style_reset(style.second); + } + + lv_obj_remove_event_cb(instance, &BasicComponent::EventCallback); + lv_obj_del(this->instance); }; void BasicComponent::setAlign (int32_t align_type, int32_t x, int32_t y) { diff --git a/src/render/react/core/reconciler/index.js b/src/render/react/core/reconciler/index.js index 0bdda577..d371c255 100644 --- a/src/render/react/core/reconciler/index.js +++ b/src/render/react/core/reconciler/index.js @@ -11,7 +11,7 @@ export const getUid = () => { const instanceMap = new Map(); export const getInstance = (uid) => { - return instanceMap[uid]; + return instanceMap.get(uid); }; const HostConfig = { @@ -53,7 +53,6 @@ const HostConfig = { workInProgress, uid, ); - instanceMap[uid] = instance; return instance; }, createTextInstance: ( @@ -124,12 +123,16 @@ const HostConfig = { commitTextUpdate(textInstance, oldText, newText) { textInstance.setText(newText); }, + detachDeletedInstance: (instance) => { + unRegistEvent(instance.uid); + instanceMap.delete(instance.uid); + instance.style = null; // Proxy preventing GC + }, removeChild(parent, child) { parent?.removeChild(child); - unRegistEvent(child.uid); - delete instanceMap[child.uid]; }, commitMount: function (instance, type, newProps, internalInstanceHandle) { + instanceMap.set(instance.uid, instance); const { commitMount } = getComponentByTagName(type); return commitMount(instance, newProps, internalInstanceHandle); },