Skip to content

[Optimization] UIManager cannot re-use elements #1707

@uber5001

Description

@uber5001

It would be useful if the UIManager allowed for re-use of native elements, so that elements don't need to be destroyed every time they should be removed from the application tree. Instead of destroying elements upon removal from their parent, there could be a UIManager.destroyView instead.

Currently, this is what happens:

// create some text and attach it...
RCTUIManager.createView(2, "RCTText", {});
RCTUIManager.createView(3, "RCTRawText", {"text":"foobar"});
RCTUIManager.manageChildren(2, null, null, [3], [0], null);
RCTUIManager.manageChildren(1, null, null, [2], [0], null);
// If we stop here, the text "foobar" is rendered, as expected

// detach the text...
RCTUIManager.manageChildren(1, null, null, null, null, [0]);
// If we stop here, the text is no longer visible, as expected

// re-attach the text...
RCTUIManager.manageChildren(1, null, null, [2], [0], null);
// If we stop here, the text is still not visible, since element 2 and 3 have been destroyed
// Oddly, there is no error in attaching a non-existent element.

// Update the text...
RCTUIManager.updateView(3, "RCTRawText", {"text":"new text"});
// App crashes with error:
//    Error setting property 'text' of RCTRawText with tag #(null): (null) does not have setter for `text` property

Ideally, when re-attaching the text, it uses the same element that was detached earlier.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions