Skip to content

Commit

Permalink
#5401 layout.Card: slideCards() => logic for slideIn and slideOut
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiu committed Apr 22, 2024
1 parent 4eff10a commit 70f1a73
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/layout/Card.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -267,11 +267,12 @@ class Card extends Base {
{items} = container,
card = items[index],
oldCard = items[oldIndex],
height, rect, transform, vdom, x, width;
slideIn = index > oldIndex,
animationWrapper, height, rect, transform, vdom, x, width;

rect = await container.getDomRect(container.id);
height = `${rect.height}px`;
x = index > oldIndex ? 0 : -rect.width;
x = slideIn ? 0 : -rect.width;
transform = `translateX(${x}px)`;
vdom = container.vdom;
width = `${2 * rect.width}px`;
Expand All @@ -281,23 +282,26 @@ class Card extends Base {
vdom.cn = [
{cls: ['neo-relative'], cn: [
{cls: ['neo-animation-wrapper'], style: {height, transform, width}, cn: [
oldCard.vdom,
card.vdom
]}
]}
];

animationWrapper = vdom.cn[0].cn[0];

animationWrapper.cn[slideIn ? 'unshift' : 'push'](oldCard.vdom);

await container.promiseUpdate();

x = index > oldIndex ? -rect.width : 0;
x = slideIn ? -rect.width : 0;

vdom.cn[0].cn[0].style.transform = `translateX(${x}px)`;
animationWrapper.style.transform = `translateX(${x}px)`;

await container.promiseUpdate();

await me.timeout(300);

vdom.cn[0] = vdom.cn[0].cn[0].cn[1];
vdom.cn[0] = vdom.cn[0].cn[0].cn[slideIn ? 1 : 0];

await container.promiseUpdate()
}
Expand Down

0 comments on commit 70f1a73

Please sign in to comment.