Skip to content

Update listview demo #55

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 3 commits into from
Apr 19, 2019
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
2 changes: 1 addition & 1 deletion listview/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ This is a demo application that showcases the plugin in action.

# Running the application

If you are coming here for the first time after cloning the repository make sure to build the plugin's code located in the `src` folder. To build it simply run the `npm run postclone` scripts in `src`. After that you can use the NativeScripty CLI commands like `tns run` as usual.
Make sure you are using the latest NativeScript CLI version by running `npm i nativescript -g`. Then run `tns run android` or `tns run ios` depending on the platform you want to run the application on.
3 changes: 2 additions & 1 deletion listview/app/examples/GettingStarted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getItemList } from '../data';
import * as frameModule from "tns-core-modules/ui/frame";

const description = 'Getting Started';

// >> listview-getting-started-vue
export default {
name: 'GettingStarted',
description: description,
Expand Down Expand Up @@ -40,3 +40,4 @@ export default {
}
}
};
// << listview-getting-started-vue
3 changes: 2 additions & 1 deletion listview/app/examples/GridLayout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { simpleItemList } from '../data';
import * as frameModule from "tns-core-modules/ui/frame";

const description = 'Grid Layout';

// >> listvue-gridlayout-vue
export default {
name: 'GridLayoutList',
description: description,
Expand Down Expand Up @@ -41,3 +41,4 @@ export default {
}
}
};
// << listvue-gridlayout-vue
69 changes: 69 additions & 0 deletions listview/app/examples/GroupScrollTo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import * as frameModule from "tns-core-modules/ui/frame";
import { ObservableArray } from "tns-core-modules/data/observable-array";


export class DataItem {
public id: number;
public name: string;
public description: string;
public category: string;

constructor(id: number, name: string, description: string, category: string) {
this.id = id;
this.name = name;
this.description = description;
this.category = category;
}
}

const description = 'Grouping with Scroll to Index';
let items = [];
for (let i = 0; i < 50; i++) {
items.push(new DataItem(i, "item " + i, "description " + i, i % 2 === 0 ? "Group 1" : "Group 2"));
}
let dataItems = new ObservableArray<DataItem>(items);

export default {
name: 'GroupScrollTo',
description: description,
template: `
<Page>
<ActionBar :title="title">
<NavigationButton text="Back" android.systemIcon="ic_menu_back" @tap="onNavigationButtonTap"></NavigationButton>
</ActionBar>
<GridLayout rows="auto, *" rows="auto, *">
<Button text="Scroll to 1 index" @tap="onScrollTo"></Button>
<RadListView row="1" ref="myListView" for="item in itemList" :groupingFunction="getItemGroup">
<v-template>
<StackLayout>
<Label fontSize="20" :text="item.name"/>
<Label fontSize="14" :text="item.description"/>
</StackLayout>
</v-template>
<v-template name="group">
<GridLayout ios:height="50">
<Label :text="item.category" backgroundColor="lightblue" padding="15"/>
</GridLayout>
</v-template>
</RadListView>
</GridLayout>
</Page>
`,
data() {
return {
title: description,
itemList: dataItems,
};
},
methods: {
onNavigationButtonTap() {
frameModule.topmost().goBack();
},
getItemGroup(item) {
return item.category;
},
onScrollTo() {
this.$refs.myListView.nativeView.scrollToIndex(1);
}
}
};
65 changes: 65 additions & 0 deletions listview/app/examples/GroupWithHeaderFooter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import * as frameModule from "tns-core-modules/ui/frame";

const description = 'Group with header/footer';

export default {
name: 'Group with header/footer',
description: description,
template: `
<Page>
<ActionBar :title="title">
<NavigationButton text="Back" android.systemIcon="ic_menu_back" @tap="onNavigationButtonTap"></NavigationButton>
</ActionBar>
<GridLayout orientation="vertical" rows="auto, *">
<StackLayout orientation="horizontal">
<Button :text="isEnabled ? 'Disable grouping' : 'Enable grouping'" @tap="toggleGrouping"></Button>
</StackLayout>
<RadListView row="1" ref="myListView" for="item in itemList" :groupingFunction="getItemGroup">
<v-template>
<StackLayout class="item" orientation="vertical">
<Label :text="item.name" class="nameLabel"></Label>
</StackLayout>
</v-template>
<v-template name="header">
<Label text="Header with height auto" backgroundColor="#65a565" fontSize="45"></Label>
</v-template>
<v-template name="footer">
<Label text="Footer with height auto" backgroundColor="#7fff7f"></Label>
</v-template>
</RadListView>
</GridLayout>
</Page>
`,
data() {
return {
title: description,
isEnabled: true,
itemList: [
{ name: 'Item 1', group: 'Ready' },
{ name: 'Item 2', group: 'Completed' },
{ name: 'Item 3', group: 'Completed' },
{ name: 'Item 4', group: 'Ready' },
{ name: 'Item 5', group: 'Completed' },
{ name: 'Item 6', group: 'Completed' },
],
};
},
methods: {
onNavigationButtonTap() {
frameModule.topmost().goBack();
},
getItemGroup(item) {
return item.group;
},
toggleGrouping() {
let listView = this.$refs.myListView.nativeView;
if (!listView.groupingFunction) {
listView.groupingFunction = this.getItemGroup;
this.isEnabled = true;
} else {
listView.groupingFunction = undefined;
this.isEnabled = false;
}
}
}
};
3 changes: 2 additions & 1 deletion listview/app/examples/ItemReorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { simpleItemList } from '../data';
import * as frameModule from "tns-core-modules/ui/frame";

const description = 'Item Reorder';

// >> listview-itemreorder-vue
export default {
name: 'ItemReorder',
description: description,
Expand Down Expand Up @@ -41,3 +41,4 @@ export default {
}
}
};
// << listview-itemreorder-vue
3 changes: 2 additions & 1 deletion listview/app/examples/ItemSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as frameModule from "tns-core-modules/ui/frame";
import { ObservableArray } from 'tns-core-modules/data/observable-array';

const description = 'Item Selection';

// >> listview-itemselection-vue
export default {
name: 'ItemSelection',
description: description,
Expand Down Expand Up @@ -60,3 +60,4 @@ export default {
}
}
};
// << listview-itemselection-vue
75 changes: 75 additions & 0 deletions listview/app/examples/LoadOnDemand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { isIOS } from 'tns-core-modules/platform';
import { RadListView } from 'nativescript-ui-listview';
import { getItemList } from '../data';

const description = 'Load On Demand';

let allItems = getItemList(20);
const chunkSize = 6;

const nextItems = () => {
return allItems.splice(0, chunkSize);
};

const initItems = () => {
allItems = getItemList(20);
return allItems.splice(0, chunkSize);
};

export default {
name: 'LoadOnDemand',
description: description,
template: `
<Page>
<ActionBar :title="title">
<NavigationButton text="Back" android.systemIcon="ic_menu_back" @tap="onNavigationButtonTap"></NavigationButton>
</ActionBar>
<StackLayout>
<RadListView for="item in itemList"
loadOnDemandMode="Manual"
@loadMoreDataRequested="onLoadMoreItemsRequested">
<v-template>
<StackLayout class="item p-10" orientation="vertical">
<Label id="label" :text="item.name" class="nameLabel m-t-10"></Label>
<Label id="label" :text="item.description" class="descriptionLabel"></Label>
</StackLayout>
</v-template>
<v-template v-if="isIOS" name="loadondemand">
<GridLayout style="background-color: white">
<Label text="Load more" horizontalAlignment="center" verticalAlignment="center"></Label>
</GridLayout>
</v-template>
</RadListView>
</StackLayout>
</Page>
`,
data () {
return {
title: description,
itemList: initItems(),
isIOS: isIOS,
};
},
methods: {
onLoadMoreItemsRequested(args) {
const listView: RadListView = args.object;
let self = this;
if (allItems.length > 0) {
setTimeout(function () {
console.log('Loading more items...');
nextItems().forEach(item => {
self.itemList.push(item);
});
listView.notifyLoadOnDemandFinished();
}, 1500);
args.returnValue = true;
} else {
args.returnValue = false;
listView.notifyLoadOnDemandFinished(true);
}
},
onNavigationButtonTap() {
this.$navigateBack();
}
}
};
3 changes: 2 additions & 1 deletion listview/app/examples/MultipleTemplates.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as frameModule from "tns-core-modules/ui/frame";

const description = 'Multiple Templates';

// >> listview-multipletemplates-itemselector-vue
export default {
name: 'MultipleTemplates',
description: 'Multiple Templates',
Expand Down Expand Up @@ -90,3 +90,4 @@ export default {
},
}
};
// << listview-multipletemplates-itemselector-vue
3 changes: 2 additions & 1 deletion listview/app/examples/PullToRefresh.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as frameModule from "tns-core-modules/ui/frame";

const description = 'Pull To Refresh';

// >> listview-pulltorefresh-vue
export default {
name: 'PullToRefresh',
description: description,
Expand Down Expand Up @@ -74,3 +74,4 @@ export default {
}
}
};
// << listview-pulltorefresh-vue
3 changes: 2 additions & 1 deletion listview/app/examples/ScrollTo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as frameModule from "tns-core-modules/ui/frame";
import { ListViewItemSnapMode } from "nativescript-ui-listview";

const description = 'Scroll To Item';

// >> listview-scrolling-vue
export default {
name: 'ScrollTo',
description: description,
Expand Down Expand Up @@ -63,3 +63,4 @@ export default {
}
}
};
// << listview-scrolling-vue
3 changes: 2 additions & 1 deletion listview/app/examples/StaggeredLayout.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as frameModule from "tns-core-modules/ui/frame";

const description = 'Staggered Layout';

// >> listview-staggeredlayout-vue
const words = ['One', 'Two', 'Three', 'Four', 'Five', 'Six', 'Seven', 'Eight', 'Nine', 'Ten'];

const getRandomString = () => {
Expand Down Expand Up @@ -63,3 +63,4 @@ export default {
}
}
};
// << listview-staggeredlayout-vue
3 changes: 2 additions & 1 deletion listview/app/examples/SwipeActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { getItemList } from '../data';
import * as frameModule from 'tns-core-modules/ui/frame';

const description = 'Swipe Actions';

// >> listview-swipeactions-vue
export default {
name: 'SwipeActions',
description: description,
Expand Down Expand Up @@ -72,3 +72,4 @@ export default {
},
}
};
// << listview-swipeactions-vue
6 changes: 6 additions & 0 deletions listview/app/examples/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,16 @@ import ItemAnimations from './ItemAnimations';
import ItemLoading from './ItemLoading';
import ItemReorder from './ItemReorder';
import ItemSelection from './ItemSelection';
import LoadOnDemand from './LoadOnDemand';
import MultipleTemplates from './MultipleTemplates';
import Observable from './Observable';
import PullToRefresh from './PullToRefresh';
import ScrollTo from './ScrollTo';
import StaggeredLayout from './StaggeredLayout';
import SwipeActions from './SwipeActions';
import Group from './Group';
import GroupScrollTo from './GroupScrollTo';
import GroupWithHeaderFooter from './GroupWithHeaderFooter';
import TemplateGroup from './TemplateGroup';

export const getExamples = () => {
Expand All @@ -25,8 +28,11 @@ export const getExamples = () => {
ItemLoading,
ItemReorder,
ItemSelection,
LoadOnDemand,
MultipleTemplates,
Group,
GroupScrollTo,
GroupWithHeaderFooter,
TemplateGroup,
ScrollTo,
SwipeActions,
Expand Down
Loading