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

feat: (#174) Introduce onCheck event to register a callback #175

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Props
----

- `onChange`: callback for whenever the element changes from being within the window viewport or not. Function is called with 1 argument `(isVisible: boolean)`
- `onCheck`: callback for whenever the element being checked if it is within the window viewport or not. Function is called with 1 argument `(isVisible: boolean)` after the check is done. - Same as `onChange` but called even if the visibility hasn't changed.
- `active`: (default `true`) boolean flag for enabling / disabling the sensor. When `active !== true` the sensor will not fire the `onChange` callback.
- `partialVisibility`: (default `false`) consider element visible if only part of it is visible. Also possible values are - 'top', 'right', 'bottom', 'left' - in case it's needed to detect when one of these become visible explicitly.
- `offset`: (default `{}`) with offset you can define amount of px from one side when the visibility should already change. So in example setting `offset={{top:10}}` means that the visibility changes hidden when there is less than 10px to top of the viewport. Offset works along with `partialVisibility`
Expand Down
2 changes: 2 additions & 0 deletions visibility-sensor.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export default class VisibilitySensor extends React.Component {

static propTypes = {
onChange: PropTypes.func,
onCheck: PropTypes.func,
active: PropTypes.bool,
partialVisibility: PropTypes.oneOfType([
PropTypes.bool,
Expand Down Expand Up @@ -321,6 +322,7 @@ export default class VisibilitySensor extends React.Component {
if (this.props.onChange) this.props.onChange(isVisible);
}

if (this.props.onCheck) this.props.onCheck(isVisible);
return state;
};

Expand Down