Skip to content
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

SaveViewState not working as expected #346

Closed
mradzinski opened this issue Nov 16, 2017 · 3 comments
Closed

SaveViewState not working as expected #346

mradzinski opened this issue Nov 16, 2017 · 3 comments

Comments

@mradzinski
Copy link
Contributor

mradzinski commented Nov 16, 2017

Hey @elihart, I have a ModelView with a ToggleButton and I wanted to preserve the on/off state of it so I remembered of the existence of saveViewState and based on the wiki thought it would be the solution. I made sure my models had VERY unique ids, so I was expecting that by just setting saveViewState to true the state would be preserved just for that particular model and I wouldn't experience the classical recycling issue (a change on item A can be seen on item F if F is a recycled instance of A and the view wasn't "reset"). So I ran the app and found out that if I change the toggle state on the first item to ON, as I scroll down the list I keep seeing multiple items with the toggle being ON when the default state of it is OFF.

Long story short, I ended up using a mix of saveViewState and @OnViewRecycled where I change back the toggle state to OFF and this seems to solve the issue, but I really was expecting saveViewState to actually save the state of just one ModelView and decide based on the ID of it if to apply the saved state or not. If this (the way I ended up doing it) is the intended behavior then I think the wiki should be updated to reflect it. If not then I believe there's an issue with how saveViewState is working.

@elihart
Copy link
Contributor

elihart commented Nov 16, 2017

Thanks for the report. I hadn't thought about this case before; you're right, we don't reset view state of views when they are unbound. To do this I believe we would need to save the view's state when it was first created (to have something that declares the default state) and reapply that before the view is bound to a model (if it doesn't have other saved state already).

I think this is reasonable and not too hard. I will try to work on it soon.

@elihart
Copy link
Contributor

elihart commented Nov 21, 2017

I have a fix in mind that should work well, but I've been a bit swamped with work, and have some vacation coming up the next week, so I won't be able to get it in for a little while still.

@elihart
Copy link
Contributor

elihart commented Dec 20, 2017

#367 makes the change to ensure a view has a clean state when a model is first bound. let me know if you notice any new issues or if this does not resolve it!

@elihart elihart closed this as completed Dec 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants