-
Notifications
You must be signed in to change notification settings - Fork 195
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
Add stayVisible
prop.
#105
base: master
Are you sure you want to change the base?
Conversation
This makes the `VisibilitySensor` stay visible once it is visible for the first time, even if it then is scrolled out of the viewport. This means that `onChange` will only be called once, the first time it becomes visible, and then never again.
What I thought was same as you.I hope this feature can be added into the package.Thanks a lot. |
Thanks for this. |
Can't you already do this with the |
@Klaasvaak but than you would have to manage state in your own component just for this (or am I missing sth?) |
I just checked this and it works great. It would be nice to get it merged so I could leave my functional components as is. Thank you for the great work on this lib. |
Who want quickly implement this feature and who use recomposer I suggest that utility HOC: import {compose,withState,mapProps} from 'recompose';
export default compose(
withState('active','setActive',true),// true sensor active
mapProps(props => ({
...props,
onChange: (isVis,visRes) => {
if(props.onChange) props.onChange(isVis,visRes);
if(props.once && props.setActive) props.setActive(!isVis); // if became visible -> false for active
}
})),
) You should set once to true on your VisibilitySensor, otherwise it will work as original sensor |
|
This is the PR for the suggestion I raised in #100 .
This makes the
VisibilitySensor
stay visible once it is visible forthe first time, even if it then is scrolled out of the viewport.
This means that
onChange
will only be called once, the first time itbecomes visible, and then never again.