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

State is forgotten when item is re-rendered #13

Open
jamesfzhang opened this issue Dec 23, 2015 · 6 comments
Open

State is forgotten when item is re-rendered #13

jamesfzhang opened this issue Dec 23, 2015 · 6 comments

Comments

@jamesfzhang
Copy link

I have a list of radio buttons, each can be toggled by tapping. When I toggle a radio button, scroll away and scroll back to it, the radio button resets to the original state. Is this intentional?

EDIT: The radio button's getInitialState sets its toggled state to be on. I'm guessing that when an item leaves the current viewport, it gets destroyed completely and then re-drawn when it comes back into view. Therefore, the item is re-rendered completely getInitialState gets called again.

@sghiassy
Copy link
Owner

Probably. The list view works by destroying views after they've scrolled off screen, so state would probably have to be persisted for items like radio buttons.

@rameshvishnoi90904
Copy link

rameshvishnoi90904 commented Jun 14, 2016

its works fine i.e state or props does not revert back in Android, but in IOS state or props values does get revert back.

@sghiassy
Copy link
Owner

I could perhaps add a props flag that you can set per cell, for the View not to be destroyed when it scrolls out of view. Would that help? You'd loose the performance benefit, but if you set it selectively for just some cells, it might still be helpful.

Let me know how helpful that'd be

@sghiassy
Copy link
Owner

Maybe keepAlive={true} or something. Default would be keepAlive={false}

@mschipperheyn
Copy link

In many case state should be replaced by props anyways. I wonder if supporting this case, is worth it and if the same effect cannot be achieve by developers rewriting their code to depend more on props (good) in stead of state (bad).

@sghiassy
Copy link
Owner

@mschipperheyn - fair point

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

4 participants