feat: adding ordering and next sibling method to flex layout (#615)

* feat: adding methods to get the child index and next child

* feat: ordering children properly in insert before
This commit is contained in:
Shubham Zanwar 2020-06-28 17:31:05 +05:30 committed by GitHub
parent a79ff1fd38
commit c54826de6a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -72,7 +72,13 @@ export class FlexLayout extends NodeLayout<FlexLayoutSignals> {
this.removeWidget(childWidget, childYogaNode);
}
const beforeChildYogaNode = beforeChildFlexNode || beforeChildWidget.getFlexNode();
this.nodeChildren.add(childWidget); // No orderer required yet, so just inserting at the end.
const widgetArr = Array.from(this.nodeChildren);
const beforeChildIndex = this.getChildIndex(beforeChildWidget);
if (beforeChildIndex !== -1) {
widgetArr.splice(beforeChildIndex, 0, childWidget);
}
this.nodeChildren = new Set(widgetArr);
this.native.insertChildBefore(childWidget.native, beforeChildYogaNode, childYogaNode);
}
@ -89,4 +95,18 @@ export class FlexLayout extends NodeLayout<FlexLayoutSignals> {
this.flexNode = flexNode;
this.native.setFlexNode(flexNode);
}
getChildIndex(childWidget: NodeWidget<any>): number {
const widgetArr = Array.from(this.nodeChildren);
return widgetArr.indexOf(childWidget);
}
getNextSibling(childWidget: NodeWidget<any>): NodeWidget<any> | null {
const childIndex = this.getChildIndex(childWidget);
const widgetArr = Array.from(this.nodeChildren);
if (childIndex !== -1) {
return (widgetArr[childIndex + 1] as NodeWidget<any>) || null;
}
return null;
}
}