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

New prop added - fullView #254

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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ enters or leaves the viewport. For details, see [Children](#children), below.
*/
fireOnRapidScroll: PropTypes.bool,

/**
* fullView - if the waypoint is displayed on the screen fully, not partly.
* The onEneter/onLeave fire
*/
fullView: PropTypes.bool,

/**
* Use this prop to get debug information in the console log. This slows
* things down significantly, so it should only be used during development.
Expand Down
6 changes: 6 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ declare namespace Waypoint {
*/
fireOnRapidScroll?: boolean;

/**
* If the waypoint is displayed on the screen fully, not partly.
* The onEneter/onLeave fire
*/
fullView?: boolean;

/**
* Use this prop to get debug information in the console log. This slows
* things down significantly, so it should only be used during development.
Expand Down
27 changes: 18 additions & 9 deletions src/getCurrentPosition.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,25 @@ export default function getCurrentPosition(bounds) {
return constants.invisible;
}

// top is within the viewport
if (bounds.viewportTop <= bounds.waypointTop &&
bounds.waypointTop <= bounds.viewportBottom) {
return constants.inside;
}
if (bounds.fullView) {
// top & bottom is within the viewport
if (bounds.viewportTop <= bounds.waypointTop &&
bounds.waypointTop <= bounds.viewportBottom &&
bounds.viewportTop <= bounds.waypointBottom &&
bounds.waypointBottom <= bounds.viewportBottom) {
return constants.inside;
}
} else {
// top is within the viewport
if (bounds.viewportTop <= bounds.waypointTop && bounds.waypointTop <= bounds.viewportBottom) {
return constants.inside;
}

// bottom is within the viewport
if (bounds.viewportTop <= bounds.waypointBottom &&
bounds.waypointBottom <= bounds.viewportBottom) {
return constants.inside;
// bottom is within the viewport
if (bounds.viewportTop <= bounds.waypointBottom &&
bounds.waypointBottom <= bounds.viewportBottom) {
return constants.inside;
}
}

// top is above the viewport and bottom is below the viewport
Expand Down
5 changes: 4 additions & 1 deletion src/waypoint.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const defaultProps = {
onLeave() { },
onPositionChange() { },
fireOnRapidScroll: true,
fullView: false,
};

/**
Expand Down Expand Up @@ -252,7 +253,7 @@ export default class Waypoint extends React.Component {
debugLog('scrollableAncestor scrollTop', contextScrollTop);
}

const { bottomOffset, topOffset } = this.props;
const { bottomOffset, topOffset, fullView } = this.props;
const topOffsetPx = computeOffsetPixels(topOffset, contextHeight);
const bottomOffsetPx = computeOffsetPixels(bottomOffset, contextHeight);
const contextBottom = contextScrollTop + contextHeight;
Expand All @@ -262,6 +263,7 @@ export default class Waypoint extends React.Component {
waypointBottom,
viewportTop: contextScrollTop + topOffsetPx,
viewportBottom: contextBottom - bottomOffsetPx,
fullView
};
}

Expand Down Expand Up @@ -299,6 +301,7 @@ Waypoint.propTypes = {
onLeave: PropTypes.func,
onPositionChange: PropTypes.func,
fireOnRapidScroll: PropTypes.bool,
fullView: PropTypes.bool,
scrollableAncestor: PropTypes.any,
horizontal: PropTypes.bool,

Expand Down