1+ <template >
2+ <Page >
3+ <ActionBar >
4+ <Label text =" Simple Templates" />
5+ </ActionBar >
6+
7+ <GridLayout >
8+ <CollectionView
9+ ref =" collectionView"
10+ :items =" itemList"
11+ itemIdGenerator =" color"
12+ rowHeight =" 100"
13+ reorderEnabled
14+ @itemReordered =" onItemReordered"
15+ >
16+ <v-template >
17+ <GridLayout id =" test" rows =" *, auto" :backgroundColor =" item.color" >
18+ <StackLayout row =" 1" class =" item" @touch =" onTouch(item, $event)" >
19+ <Label row =" 1" :text =" item.name" class =" title" />
20+ <Label row =" 1" :text =" item.color" class =" subtitle" />
21+ </StackLayout >
22+ </GridLayout >
23+ </v-template >
24+ </CollectionView >
25+ </GridLayout >
26+ </Page >
27+ </template >
28+
29+ <script >
30+ import { ObservableArray } from ' @nativescript/core' ;
31+ export default {
32+ data () {
33+ const items = new ObservableArray ([
34+ { type: ' item' , name: ' TURQUOISE' , color: ' #1abc9c' },
35+ { type: ' item' , name: ' EMERALD' , color: ' #2ecc71' },
36+ { type: ' item' , name: ' PETER RIVER' , color: ' #3498db' },
37+ { type: ' item' , name: ' AMETHYST' , color: ' #9b59b6' },
38+ { type: ' item' , name: ' GREEN SEA' , color: ' #16a085' },
39+ { type: ' item' , name: ' NEPHRITIS' , color: ' #27ae60' },
40+ { type: ' item' , name: ' BELIZE HOLE' , color: ' #2980b9' },
41+ { type: ' item' , name: ' ASBESTOS' , color: ' #7f8c8d' },
42+ { type: ' item' , name: ' MIDNIGHT BLUE' , color: ' #2c3e50' },
43+ { type: ' item' , name: ' SUN FLOWER' , color: ' #f1c40f' },
44+ { type: ' item' , name: ' CARROT' , color: ' #e67e22' },
45+ { type: ' item' , name: ' POMEGRANATE' , color: ' #c0392b' },
46+ { type: ' item' , name: ' CLOUDS' , color: ' #ecf0f1' },
47+ { type: ' item' , name: ' CONCRETE' , color: ' #95a5a6' },
48+ { type: ' item' , name: ' ORANGE' , color: ' #f39c12' },
49+ { type: ' item' , name: ' PUMPKIN' , color: ' #d35400' },
50+ ]);
51+ return {
52+ itemList: items
53+ };
54+ },
55+ methods: {
56+ logEvent (e ) {
57+ console .log (' logEvent' , e .eventName , e .extraData );
58+ },
59+ onItemReordered () {},
60+ onTouch (item , event ) {
61+ if (event .action === ' down' ) {
62+ const pointer = event .getActivePointers ()[0 ];
63+ this .$refs .collectionView .nativeView .startDragging (this .itemList .indexOf (item), pointer);
64+ }
65+ }
66+ }
67+ };
68+ </script >
69+
70+ <style scoped lang="scss">
71+ ActionBar {
72+ background-color : #42b883 ;
73+ }
74+ .item {
75+ padding : 10 ;
76+ color : white ;
77+ .title {
78+ font-size : 17 ;
79+ font-weight : bold ;
80+ }
81+ .subtitle {
82+ font-size : 14 ;
83+ }
84+ }
85+ </style >
0 commit comments