Skip to content

Commit

Permalink
fix isolated waypoint bug
Browse files Browse the repository at this point in the history
  • Loading branch information
julianbenegas committed Feb 22, 2024
1 parent ea15c7c commit 1b708b9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,4 @@ yarn-error.log*

.env
.vercel
.env*.local
18 changes: 11 additions & 7 deletions scrollytelling/src/components/waypoint/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import {
} from "../../types";
import * as React from "react";
import { useScrollytelling } from "../../primitive";
import { getTweenTarget, getValidAt, buildDeclarativeTween } from "../../util";
import { getTweenTarget, buildDeclarativeTween } from "../../util";
import { DataAttribute } from "../debugger/visualizer/shared-types";
import { useDispatcher } from "../../context";

export function Waypoint(
props: WaypointBaseDef & {
Expand Down Expand Up @@ -46,7 +47,8 @@ export function Waypoint({
"idle"
);

const { timeline } = useScrollytelling();
const { timeline, } = useScrollytelling();
const { getTimelineSpace } = useDispatcher();

const waypointLabel = label ?? `label-${id}`;

Expand All @@ -67,8 +69,9 @@ export function Waypoint({
});
generatedTween = gsap.getById<gsap.core.Tween>(id + "-tween");
}

const validAt = getValidAt(at);

const space = getTimelineSpace({ start: at, end: at })
if (!space) return

// create a new paused set
const newSet = gsap.set(
Expand Down Expand Up @@ -114,19 +117,20 @@ export function Waypoint({
};

// add it to the timeline
timeline.add(newSet, validAt);
timeline.add(newSet, space.position);

// this won't actually play it. it will enable it so that the timeline can play it whenever it needs to
newSet.play();

timeline.addLabel(waypointLabel, validAt);
timeline.addLabel(waypointLabel, space.position);

return () => {
gsap.getById(id)?.revert();
cleanupTween?.();
timeline.removeLabel(waypointLabel);
space.cleanup()
};
}, [at, disabled, id, waypointLabel, onCall, onReverseCall, timeline, tween]);
}, [at, disabled, getTimelineSpace, id, onCall, onReverseCall, timeline, tween, waypointLabel]);

if (children) {
return <Slot ref={ref}>{children}</Slot>;
Expand Down

0 comments on commit 1b708b9

Please sign in to comment.