Skip to content

Commit

Permalink
fix(skipInLayout): fix layout object check in setParent
Browse files Browse the repository at this point in the history
  • Loading branch information
basvanmeurs committed Apr 15, 2020
1 parent e213713 commit 7447504
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/FlexNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -670,11 +670,11 @@ export default class FlexNode {
return this.isFlexEnabled() && !this.isFlexItemEnabled();
}

private static getActiveLayoutNode(subject: FlexSubject | undefined): FlexNode | undefined {
static getActiveLayoutNode(subject: FlexSubject | undefined): FlexNode | undefined {
return this.getActiveLayoutSubject(subject)?.getLayout();
}

private static getActiveLayoutSubject(subject: FlexSubject | undefined): FlexSubject | undefined {
static getActiveLayoutSubject(subject: FlexSubject | undefined): FlexSubject | undefined {
let current: FlexSubject | undefined = subject;
while (current && current.hasLayout() && current.getLayout().skip) {
current = current.getParent();
Expand Down
2 changes: 1 addition & 1 deletion src/FlexTarget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ export default class FlexTarget implements FlexSubject {
if (this._parent !== p) {
const prevParent = this._parent;
this._parent = p;
if (this._layout || (p && p.getLayout().isFlexEnabled())) {
if (this._layout || FlexNode.getActiveLayoutNode(p)?.isFlexEnabled()) {
this.layout.setParent(prevParent, p);
}

Expand Down
45 changes: 45 additions & 0 deletions tests/test.tunnel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,51 @@ describe("tunnel", () => {
});
});

describe("add new flex item", () => {
let root: any;

const getRoot = () => root;
const addUpdateTest = (name: string, setup: any) => {
flexTestUtils.addAnnotatedUpdateTest(getRoot, name, setup);
};

let subject: Target;

before(() => {
const structure = {
r: [0, 0, 100, 100],
children: [
{
skipInLayout: true,
r: [0, 0, 0, 0],
},
],
};

root = flexTestUtils.buildFlexFromStructure(structure);

subject = root.children[0];

root.flex = true;

const child = new Target();
Target.patch(root, { w: 100, h: 100, r: [0, 0, 100, 100] });

subject.addChild(child);
});

describe("initial", () => {
it("layouts", () => {
return flexTestUtils.validateAnnotatedFlex(root);
});
});

addUpdateTest("no changes", () => {
return { layouts: [] };
});

});

describe("absolute", () => {
let root: any;

Expand Down

0 comments on commit 7447504

Please sign in to comment.