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
ListView template's child components aren't updated #612
Comments
Hey @jzgoda thank you for your project and great explanations of the issue you have encountered - indeed I think this is a good addition for a documentation article or sdk example. The solution with using onChanges is the way to go when you want watch the immutable input in your child component. Great blog post on that matter can be found here (the approach you have used is shown at the end of the article as the right solution for similar scenario) |
@NickIliev, thanks for clearing that up! |
Example added in nativescript-sdk-examples-ng application via this PR. @jzgoda the sample will also appear in our documentation after the official release - once again thank you for noticing this one! |
I ran into a weird issue with a ListView who's template had a child component. When I started scrolling down and back up in the ListView, the child components started to change which parent template they were associated with.
I made a sample app to illustrate this problem.
(There's an animated GIF in the README that shows the odd behavior.)
I attempted to move the template code into it's own component, which didn't solve this issue. (I read that solved another, somewhat similar, issue.)
This child component has an
@Input
which is passed to it by the parent template, and thenOnInit
sets a instance variable based on that data.It's the
OnInit
that seems to be the issue, or rather the wrong solution, and anOnChanges
should be used here. Once I switched toOnChanges
, I was able to pass the currentValue of the changed@Input
to the instance variable, and all was good. (I posted that commit to the above repo as well.)I'm wondering if this is a bug, or just something that needs to be documented? It certainly wasn't obvious to me that a ListView template component's children could become associated with another component. (Although I can guess that this has to do with the reuse of allocated visual elements, but still figured that it would trickle down to child components.)
Let me know if there is anything else you need me to provide.
The text was updated successfully, but these errors were encountered: