Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a3f1493

Browse files
rakeshgiraseAlexander Vakrilov
authored andcommitted
5620 GridLayout addChild to set row and column (NativeScript#6411)
1 parent 4407af7 commit a3f1493

File tree

3 files changed

+132
-0
lines changed

3 files changed

+132
-0
lines changed

tests/app/ui/layouts/grid-layout-tests.ts

Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,121 @@ export class GridLayoutTest extends testModule.UITest<RemovalTrackingGridLayout>
183183
GridLayout.setColumnSpan(new Button(), 0);
184184
}
185185

186+
public test_addChildAtCell_with_all_params() {
187+
let btn = new Button();
188+
let row: number = 1;
189+
let column: number = 2;
190+
let rowSpan: number = 3;
191+
let columnSpan: number = 4;
192+
this.testView.addChildAtCell(btn, row, column, rowSpan, columnSpan);
193+
TKUnit.assertEqual(
194+
this.row(btn),
195+
row,
196+
"'row' property not applied For GridLayout addChildAtCell."
197+
);
198+
TKUnit.assertEqual(
199+
this.col(btn),
200+
column,
201+
"'column' property not applied For GridLayout addChildAtCell."
202+
);
203+
TKUnit.assertEqual(
204+
this.rowSpan(btn),
205+
rowSpan,
206+
"'rowSpan' property not applied For GridLayout addChildAtCell."
207+
);
208+
TKUnit.assertEqual(
209+
this.colSpan(btn),
210+
columnSpan,
211+
"'columnSpan' property not applied For GridLayout addChildAtCell."
212+
);
213+
}
214+
215+
public test_addChildAtCell_without_optional_params() {
216+
let btn = new Button();
217+
let row: number = 1;
218+
let column: number = 2;
219+
let defaultSpanValue: number = 1;
220+
this.testView.addChildAtCell(btn, row, column);
221+
TKUnit.assertEqual(
222+
this.row(btn),
223+
row,
224+
"'row' property not applied For GridLayout addChildAtCell."
225+
);
226+
TKUnit.assertEqual(
227+
this.col(btn),
228+
column,
229+
"'column' property not applied For GridLayout addChildAtCell."
230+
);
231+
TKUnit.assertEqual(
232+
this.rowSpan(btn),
233+
defaultSpanValue,
234+
"'rowSpan' property not applied For GridLayout addChildAtCell without optional params."
235+
);
236+
TKUnit.assertEqual(
237+
this.colSpan(btn),
238+
defaultSpanValue,
239+
"'colSpan' property not applied For GridLayout addChildAtCell without optional params."
240+
);
241+
}
242+
243+
public test_addChildAtCell_without_rowSpan() {
244+
let btn = new Button();
245+
let row: number = 1;
246+
let column: number = 2;
247+
let columnSpan: number = 2;
248+
let defaultSpanValue: number = 1;
249+
this.testView.addChildAtCell(btn, row, column, undefined, columnSpan);
250+
TKUnit.assertEqual(
251+
this.row(btn),
252+
row,
253+
"'row' property not applied For GridLayout addChildAtCell without rowspan."
254+
);
255+
TKUnit.assertEqual(
256+
this.col(btn),
257+
column,
258+
"'column' property not applied For GridLayout addChildAtCell without rowspan."
259+
);
260+
TKUnit.assertEqual(
261+
this.rowSpan(btn),
262+
defaultSpanValue,
263+
"'rowSpan' property not applied For GridLayout addChildAtCell without rowspan."
264+
);
265+
TKUnit.assertEqual(
266+
this.colSpan(btn),
267+
columnSpan,
268+
"'columnSpan' property not applied For GridLayout addChildAtCell without rowspan."
269+
);
270+
}
271+
272+
public test_addChildAtCell_without_columnSpan() {
273+
let btn = new Button();
274+
let row: number = 1;
275+
let column: number = 2;
276+
let rowSpan: number = 2;
277+
let defaultSpanValue: number = 1;
278+
this.testView.addChildAtCell(btn, row, column, rowSpan);
279+
TKUnit.assertEqual(
280+
this.row(btn),
281+
row,
282+
"'row' property not applied For GridLayout addChildAtCell without columnSpan."
283+
);
284+
TKUnit.assertEqual(
285+
this.col(btn),
286+
column,
287+
"'column' property not applied For GridLayout addChildAtCell without columnSpan."
288+
);
289+
TKUnit.assertEqual(
290+
this.rowSpan(btn),
291+
rowSpan,
292+
"'rowSpan' property not applied For GridLayout addChildAtCell without columnSpan."
293+
);
294+
TKUnit.assertEqual(
295+
this.colSpan(btn),
296+
defaultSpanValue,
297+
"'columnSpan' property not applied For GridLayout addChildAtCell without columnSpan."
298+
);
299+
}
300+
186301
public test_addRow_shouldThrow_onNullValues() {
187302
TKUnit.assertThrows(() => {
188303
this.testView.addRow(null);

tns-core-modules/ui/layouts/grid-layout/grid-layout-common.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,18 @@ export class GridLayoutBase extends LayoutBase implements GridLayoutDefinition {
178178
this.invalidate();
179179
}
180180

181+
public addChildAtCell(view: View, row: number, column: number, rowSpan?: number, columnSpan?: number): void {
182+
this.addChild(view);
183+
GridLayoutBase.setRow(view, row);
184+
GridLayoutBase.setColumn(view, column);
185+
if (rowSpan) {
186+
GridLayoutBase.setRowSpan(view, rowSpan);
187+
}
188+
if (columnSpan) {
189+
GridLayoutBase.setColumnSpan(view, columnSpan);
190+
}
191+
}
192+
181193
public removeRow(itemSpec: ItemSpec): void {
182194
if (!itemSpec) {
183195
throw new Error("Value is null.");

tns-core-modules/ui/layouts/grid-layout/grid-layout.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,11 @@ export class GridLayout extends LayoutBase {
101101
*/
102102
public addRow(itemSpec: ItemSpec): void;
103103

104+
/**
105+
* Adds a child at specific cell in GridLayout. Optional rowSpan and columnSpan attributes
106+
*/
107+
public addChildAtCell(view: View, row: number, column: number, rowSpan?: number, columnSpan?: number): void;
108+
104109
/**
105110
* Removes a column specification from a GridLayout.
106111
*/

0 commit comments

Comments
 (0)