From 75a88d721bc77f170890d70058fef8044abdd12b Mon Sep 17 00:00:00 2001 From: Sergey Vinogradov Date: Sun, 28 Nov 2021 12:10:49 +0300 Subject: [PATCH] fix: fix START => FINISH transition for sidebar not exceeding viewport --- src/fsm-actions.js | 1 + src/fsm-transitions.js | 13 +++++++++++-- test/transitions.test.js | 11 ++++++----- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/fsm-actions.js b/src/fsm-actions.js index 1712eb6..6dfc495 100644 --- a/src/fsm-actions.js +++ b/src/fsm-actions.js @@ -29,5 +29,6 @@ export default { $sideInner.style.position = 'absolute'; $sideInner.style.top = 'auto'; $sideInner.style.bottom = '0'; + console.log(_d); } } diff --git a/src/fsm-transitions.js b/src/fsm-transitions.js index f8f81a9..2410f74 100644 --- a/src/fsm-transitions.js +++ b/src/fsm-transitions.js @@ -6,7 +6,16 @@ export default { to: states.FINISH, when: (d) => [ d.isSideInnerWithinPath === true, - d.viewportTop + d.sideInnerHeight > d.finishPoint + d.isSideInnerWithinViewport === false, + d.viewportBottom > d.finishPoint + ] + }, + { + to: states.FINISH, + when: (d) => [ + d.isSideInnerWithinPath === true, + d.isSideInnerWithinViewport === true, + d.viewportTop + d.sideInnerHeight + d.bottomSpacing > d.finishPoint ] }, { @@ -60,7 +69,7 @@ export default { }, { to: states.FINISH, - when: (d) => [d.viewportTop + d.sideInnerHeight > d.finishPoint] + when: (d) => [d.viewportBottom > d.finishPoint] }, { to: states.TOP_FIXED, diff --git a/test/transitions.test.js b/test/transitions.test.js index eb8bdad..f546a66 100644 --- a/test/transitions.test.js +++ b/test/transitions.test.js @@ -205,11 +205,12 @@ describe('transitions', function() { // isSideInnerWithinPath === true describe('when height(content) > height(sidebarInner)', () => { beforeEach(async () => { - setContentHeight(sidebarInnerHeight * 2); + setContentHeight(sidebarInnerHeight * 1.5); await nextFrame(); }); - it('START => BOTTOM_FIXED', async () => { + it.only('START => BOTTOM_FIXED', async () => { + await scrollTo(); await scrollTo(getElementBottom(sidebarInnerElement) - window.innerHeight + 1); await forceUpdate(); expectTransitionTo(BOTTOM_FIXED); @@ -220,7 +221,7 @@ describe('transitions', function() { await forceUpdate(); expectTransitionTo(BOTTOM_FIXED); - setContentHeight(sidebarInnerHeight / 2); + setContentHeight(sidebarInnerHeight / 1.5); await forceUpdate(); expectTransitionTo(START); }); @@ -274,7 +275,7 @@ describe('transitions', function() { await forceUpdate(); expectTransitionTo(UNFIXED); - setContentHeight(sidebarInnerHeight / 2); + setContentHeight(sidebarInnerHeight / 1.5); await forceUpdate(); expectTransitionTo(START); }); @@ -408,7 +409,7 @@ describe('transitions', function() { }); it('START => FINISH', async () => { - await scrollTo(getElementBottom(contentElement) - window.innerHeight); + await scrollTo(getElementBottom(contentElement) - window.innerHeight + 1); await forceUpdate(); expectTransitionTo(FINISH); });