-
-
Notifications
You must be signed in to change notification settings - Fork 241
Manipulation Done on Native Elements Removed on Back Navigation #410
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I think this is related to the new angular router creating the components again. More info on this is here |
@shripalsoni04 All changes made by accessing the native elements are lost because we the native elements are destroyed when navigation happens. This is done in order to reduce memory pressure. If you want to keep the native elements alive you can set |
Thanks a lot @hshristov, this information will surely help us in deciding app design strategy. |
I have one question. If on back navigation native views are re-created, and angular component is re-used, so is there any way that we can attach the angular directives back on the native views. If there is any way or it is accommodated in nativescript-angular, that will be very helpful in such scenarios. Edit (Adding more information) : |
@vakrilov Will know better about angular component. |
@shripalsoni04 - You got all things right. When navigating the components are cached, but the actual android views are recreated. So here are the 3 levels of abstraction here:
As the component instances are cached (lvl 1) the lifecycle hooks ( If you are touching the Native android view directly you can attach to the |
That is an awesome explanation of caching mechanism. The solution of using Thanks a lot @vakrilov 👍 |
It seems like any manipulations done on native android element is getting removed when we navigate back to the route having that component.
Preview of the Issue:
Issue Description:
Here, I have created a class directive with selector '.test-btn' and I have attached this class directive to the button on Page1. Now when we navigate to other page and come back to the page again, the background color that I set using native api is getting removed.
I know we can set background color using nativescript only, but just to illustrate the issue easily, I am setting backgroundColor using native android api.
I don't know the same issue is for iOS also or not as I have tested on android only till now.
Sample Project Code
You can find the sample project described above at https://github.com/shripalsoni04/ns-ng-route-change-issue.
I am not sure but It seems like nativescript is creating the native button element again on back navigation and the directives attached to it are not executed again.
It will be great if we can find a solution for this.
The text was updated successfully, but these errors were encountered: