X Tutup
The Wayback Machine - https://web.archive.org/web/20260214202257/https://github.com/NativeScript/NativeScript/pull/8184
Skip to content

DO NOT MERGE: feat: reusable views#8184

Draft
edusperoni wants to merge 11 commits intoNativeScript:mainfrom
edusperoni:reusable-views
Draft

DO NOT MERGE: feat: reusable views#8184
edusperoni wants to merge 11 commits intoNativeScript:mainfrom
edusperoni:reusable-views

Conversation

@edusperoni
Copy link
Contributor

@edusperoni edusperoni commented Dec 9, 2019

PR Checklist

What is the current behavior?

Views and view trees are destroyed when removed from the view tree.

What is the new behavior?

Views can be marked as reusable and will not be destroyed when removed from view tree. Removing these nodes require the developer to do:

view.destroyNode();
// which calls
view.reusable = false;
view._tearDownUI();

For implementation details on how frameworks should deal with it, see my work in nativescript-angular: https://github.com/edusperoni/nativescript-angular/tree/reusable-views

Implements #7469.


To be defined:

What happens when a reusable view with children gets removed? The current implementation does not call _tearDownUI on children, but we should still suspendNativeUpdates down the chain (this._suspendNativeUpdates(SuspendType.UISetup);).

Maybe we should we create a new SuspendType (Detached)? Maybe this isn't even needed as the view should be unloaded by _removeViewCore which eventually calls this._suspendNativeUpdates(SuspendType.Loaded); on all children.

Possible refactoring needed (not directly related to this PR)

The current logic of _resumeNativeUpdates will call initNativeView. In most places I checked, initNativeView creates delegates that are only removed in disposeNativeView. This behavior is probably already an issue on loading/unloading views (like navigation) because of this._resumeNativeUpdates(SuspendType.Loaded);, meaning initNativeView is called multiple times during the application lifecycle, but the delegates are only cleaned up once.

During my tests with WebView, calling initNativeView did not result in a performance impact

@cla-bot cla-bot bot added the cla: yes label Dec 9, 2019
@edusperoni
Copy link
Contributor Author

After further working on this, SuspendType.Loaded seems to be sufficient. One of my commits had actually messed with the logic resulting in a crash (trying to re-add children to the native visual tree, which they already were added to). All child views are unloaded on parent removal.

I'll also weigh in that I believe child views should not be destroyed even when detached simply because it's already the behavior on tabviews (which soft detaches elements)

@NathanWalker
Copy link
Contributor

@edusperoni I'm curious what are your current thoughts on this PR? Does it still require changes?

@edusperoni
Copy link
Contributor Author

@NathanWalker I believe this just requires some testing and maybe treatment of edge cases. For example: if the view is detached and reusable is set to false, should it run _tearDownUI? Other than that, I think it'd be good as is.

@NathanWalker
Copy link
Contributor

Flagging for 7.0 to test more with latest changes planned.

@NathanWalker
Copy link
Contributor

@edusperoni Let's update this to latest master either from a new branch or rebase.

@rigor789 rigor789 removed this from the 7.1 milestone Dec 20, 2020
@rigor789 rigor789 marked this pull request as draft December 20, 2020 11:19
@edusperoni edusperoni mentioned this pull request Jan 21, 2021
5 tasks
@NathanWalker NathanWalker added this to the 9.0 milestone Aug 6, 2021
@NathanWalker NathanWalker removed this from the 9.0 milestone Nov 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

X Tutup