Merge pull request #863 from NativeScript/layout-changes

Layout changes
This commit is contained in:
Vladimir Enchev
2015-10-01 13:57:38 +03:00
5 changed files with 47 additions and 10 deletions

View File

@ -202,6 +202,22 @@ export class GridLayout extends layouts.LayoutBase implements definition.GridLay
this.onColumnRemoved(itemSpec, index); this.onColumnRemoved(itemSpec, index);
} }
public removeColumns() {
for (var i = 0; i < this._cols.length; i++) {
this._cols[i].index = -1;
}
this._cols.length = 0;
this.invalidate();
}
public removeRows() {
for (var i = 0; i < this._rows.length; i++) {
this._rows[i].index = -1;
}
this._rows.length = 0;
this.invalidate();
}
protected onRowChanged(element: view.View, oldValue: number, newValue: number) { protected onRowChanged(element: view.View, oldValue: number, newValue: number) {
// //
} }

View File

@ -119,23 +119,33 @@
/** /**
* Adds a column specification to a GridLayout. * Adds a column specification to a GridLayout.
*/ */
public addColumn(itemSpec: ItemSpec); public addColumn(itemSpec: ItemSpec): void;
/** /**
* Adds a row specification to a GridLayout. * Adds a row specification to a GridLayout.
*/ */
public addRow(itemSpec: ItemSpec); public addRow(itemSpec: ItemSpec): void;
/** /**
* Removes a column specification from a GridLayout. * Removes a column specification from a GridLayout.
*/ */
public removeColumn(itemSpec: ItemSpec): void; public removeColumn(itemSpec: ItemSpec): void;
/**
* Removes all columns specification from a GridLayout.
*/
public removeColumns(): void;
/** /**
* Removes a row specification from a GridLayout. * Removes a row specification from a GridLayout.
*/ */
public removeRow(itemSpec: ItemSpec): void; public removeRow(itemSpec: ItemSpec): void;
/**
* Removes all rows specification from a GridLayout.
*/
public removeRows(): void;
/** /**
* Gets array of column specifications defined on this instance of GridLayout. * Gets array of column specifications defined on this instance of GridLayout.
*/ */

View File

@ -12,7 +12,7 @@ export class GridLayout extends common.GridLayout {
protected onRowAdded(itemSpec: common.ItemSpec) { protected onRowAdded(itemSpec: common.ItemSpec) {
this.invalidate(); this.invalidate();
} }
protected onColumnAdded(itemSpec: common.ItemSpec) { protected onColumnAdded(itemSpec: common.ItemSpec) {
this.invalidate(); this.invalidate();

View File

@ -30,20 +30,25 @@
* Adds the view to children array. * Adds the view to children array.
* @param view The view to be added to the end of the children array. * @param view The view to be added to the end of the children array.
*/ */
addChild(view: view.View); addChild(view: view.View): void;
/** /**
* Inserts the view to children array at the specified index. * Inserts the view to children array at the specified index.
* @param view The view to be added to the end of the children array. * @param view The view to be added to the end of the children array.
* @param atIndex The insertion index. * @param atIndex The insertion index.
*/ */
insertChild(child: view.View, atIndex: number); insertChild(child: view.View, atIndex: number): void;
/** /**
* Removes the specified view from the children array. * Removes the specified view from the children array.
* @param view The view to remove from the children array. * @param view The view to remove from the children array.
*/ */
removeChild(view: view.View); removeChild(view: view.View): void;
/**
* Removes all views in this layout.
*/
removeChildren(): void;
/** /**
* Gets or sets padding style property. * Gets or sets padding style property.

View File

@ -37,18 +37,18 @@ export class LayoutBase extends view.CustomLayoutView implements definition.Layo
return view.getViewById(this, id); return view.getViewById(this, id);
} }
public addChild(child: view.View) { public addChild(child: view.View): void {
// TODO: Do we need this method since we have the core logic in the View implementation? // TODO: Do we need this method since we have the core logic in the View implementation?
this._addView(child); this._addView(child);
this._subViews.push(child); this._subViews.push(child);
} }
public insertChild(child: view.View, atIndex: number) { public insertChild(child: view.View, atIndex: number): void {
this._addView(child, atIndex); this._addView(child, atIndex);
this._subViews.splice(atIndex, 0, child); this._subViews.splice(atIndex, 0, child);
} }
public removeChild(child: view.View) { public removeChild(child: view.View): void {
this._removeView(child); this._removeView(child);
// TODO: consider caching the index on the child. // TODO: consider caching the index on the child.
@ -56,7 +56,13 @@ export class LayoutBase extends view.CustomLayoutView implements definition.Layo
this._subViews.splice(index, 1); this._subViews.splice(index, 1);
} }
public _eachChildView(callback: (child: view.View) => boolean) { public removeChildren(): void {
while (this.getChildrenCount() !== 0) {
this.removeChild(this._subViews[this.getChildrenCount() - 1]);
}
}
public _eachChildView(callback: (child: view.View) => boolean): void {
var i; var i;
var length = this._subViews.length; var length = this._subViews.length;
var retVal: boolean; var retVal: boolean;