Skip to content

fix: support both old and new gridlayout addRow APIs #473

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/core-tabs/tab-content-item/index.android.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GridLayout, Trace, View } from '@nativescript/core';
import { addGridLayoutRow } from '@nativescript-community/ui-material-core/android/utils';
import { TabContentItem as TabContentItemDefinition } from '.';
import { TabContentItemBase } from './tab-content-item-common';

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

public createNativeView() {
const layout = new org.nativescript.widgets.GridLayout(this._context);
layout.addRow(1, org.nativescript.widgets.GridUnitType.star);
addGridLayoutRow(layout, 1, org.nativescript.widgets.GridUnitType.star);

return layout;
}
Expand Down
9 changes: 5 additions & 4 deletions src/core-tabs/tab-navigation/index.android.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Application, Color, CoreTypes, Font, ImageAsset, ImageSource, Utils, getTransformedText } from '@nativescript/core';
import { addGridLayoutRow } from '@nativescript-community/ui-material-core/android/utils';
import { TabContentItem } from '../tab-content-item';
import { getIconSpecSize, itemsProperty, selectedIndexProperty, tabStripProperty } from '../tab-navigation-base';
import { TabStrip } from '../tab-strip';
Expand Down Expand Up @@ -222,13 +223,13 @@ export abstract class TabNavigation<T extends android.view.ViewGroup = any> exte
const lp = new org.nativescript.widgets.CommonLayoutParams();
lp.row = 1;
if (this.tabsPosition === 'top') {
nativeView.addRow(1, org.nativescript.widgets.GridUnitType.auto);
nativeView.addRow(1, org.nativescript.widgets.GridUnitType.star);
addGridLayoutRow(nativeView, 1, org.nativescript.widgets.GridUnitType.auto);
addGridLayoutRow(nativeView, 1, org.nativescript.widgets.GridUnitType.star);

viewPager.setLayoutParams(lp);
} else {
nativeView.addRow(1, org.nativescript.widgets.GridUnitType.star);
nativeView.addRow(1, org.nativescript.widgets.GridUnitType.auto);
addGridLayoutRow(nativeView, 1, org.nativescript.widgets.GridUnitType.star);
addGridLayoutRow(nativeView, 1, org.nativescript.widgets.GridUnitType.auto);
this.tabBarLayoutParams = lp;
}

Expand Down
20 changes: 20 additions & 0 deletions src/core/android/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,23 @@ export function inflateLayout(context: android.content.Context, layoutId: string
}
return NUtils.inflateLayout(context, layoutId);
}

let isNewGridAPI: boolean | undefined;

export function addGridLayoutRow(gridLayout: org.nativescript.widgets.GridLayout, value: number, unitType: org.nativescript.widgets.GridUnitType) {
if (isNewGridAPI === undefined) {
try {
gridLayout.addRow(value, unitType);
isNewGridAPI = true;
return;
} catch (e) {
isNewGridAPI = false;
}
}
if (isNewGridAPI) {
gridLayout.addRow(value, unitType);
} else {
// @ts-expect-error older API
gridLayout.addRow(new org.nativescript.widgets.ItemSpec(value, unitType));
}
}
52 changes: 26 additions & 26 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3590,49 +3590,49 @@ __metadata:
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-activityindicator@workspace:packages/activityindicator"
dependencies:
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
languageName: unknown
linkType: soft

"@nativescript-community/ui-material-bottom-navigation@npm:*, @nativescript-community/ui-material-bottom-navigation@workspace:packages/bottom-navigation":
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-bottom-navigation@workspace:packages/bottom-navigation"
dependencies:
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-core-tabs": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
"@nativescript-community/ui-material-core-tabs": "npm:^7.2.69"
languageName: unknown
linkType: soft

"@nativescript-community/ui-material-bottomnavigationbar@npm:*, @nativescript-community/ui-material-bottomnavigationbar@workspace:packages/bottomnavigationbar":
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-bottomnavigationbar@workspace:packages/bottomnavigationbar"
dependencies:
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
languageName: unknown
linkType: soft

"@nativescript-community/ui-material-bottomsheet@npm:*, @nativescript-community/ui-material-bottomsheet@workspace:packages/bottomsheet":
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-bottomsheet@workspace:packages/bottomsheet"
dependencies:
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
languageName: unknown
linkType: soft

"@nativescript-community/ui-material-button@npm:*, @nativescript-community/ui-material-button@npm:^7.2.68, @nativescript-community/ui-material-button@workspace:packages/button":
"@nativescript-community/ui-material-button@npm:*, @nativescript-community/ui-material-button@npm:^7.2.69, @nativescript-community/ui-material-button@workspace:packages/button":
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-button@workspace:packages/button"
dependencies:
"@nativescript-community/text": "npm:^1.5.2"
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
languageName: unknown
linkType: soft

"@nativescript-community/ui-material-cardview@npm:*, @nativescript-community/ui-material-cardview@workspace:packages/cardview":
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-cardview@workspace:packages/cardview"
dependencies:
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
languageName: unknown
linkType: soft

Expand All @@ -3645,15 +3645,15 @@ __metadata:
languageName: unknown
linkType: soft

"@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":
"@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":
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-core-tabs@workspace:packages/core-tabs"
dependencies:
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
languageName: unknown
linkType: soft

"@nativescript-community/ui-material-core@npm:*, @nativescript-community/ui-material-core@npm:^7.2.68, @nativescript-community/ui-material-core@workspace:packages/core":
"@nativescript-community/ui-material-core@npm:*, @nativescript-community/ui-material-core@npm:^7.2.69, @nativescript-community/ui-material-core@workspace:packages/core":
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-core@workspace:packages/core"
languageName: unknown
Expand All @@ -3663,83 +3663,83 @@ __metadata:
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-dialogs@workspace:packages/dialogs"
dependencies:
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-textfield": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
"@nativescript-community/ui-material-textfield": "npm:^7.2.69"
languageName: unknown
linkType: soft

"@nativescript-community/ui-material-floatingactionbutton@npm:*, @nativescript-community/ui-material-floatingactionbutton@workspace:packages/floatingactionbutton":
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-floatingactionbutton@workspace:packages/floatingactionbutton"
dependencies:
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
languageName: unknown
linkType: soft

"@nativescript-community/ui-material-progress@npm:*, @nativescript-community/ui-material-progress@workspace:packages/progress":
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-progress@workspace:packages/progress"
dependencies:
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
languageName: unknown
linkType: soft

"@nativescript-community/ui-material-ripple@npm:*, @nativescript-community/ui-material-ripple@workspace:packages/ripple":
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-ripple@workspace:packages/ripple"
dependencies:
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
languageName: unknown
linkType: soft

"@nativescript-community/ui-material-slider@npm:*, @nativescript-community/ui-material-slider@workspace:packages/slider":
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-slider@workspace:packages/slider"
dependencies:
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
languageName: unknown
linkType: soft

"@nativescript-community/ui-material-snackbar@npm:*, @nativescript-community/ui-material-snackbar@workspace:packages/snackbar":
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-snackbar@workspace:packages/snackbar"
dependencies:
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
languageName: unknown
linkType: soft

"@nativescript-community/ui-material-speeddial@npm:*, @nativescript-community/ui-material-speeddial@workspace:packages/speeddial":
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-speeddial@workspace:packages/speeddial"
dependencies:
"@nativescript-community/ui-material-button": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-button": "npm:^7.2.69"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
languageName: unknown
linkType: soft

"@nativescript-community/ui-material-switch@workspace:packages/switch":
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-switch@workspace:packages/switch"
dependencies:
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
languageName: unknown
linkType: soft

"@nativescript-community/ui-material-tabs@npm:*, @nativescript-community/ui-material-tabs@workspace:packages/tabs":
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-tabs@workspace:packages/tabs"
dependencies:
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-core-tabs": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
"@nativescript-community/ui-material-core-tabs": "npm:^7.2.69"
languageName: unknown
linkType: soft

"@nativescript-community/ui-material-textfield@npm:*, @nativescript-community/ui-material-textfield@npm:^7.2.68, @nativescript-community/ui-material-textfield@workspace:packages/textfield":
"@nativescript-community/ui-material-textfield@npm:*, @nativescript-community/ui-material-textfield@npm:^7.2.69, @nativescript-community/ui-material-textfield@workspace:packages/textfield":
version: 0.0.0-use.local
resolution: "@nativescript-community/ui-material-textfield@workspace:packages/textfield"
dependencies:
"@nativescript-community/text": "npm:^1.5.33"
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
languageName: unknown
linkType: soft

Expand All @@ -3748,7 +3748,7 @@ __metadata:
resolution: "@nativescript-community/ui-material-textview@workspace:packages/textview"
dependencies:
"@nativescript-community/text": "npm:^1.5.33"
"@nativescript-community/ui-material-core": "npm:^7.2.68"
"@nativescript-community/ui-material-core": "npm:^7.2.69"
languageName: unknown
linkType: soft

Expand Down