Skip to content
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

perf: additional GridLayout optimizations #10428

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/ui/package.json
Expand Up @@ -7,8 +7,9 @@
"url": "https://github.com/NativeScript/NativeScript.git"
},
"dependencies": {
"@nativescript/core": "file:../../packages/core",
"nativescript-theme-core": "file:../../node_modules/nativescript-theme-core",
"@nativescript/core": "file:../../packages/core"
"pre-commit": "^1.2.2"
},
"devDependencies": {
"@nativescript/android": "~8.5.0",
Expand Down
37 changes: 37 additions & 0 deletions apps/ui/src/grid-layout/grid-layout-page.ts
@@ -0,0 +1,37 @@
import { EventData, GestureStateTypes, PanGestureEventData, Page, View, ScrollView, GridLayout } from '@nativescript/core';

var page;
export function pageLoaded(args: EventData) {
page = <Page>args.object;
}

let currentDeltaY = 0;
export function panLayout(args: PanGestureEventData) {
const view = <View>args.object;
const scrollView = <ScrollView>view.parent;

if (args.state === GestureStateTypes.began) {
currentDeltaY = 0;
scrollView.isScrollEnabled = false;
} else if (args.state === GestureStateTypes.changed) {
const diff = args.deltaY - currentDeltaY;
view.translateY += diff;
currentDeltaY = args.deltaY;
} else if (args.state === GestureStateTypes.ended) {
scrollView.isScrollEnabled = true;
}
}

let isShowingGridLayout: boolean = true;

export function showHide() {
let gridContainer = page.getViewById('grid-container');
console.log('tap tap');
isShowingGridLayout = !isShowingGridLayout;

if (!isShowingGridLayout) {
gridContainer.visibility = 'hidden';
} else {
gridContainer.visibility = 'visible';
}
}
79 changes: 79 additions & 0 deletions apps/ui/src/grid-layout/grid-layout-page.xml
@@ -0,0 +1,79 @@
<Page xmlns="http://schemas.nativescript.org/tns.xsd" loaded="pageLoaded" class="page">
<ScrollView id="grid-layout" height="100%">
<GridLayout height="80%" backgroundColor="red" rows="auto auto">
<StackLayout backgroundColor="green">
<Button backgroundColor="mediumblue" color="#fff" height="42" width="80" fontSize="20" tap="showHide" text="Show It"></Button>
</StackLayout>
<StackLayout row="1">
<GridLayout id="grid-container" columns="* * * * * * *" rows="* * *" height="400">
<StackLayout col="0" row="0" backgroundColor='maroon'>
<Label text="TNT" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="1" row="0" backgroundColor="blue">
<Label text="DAM" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="2" row="0" backgroundColor="salmon">
<Label text="BAR" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="3" row="0" backgroundColor="olive">
<Label text="OLD" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="4" row="0" backgroundColor="cyan">
<Label text="OUR" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="5" row="0" backgroundColor="darkcyan">
<Label text="THE" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="6" row="0" backgroundColor="limegreen">
<Label text="PER" color="#fff" fontSize="22"/>
</StackLayout>

<StackLayout col="0" row="1" backgroundColor='sandybrown'>
<Label text="ROW" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="1" row="1" backgroundColor="teal">
<Label text="WIP" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="2" row="1" backgroundColor="salmon">
<Label text="HIP" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="3" row="1" backgroundColor="sienna">
<Label text="LIP" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="4" row="1" backgroundColor="red">
<Label text="SON" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="5" row="1" backgroundColor="darkcyan">
<Label text="MOO" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="6" row="1" backgroundColor="purple">
<Label text="DID" color="#fff" fontSize="22"/>
</StackLayout>

<StackLayout col="0" row="2" backgroundColor='silver'>
<Label text="VID" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="1" row="2" backgroundColor="peru">
<Label text="FOR" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="2" row="2" backgroundColor="seagreen">
<Label text="LOB" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="3" row="2" backgroundColor="olivedrab">
<Label text="MIN" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="4" row="2" backgroundColor="orchid">
<Label text="BIN" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="5" row="2" backgroundColor="orangered">
<Label text="END" color="#fff" fontSize="22"/>
</StackLayout>
<StackLayout col="6" row="2" backgroundColor="navy">
<Label text="ACE" color="#fff" fontSize="22"/>
</StackLayout>

</GridLayout>
</StackLayout>
</GridLayout>
</ScrollView>
</Page>
1 change: 1 addition & 0 deletions apps/ui/src/main-page.ts
Expand Up @@ -39,6 +39,7 @@ export function pageLoaded(args: EventData) {
examples.set('date-picker', 'date-picker/date-picker-page');
examples.set('nested-frames', 'nested-frames/main-page');
examples.set('screen-qualifiers', 'screen-qualifiers/main-page');
examples.set('grid-layout', 'grid-layout/grid-layout-page');
page.bindingContext = new MainPageViewModel(wrapLayout, examples);

const parent = page.getViewById('parentLayout');
Expand Down