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

fix: Filter layers that used on the current transition #2419

Merged
merged 3 commits into from
Sep 27, 2024
Merged
Changes from 1 commit
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
34 changes: 23 additions & 11 deletions src/storyMap/components/StoryMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const Title = props => {
);
};

const getTransition = (config, id) => {
const getTransition = ({ config, id, direction }) => {
const isTitle = id === 'story-map-title';
if (isTitle) {
return {
Expand All @@ -211,8 +211,13 @@ const getTransition = (config, id) => {
}
const chapterIndex = config.chapters.findIndex(chapter => chapter.id === id);
const chapter = config.chapters[chapterIndex];
const next =
direction === 'up'
? _.get(`chapters[${chapterIndex - 1}]`, config)
: _.get(`chapters[${chapterIndex + 1}]`, config);
return {
transition: chapter,
nextTransition: next,
index: chapterIndex,
};
};
Expand Down Expand Up @@ -427,14 +432,14 @@ const Scroller = props => {
offset: 0.5,
})
.onStepEnter(async response => {
const { index, transition } = getTransition(
{
const { index, transition } = getTransition({
config: {
titleTransition: config.titleTransition,
chapters: config.chapters,
},
response.element.id
);

id: response.element.id,
direction: response.direction,
});
response.element.classList.add('active');
startTransition(transition);
onStepChange?.(response.element.id);
Expand All @@ -451,16 +456,23 @@ const Scroller = props => {
}
})
.onStepExit(response => {
const { transition } = getTransition(
{
const { transition, nextTransition } = getTransition({
config: {
titleTransition: config.titleTransition,
chapters: config.chapters,
},
response.element.id
);
id: response.element.id,
direction: response.direction,
});
response.element.classList.remove('active');
if (transition?.onChapterExit && transition.onChapterExit.length > 0) {
transition.onChapterExit.forEach(setLayerOpacity);
const onEnterLayers = nextTransition?.onChapterEnter?.map(
_.get('layer')
);
const filtered = transition.onChapterExit.filter(
transition => !_.includes(transition.layer, onEnterLayers)
);
filtered.forEach(setLayerOpacity);
}
});

Expand Down
Loading