Skip to content
This repository has been archived by the owner on Sep 20, 2023. It is now read-only.

Commit

Permalink
feat: added property to configure swipe offset;
Browse files Browse the repository at this point in the history
  • Loading branch information
jacekk committed Mar 18, 2019
1 parent 490a713 commit ac95547
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/AniLink/Swipe.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,23 @@ const swipeTopDirection = (direction, reverse) => {
}
};

const swipeBottomDirection = (direction, reverse) => {
const swipeBottomDirection = (direction, reverse = false, offset = 40) => {
const polarityPos = reverse ? "-" : "";
const polarityNeg = reverse ? "" : "-";

switch (direction) {
case "down":
return { y: `${polarityNeg}40vh`, ease: Power1.easeIn };
return { y: `${polarityNeg}${offset}vh`, ease: Power1.easeIn };
case "up":
return { y: `${polarityPos}40vh`, ease: Power1.easeIn };
return { y: `${polarityPos}${offset}vh`, ease: Power1.easeIn };
case "left":
return { x: `${polarityPos}40%`, ease: Power1.easeIn };
return { x: `${polarityPos}${offset}%`, ease: Power1.easeIn };
default:
return { x: `${polarityNeg}40%`, ease: Power1.easeIn };
return { x: `${polarityNeg}${offset}%`, ease: Power1.easeIn };
}
};

const swipe = ({ node, exit, direction, top, triggerName }) => {
const swipe = ({ node, exit, direction, top, triggerName, swipeBottomOffset }) => {
const scrollTop =
document.scrollingElement.scrollTop ||
document.body.scrollTop ||
Expand All @@ -56,7 +56,7 @@ const swipe = ({ node, exit, direction, top, triggerName }) => {
return new TimelineMax().from(
node,
exit.length,
swipeBottomDirection(direction)
swipeBottomDirection(direction, false, swipeBottomOffset)
);
} else if (triggerName === "exit" && top === "exit") {
return new TimelineMax()
Expand All @@ -76,7 +76,7 @@ const swipe = ({ node, exit, direction, top, triggerName }) => {
height: "100vh",
scrollTop: scrollTop
})
.to(node, exit.length, swipeBottomDirection(direction, true))
.to(node, exit.length, swipeBottomDirection(direction, true, swipeBottomOffset))
.set(node, { overflowY: "initial" });
}
};
Expand All @@ -85,6 +85,7 @@ export default function SwipeOver({
exit,
entry,
swipe: removedProp,
swipeBottomOffset = 40,
...props
}) {
const top = props.top || "exit";
Expand All @@ -103,6 +104,7 @@ export default function SwipeOver({
exit,
direction: props.direction,
top: top,
swipeBottomOffset,
triggerName: "exit"
}),
zIndex: exitZ
Expand All @@ -115,6 +117,7 @@ export default function SwipeOver({
exit,
direction: props.direction,
top: top,
swipeBottomOffset,
triggerName: "entry"
}),
zIndex: entryZ
Expand Down

0 comments on commit ac95547

Please sign in to comment.