Skip to content

Commit 9f380f7

Browse files
authored
Merge pull request #473 from nativescript-community/fix/support-old-gridlayout-api
fix: support both old and new gridlayout addRow APIs
2 parents 8d003b2 + 9f9b157 commit 9f380f7

File tree

4 files changed

+53
-31
lines changed

4 files changed

+53
-31
lines changed

Diff for: src/core-tabs/tab-content-item/index.android.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { GridLayout, Trace, View } from '@nativescript/core';
2+
import { addGridLayoutRow } from '@nativescript-community/ui-material-core/android/utils';
23
import { TabContentItem as TabContentItemDefinition } from '.';
34
import { TabContentItemBase } from './tab-content-item-common';
45

@@ -14,7 +15,7 @@ export class TabContentItem extends TabContentItemBase {
1415

1516
public createNativeView() {
1617
const layout = new org.nativescript.widgets.GridLayout(this._context);
17-
layout.addRow(1, org.nativescript.widgets.GridUnitType.star);
18+
addGridLayoutRow(layout, 1, org.nativescript.widgets.GridUnitType.star);
1819

1920
return layout;
2021
}

Diff for: src/core-tabs/tab-navigation/index.android.ts

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { Application, Color, CoreTypes, Font, ImageAsset, ImageSource, Utils, getTransformedText } from '@nativescript/core';
2+
import { addGridLayoutRow } from '@nativescript-community/ui-material-core/android/utils';
23
import { TabContentItem } from '../tab-content-item';
34
import { getIconSpecSize, itemsProperty, selectedIndexProperty, tabStripProperty } from '../tab-navigation-base';
45
import { TabStrip } from '../tab-strip';
@@ -222,13 +223,13 @@ export abstract class TabNavigation<T extends android.view.ViewGroup = any> exte
222223
const lp = new org.nativescript.widgets.CommonLayoutParams();
223224
lp.row = 1;
224225
if (this.tabsPosition === 'top') {
225-
nativeView.addRow(1, org.nativescript.widgets.GridUnitType.auto);
226-
nativeView.addRow(1, org.nativescript.widgets.GridUnitType.star);
226+
addGridLayoutRow(nativeView, 1, org.nativescript.widgets.GridUnitType.auto);
227+
addGridLayoutRow(nativeView, 1, org.nativescript.widgets.GridUnitType.star);
227228

228229
viewPager.setLayoutParams(lp);
229230
} else {
230-
nativeView.addRow(1, org.nativescript.widgets.GridUnitType.star);
231-
nativeView.addRow(1, org.nativescript.widgets.GridUnitType.auto);
231+
addGridLayoutRow(nativeView, 1, org.nativescript.widgets.GridUnitType.star);
232+
addGridLayoutRow(nativeView, 1, org.nativescript.widgets.GridUnitType.auto);
232233
this.tabBarLayoutParams = lp;
233234
}
234235

Diff for: src/core/android/utils.ts

+20
Original file line numberDiff line numberDiff line change
@@ -263,3 +263,23 @@ export function inflateLayout(context: android.content.Context, layoutId: string
263263
}
264264
return NUtils.inflateLayout(context, layoutId);
265265
}
266+
267+
let isNewGridAPI: boolean | undefined;
268+
269+
export function addGridLayoutRow(gridLayout: org.nativescript.widgets.GridLayout, value: number, unitType: org.nativescript.widgets.GridUnitType) {
270+
if (isNewGridAPI === undefined) {
271+
try {
272+
gridLayout.addRow(value, unitType);
273+
isNewGridAPI = true;
274+
return;
275+
} catch (e) {
276+
isNewGridAPI = false;
277+
}
278+
}
279+
if (isNewGridAPI) {
280+
gridLayout.addRow(value, unitType);
281+
} else {
282+
// @ts-expect-error older API
283+
gridLayout.addRow(new org.nativescript.widgets.ItemSpec(value, unitType));
284+
}
285+
}

Diff for: yarn.lock

+26-26
Original file line numberDiff line numberDiff line change
@@ -3590,49 +3590,49 @@ __metadata:
35903590
version: 0.0.0-use.local
35913591
resolution: "@nativescript-community/ui-material-activityindicator@workspace:packages/activityindicator"
35923592
dependencies:
3593-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3593+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
35943594
languageName: unknown
35953595
linkType: soft
35963596

35973597
"@nativescript-community/ui-material-bottom-navigation@npm:*, @nativescript-community/ui-material-bottom-navigation@workspace:packages/bottom-navigation":
35983598
version: 0.0.0-use.local
35993599
resolution: "@nativescript-community/ui-material-bottom-navigation@workspace:packages/bottom-navigation"
36003600
dependencies:
3601-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3602-
"@nativescript-community/ui-material-core-tabs": "npm:^7.2.68"
3601+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
3602+
"@nativescript-community/ui-material-core-tabs": "npm:^7.2.69"
36033603
languageName: unknown
36043604
linkType: soft
36053605

36063606
"@nativescript-community/ui-material-bottomnavigationbar@npm:*, @nativescript-community/ui-material-bottomnavigationbar@workspace:packages/bottomnavigationbar":
36073607
version: 0.0.0-use.local
36083608
resolution: "@nativescript-community/ui-material-bottomnavigationbar@workspace:packages/bottomnavigationbar"
36093609
dependencies:
3610-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3610+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
36113611
languageName: unknown
36123612
linkType: soft
36133613

36143614
"@nativescript-community/ui-material-bottomsheet@npm:*, @nativescript-community/ui-material-bottomsheet@workspace:packages/bottomsheet":
36153615
version: 0.0.0-use.local
36163616
resolution: "@nativescript-community/ui-material-bottomsheet@workspace:packages/bottomsheet"
36173617
dependencies:
3618-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3618+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
36193619
languageName: unknown
36203620
linkType: soft
36213621

3622-
"@nativescript-community/ui-material-button@npm:*, @nativescript-community/ui-material-button@npm:^7.2.68, @nativescript-community/ui-material-button@workspace:packages/button":
3622+
"@nativescript-community/ui-material-button@npm:*, @nativescript-community/ui-material-button@npm:^7.2.69, @nativescript-community/ui-material-button@workspace:packages/button":
36233623
version: 0.0.0-use.local
36243624
resolution: "@nativescript-community/ui-material-button@workspace:packages/button"
36253625
dependencies:
36263626
"@nativescript-community/text": "npm:^1.5.2"
3627-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3627+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
36283628
languageName: unknown
36293629
linkType: soft
36303630

36313631
"@nativescript-community/ui-material-cardview@npm:*, @nativescript-community/ui-material-cardview@workspace:packages/cardview":
36323632
version: 0.0.0-use.local
36333633
resolution: "@nativescript-community/ui-material-cardview@workspace:packages/cardview"
36343634
dependencies:
3635-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3635+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
36363636
languageName: unknown
36373637
linkType: soft
36383638

@@ -3645,15 +3645,15 @@ __metadata:
36453645
languageName: unknown
36463646
linkType: soft
36473647

3648-
"@nativescript-community/ui-material-core-tabs@npm:*, @nativescript-community/ui-material-core-tabs@npm:^7.2.68, @nativescript-community/ui-material-core-tabs@workspace:packages/core-tabs":
3648+
"@nativescript-community/ui-material-core-tabs@npm:*, @nativescript-community/ui-material-core-tabs@npm:^7.2.69, @nativescript-community/ui-material-core-tabs@workspace:packages/core-tabs":
36493649
version: 0.0.0-use.local
36503650
resolution: "@nativescript-community/ui-material-core-tabs@workspace:packages/core-tabs"
36513651
dependencies:
3652-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3652+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
36533653
languageName: unknown
36543654
linkType: soft
36553655

3656-
"@nativescript-community/ui-material-core@npm:*, @nativescript-community/ui-material-core@npm:^7.2.68, @nativescript-community/ui-material-core@workspace:packages/core":
3656+
"@nativescript-community/ui-material-core@npm:*, @nativescript-community/ui-material-core@npm:^7.2.69, @nativescript-community/ui-material-core@workspace:packages/core":
36573657
version: 0.0.0-use.local
36583658
resolution: "@nativescript-community/ui-material-core@workspace:packages/core"
36593659
languageName: unknown
@@ -3663,83 +3663,83 @@ __metadata:
36633663
version: 0.0.0-use.local
36643664
resolution: "@nativescript-community/ui-material-dialogs@workspace:packages/dialogs"
36653665
dependencies:
3666-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3667-
"@nativescript-community/ui-material-textfield": "npm:^7.2.68"
3666+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
3667+
"@nativescript-community/ui-material-textfield": "npm:^7.2.69"
36683668
languageName: unknown
36693669
linkType: soft
36703670

36713671
"@nativescript-community/ui-material-floatingactionbutton@npm:*, @nativescript-community/ui-material-floatingactionbutton@workspace:packages/floatingactionbutton":
36723672
version: 0.0.0-use.local
36733673
resolution: "@nativescript-community/ui-material-floatingactionbutton@workspace:packages/floatingactionbutton"
36743674
dependencies:
3675-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3675+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
36763676
languageName: unknown
36773677
linkType: soft
36783678

36793679
"@nativescript-community/ui-material-progress@npm:*, @nativescript-community/ui-material-progress@workspace:packages/progress":
36803680
version: 0.0.0-use.local
36813681
resolution: "@nativescript-community/ui-material-progress@workspace:packages/progress"
36823682
dependencies:
3683-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3683+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
36843684
languageName: unknown
36853685
linkType: soft
36863686

36873687
"@nativescript-community/ui-material-ripple@npm:*, @nativescript-community/ui-material-ripple@workspace:packages/ripple":
36883688
version: 0.0.0-use.local
36893689
resolution: "@nativescript-community/ui-material-ripple@workspace:packages/ripple"
36903690
dependencies:
3691-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3691+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
36923692
languageName: unknown
36933693
linkType: soft
36943694

36953695
"@nativescript-community/ui-material-slider@npm:*, @nativescript-community/ui-material-slider@workspace:packages/slider":
36963696
version: 0.0.0-use.local
36973697
resolution: "@nativescript-community/ui-material-slider@workspace:packages/slider"
36983698
dependencies:
3699-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3699+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
37003700
languageName: unknown
37013701
linkType: soft
37023702

37033703
"@nativescript-community/ui-material-snackbar@npm:*, @nativescript-community/ui-material-snackbar@workspace:packages/snackbar":
37043704
version: 0.0.0-use.local
37053705
resolution: "@nativescript-community/ui-material-snackbar@workspace:packages/snackbar"
37063706
dependencies:
3707-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3707+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
37083708
languageName: unknown
37093709
linkType: soft
37103710

37113711
"@nativescript-community/ui-material-speeddial@npm:*, @nativescript-community/ui-material-speeddial@workspace:packages/speeddial":
37123712
version: 0.0.0-use.local
37133713
resolution: "@nativescript-community/ui-material-speeddial@workspace:packages/speeddial"
37143714
dependencies:
3715-
"@nativescript-community/ui-material-button": "npm:^7.2.68"
3716-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3715+
"@nativescript-community/ui-material-button": "npm:^7.2.69"
3716+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
37173717
languageName: unknown
37183718
linkType: soft
37193719

37203720
"@nativescript-community/ui-material-switch@workspace:packages/switch":
37213721
version: 0.0.0-use.local
37223722
resolution: "@nativescript-community/ui-material-switch@workspace:packages/switch"
37233723
dependencies:
3724-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3724+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
37253725
languageName: unknown
37263726
linkType: soft
37273727

37283728
"@nativescript-community/ui-material-tabs@npm:*, @nativescript-community/ui-material-tabs@workspace:packages/tabs":
37293729
version: 0.0.0-use.local
37303730
resolution: "@nativescript-community/ui-material-tabs@workspace:packages/tabs"
37313731
dependencies:
3732-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3733-
"@nativescript-community/ui-material-core-tabs": "npm:^7.2.68"
3732+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
3733+
"@nativescript-community/ui-material-core-tabs": "npm:^7.2.69"
37343734
languageName: unknown
37353735
linkType: soft
37363736

3737-
"@nativescript-community/ui-material-textfield@npm:*, @nativescript-community/ui-material-textfield@npm:^7.2.68, @nativescript-community/ui-material-textfield@workspace:packages/textfield":
3737+
"@nativescript-community/ui-material-textfield@npm:*, @nativescript-community/ui-material-textfield@npm:^7.2.69, @nativescript-community/ui-material-textfield@workspace:packages/textfield":
37383738
version: 0.0.0-use.local
37393739
resolution: "@nativescript-community/ui-material-textfield@workspace:packages/textfield"
37403740
dependencies:
37413741
"@nativescript-community/text": "npm:^1.5.33"
3742-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3742+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
37433743
languageName: unknown
37443744
linkType: soft
37453745

@@ -3748,7 +3748,7 @@ __metadata:
37483748
resolution: "@nativescript-community/ui-material-textview@workspace:packages/textview"
37493749
dependencies:
37503750
"@nativescript-community/text": "npm:^1.5.33"
3751-
"@nativescript-community/ui-material-core": "npm:^7.2.68"
3751+
"@nativescript-community/ui-material-core": "npm:^7.2.69"
37523752
languageName: unknown
37533753
linkType: soft
37543754

0 commit comments

Comments
 (0)