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(NavigationManager): allow itemPosX and itemPosY to animate #483

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import lng from '@lightningjs/core';
import { context } from '../../globals';
import { flatten, getWidthByUpCount } from '../../utils';
import Row from '../Row';
import TitleRow from '../TitleRow';
import Tile from '../Tile';
import Button from '../Button';
import { default as ColumnComponent } from '.';
Expand All @@ -36,6 +37,19 @@ const columnHeight =
context.theme.layout.screenH -
2 * (context.theme.layout.marginY + context.theme.layout.gutterY);

const createRows = (rowType, length, style, items) => {
return Array.from({ length }).map((_, i) => {
return {
type: rowType,
title: `Row ${i}`,
autoResizeHeight: true,
w: getWidthByUpCount(context.theme, 1),
items,
style
};
});
};

// creates an array of buttons to be used in Stories
const createItems = (buttonType, length, isVariedHeight, isDynamicWidth) => {
return Array.from({ length }).map((_, i) => {
Expand Down Expand Up @@ -770,3 +784,23 @@ RemovingItems.parameters = {
storyDetails:
'The third button in this column is configured to invoke removeItemAt to remove that button. Focus on that button and press Enter to invoke that method and remove the button from the column.'
};

export const ShiftingItemPos = () =>
class ShiftingItemPos extends lng.Component {
static _template() {
return {
Column: {
type: ColumnComponent,
h:
context.theme.layout.screenH -
2 * (context.theme.layout.marginY + context.theme.layout.gutterY),
items: createRows(
TitleRow,
10,
{ mode: { focused: { titleMarginBottom: 100 } } },
createItems(Button, 10)
)
}
};
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ exports[`ControlRow renders 1`] = `
"visible": true,
"w": 880,
"x": -40,
"y": 68,
"y": 20,
"zIndex": 0,
},
"Title": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default class FocusManager extends Base {
}

static get properties() {
return ['direction', 'wrapSelected'];
return ['direction', 'wrapSelected', 'itemPosX', 'itemPosY'];
}

_construct() {
Expand Down Expand Up @@ -89,22 +89,6 @@ export default class FocusManager extends Base {
this._checkSkipFocus();
}

set itemPosX(x) {
this.Items.x = this._itemPosX = x;
}

get itemPosX() {
return this._itemPosX;
}

set itemPosY(y) {
this.Items.y = this._itemPosY = y;
}

get itemPosY() {
return this._itemPosY;
}

_resetItems() {
this.Items.childList.clear();
this.Items.patch({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,16 @@ export default class NavigationManager extends FocusManager {
}

_update() {
super._update();
this._updateDefaultItemPos();
this._updateLayout();
}

_updateDefaultItemPos() {
const itemPos = this._isRow ? { y: this.itemPosY } : { x: this.itemPosX };
this.applySmooth(this.Items, itemPos);
}

_updateLayout() {
const { lengthDimension, crossDimension, crossAxis, innerCrossDimension } =
this._directionPropNames;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ export default class TitleRow extends Row {
}

_update() {
super._update();
this._updateTitle();
this._updateRow();
super._update();
}

_autoResize() {
this.w = this.w || this.style.w;
this.h = this.autoResizeHeight ? this.Items.y + this.Items.h : this.h;
this.h = this.autoResizeHeight ? this.itemPosY + this.Items.h : this.h;
}

_updateTitle() {
Expand Down Expand Up @@ -94,9 +94,10 @@ export default class TitleRow extends Row {
}

_updateRow() {
this.applySmooth(this.Items, {
y: this.title ? this._Title.finalH + this.style.titleMarginBottom : 0
});
this.itemPosY =
this.title && this._Title
? this._Title.finalH + this.style.titleMarginBottom
: 0;
}

set announce(announce) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ describe('TitleRow', () => {
items
},
{
spyOnMethods: ['_titleLoaded']
spyOnMethods: ['_update']
}
);
expect(titleRow._Items.y).toBe(titleRow.style.titleMarginBottom);

await titleRow.__titleLoadedSpyPromise;
await titleRow.__updateSpyPromise;

expect(titleRow._Items.y).toBe(
titleRow._Title.finalH + titleRow.style.titleMarginBottom
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ exports[`TitleRow renders 1`] = `
"visible": true,
"w": 2220,
"x": 0,
"y": 68,
"y": 20,
"zIndex": 0,
},
"Title": {
Expand Down
Loading