Skip to content

Commit 5e39c16

Browse files
committed
fix(NavigationManager): allow itemPosX and itemPosY to animate the Items element and adjust on the update lifecycle
1 parent 4a9c28a commit 5e39c16

File tree

4 files changed

+59
-17
lines changed

4 files changed

+59
-17
lines changed

packages/@lightningjs/ui-components/src/components/Column/Column.stories.js

+34
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import lng from '@lightningjs/core';
2020
import { context } from '../../globals';
2121
import { flatten, getWidthByUpCount } from '../../utils';
2222
import Row from '../Row';
23+
import TitleRow from '../TitleRow';
2324
import Tile from '../Tile';
2425
import Button from '../Button';
2526
import { default as ColumnComponent } from '.';
@@ -36,6 +37,19 @@ const columnHeight =
3637
context.theme.layout.screenH -
3738
2 * (context.theme.layout.marginY + context.theme.layout.gutterY);
3839

40+
const createRows = (rowType, length, style, items) => {
41+
return Array.from({ length }).map((_, i) => {
42+
return {
43+
type: rowType,
44+
title: `Row ${i}`,
45+
autoResizeHeight: true,
46+
w: getWidthByUpCount(context.theme, 1),
47+
items,
48+
style
49+
};
50+
});
51+
};
52+
3953
// creates an array of buttons to be used in Stories
4054
const createItems = (buttonType, length, isVariedHeight, isDynamicWidth) => {
4155
return Array.from({ length }).map((_, i) => {
@@ -770,3 +784,23 @@ RemovingItems.parameters = {
770784
storyDetails:
771785
'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.'
772786
};
787+
788+
export const ShiftingItemPos = () =>
789+
class ShiftingItemPos extends lng.Component {
790+
static _template() {
791+
return {
792+
Column: {
793+
type: ColumnComponent,
794+
h:
795+
context.theme.layout.screenH -
796+
2 * (context.theme.layout.marginY + context.theme.layout.gutterY),
797+
items: createRows(
798+
TitleRow,
799+
10,
800+
{ mode: { focused: { titleMarginBottom: 100 } } },
801+
createItems(Button, 10)
802+
)
803+
}
804+
};
805+
}
806+
};

packages/@lightningjs/ui-components/src/components/FocusManager/FocusManager.js

+13-13
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export default class FocusManager extends Base {
3939
}
4040

4141
static get properties() {
42-
return ['direction', 'wrapSelected'];
42+
return ['direction', 'wrapSelected', 'itemPosX', 'itemPosY'];
4343
}
4444

4545
_construct() {
@@ -89,21 +89,21 @@ export default class FocusManager extends Base {
8989
this._checkSkipFocus();
9090
}
9191

92-
set itemPosX(x) {
93-
this.Items.x = this._itemPosX = x;
94-
}
92+
// set itemPosX(x) {
93+
// this.Items.x = this._itemPosX = x;
94+
// }
9595

96-
get itemPosX() {
97-
return this._itemPosX;
98-
}
96+
// get itemPosX() {
97+
// return this._itemPosX;
98+
// }
9999

100-
set itemPosY(y) {
101-
this.Items.y = this._itemPosY = y;
102-
}
100+
// set itemPosY(y) {
101+
// this.Items.y = this._itemPosY = y;
102+
// }
103103

104-
get itemPosY() {
105-
return this._itemPosY;
106-
}
104+
// get itemPosY() {
105+
// return this._itemPosY;
106+
// }
107107

108108
_resetItems() {
109109
this.Items.childList.clear();

packages/@lightningjs/ui-components/src/components/NavigationManager/NavigationManager.js

+7
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,16 @@ export default class NavigationManager extends FocusManager {
104104
}
105105

106106
_update() {
107+
super._update();
108+
this._updateDefaultItemPos();
107109
this._updateLayout();
108110
}
109111

112+
_updateDefaultItemPos() {
113+
const itemPos = this._isRow ? { y: this.itemPosY } : { x: this.itemPosX };
114+
this.applySmooth(this.Items, itemPos);
115+
}
116+
110117
_updateLayout() {
111118
const { lengthDimension, crossDimension, crossAxis, innerCrossDimension } =
112119
this._directionPropNames;

packages/@lightningjs/ui-components/src/components/TitleRow/TitleRow.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ export default class TitleRow extends Row {
5252
}
5353

5454
_update() {
55+
this._updateRow();
5556
super._update();
5657
this._updateTitle();
57-
this._updateRow();
5858
}
5959

6060
_autoResize() {
@@ -94,9 +94,10 @@ export default class TitleRow extends Row {
9494
}
9595

9696
_updateRow() {
97-
this.applySmooth(this.Items, {
98-
y: this.title ? this._Title.finalH + this.style.titleMarginBottom : 0
99-
});
97+
this.itemPosY =
98+
this.title && this._Title
99+
? this._Title.finalH + this.style.titleMarginBottom
100+
: 0;
100101
}
101102

102103
set announce(announce) {

0 commit comments

Comments
 (0)