@nstudio/ui-collectionview 4.0.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +396 -0
- package/angular/collectionview.component.d.ts +82 -0
- package/angular/esm2020/collectionview.component.mjs +394 -0
- package/angular/esm2020/index.mjs +19 -0
- package/angular/esm2020/nstudio-ui-collectionview-angular.mjs +5 -0
- package/angular/fesm2015/nstudio-ui-collectionview-angular.mjs +421 -0
- package/angular/fesm2015/nstudio-ui-collectionview-angular.mjs.map +1 -0
- package/angular/fesm2020/nstudio-ui-collectionview-angular.mjs +416 -0
- package/angular/fesm2020/nstudio-ui-collectionview-angular.mjs.map +1 -0
- package/angular/index.d.ts +8 -0
- package/angular/package.json +26 -0
- package/common.d.ts +191 -0
- package/common.js +610 -0
- package/common.js.map +1 -0
- package/index.android.d.ts +117 -0
- package/index.android.js +1097 -0
- package/index.android.js.map +1 -0
- package/index.d.ts +16 -0
- package/index.ios.d.ts +118 -0
- package/index.ios.js +1123 -0
- package/index.ios.js.map +1 -0
- package/package.json +57 -0
- package/platforms/android/AndroidManifest.xml +3 -0
- package/platforms/android/include.gradle +7 -0
- package/platforms/android/java/com/nativescript/collectionview/Adapter.java +66 -0
- package/platforms/android/java/com/nativescript/collectionview/AdapterInterface.java +19 -0
- package/platforms/android/java/com/nativescript/collectionview/CollectionViewCellHolder.java +12 -0
- package/platforms/android/java/com/nativescript/collectionview/GridLayoutManager.java +72 -0
- package/platforms/android/java/com/nativescript/collectionview/OnScrollListener.java +35 -0
- package/platforms/android/java/com/nativescript/collectionview/PreCachingGridLayoutManager.java +51 -0
- package/platforms/android/java/com/nativescript/collectionview/RecycledViewPool.java +85 -0
- package/platforms/android/java/com/nativescript/collectionview/RecyclerView.java +46 -0
- package/platforms/android/java/com/nativescript/collectionview/SizeChangedListener.java +6 -0
- package/platforms/android/java/com/nativescript/collectionview/SpanSizeLookup.java +26 -0
- package/platforms/android/native-api-usage.json +29 -0
- package/platforms/android/res/layout/collectionview.xml +5 -0
- package/platforms/android/ui_collectionview.aar +0 -0
- package/react/index.d.ts +119 -0
- package/react/index.js +148 -0
- package/react/index.js.map +1 -0
- package/svelte/index.d.ts +21 -0
- package/svelte/index.js +143 -0
- package/svelte/index.js.map +1 -0
- package/vue/component.d.ts +38 -0
- package/vue/component.js +104 -0
- package/vue/component.js.map +1 -0
- package/vue/index.d.ts +4 -0
- package/vue/index.js +12 -0
- package/vue/index.js.map +1 -0
package/LICENSE
ADDED
@@ -0,0 +1,201 @@
|
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "{}"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright (c) 2015-2019 Progress Software Corporation
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
package/README.md
ADDED
@@ -0,0 +1,396 @@
|
|
1
|
+
All credits to [farfromrefug](https://github.com/farfromrefug) for `@nativescript-community/ui-collectionview`.
|
2
|
+
|
3
|
+
This customizes the community plugin to support:
|
4
|
+
- Adjusting cell behavior for more custom layouts
|
5
|
+
- Improved Angular support
|
6
|
+
|
7
|
+
<p align="center">
|
8
|
+
<b>Allows you to easily add a collection view (grid list view) to your projects. Supports vertical and horizontal modes, templating, and more.</b></br>
|
9
|
+
<sub><sub>
|
10
|
+
</p>
|
11
|
+
|
12
|
+
<br />
|
13
|
+
|
14
|
+
|
15
|
+
| <img src="https://github.com/nativescript-community/ui-collectionview/raw/master/images/demo-ios.gif" height="500" /> | <img src="https://github.com/nativescript-community/ui-collectionview/raw/master/images/demo-android.gif" height="500" /> |
|
16
|
+
| --- | ----------- |
|
17
|
+
| iOS Demo | Android Demo |
|
18
|
+
|
19
|
+
|
20
|
+
[](#table-of-contents)
|
21
|
+
|
22
|
+
## Table of Contents
|
23
|
+
|
24
|
+
- [Table of Contents](#table-of-contents)
|
25
|
+
- [Installation](#installation)
|
26
|
+
- [API](#api)
|
27
|
+
- [Events](#events)
|
28
|
+
- [Properties](#properties)
|
29
|
+
- [Methods](#methods)
|
30
|
+
- [Usage](#usage)
|
31
|
+
- [Simple Example](#simple-example)
|
32
|
+
- [Templates Example](#templates-example)
|
33
|
+
- [Usage in Angular](#usage-in-angular)
|
34
|
+
- [Simple Example](#simple-example-1)
|
35
|
+
- [Templates Example](#templates-example-1)
|
36
|
+
- [Usage in Vue](#usage-in-vue)
|
37
|
+
- [Simple Example](#simple-example-2)
|
38
|
+
- [Usage in Svelte](#usage-in-svelte)
|
39
|
+
- [Simple Example](#simple-example-3)
|
40
|
+
- [Usage in React](#usage-in-react)
|
41
|
+
- [Simple Example](#simple-example-4)
|
42
|
+
- [Questions](#questions)
|
43
|
+
|
44
|
+
|
45
|
+
[](#installation)
|
46
|
+
|
47
|
+
## Installation
|
48
|
+
Run the following command from the root of your project:
|
49
|
+
|
50
|
+
`npm install @nstudio/ui-collectionview`
|
51
|
+
|
52
|
+
|
53
|
+
[](#api)
|
54
|
+
|
55
|
+
## API
|
56
|
+
|
57
|
+
### Events
|
58
|
+
|
59
|
+
| Property | Description |
|
60
|
+
| ------------------- | ---------------------------------------------------------------------------- |
|
61
|
+
| itemLoading | Triggered when generating an item in the CollectionView. |
|
62
|
+
| itemTap | Triggered when the user taps on an item in the CollectionView. |
|
63
|
+
| loadMoreItems | Triggered when the generated items reached the end of the items property. |
|
64
|
+
| scroll | Triggered on collectionview scroll. |
|
65
|
+
| scrollEnd | Triggered on collectionview scroll end. |
|
66
|
+
| itemReorderStarting | Triggered when a reorder is starting. Changing the `returnValue` of the event data allows you to cancel it |
|
67
|
+
| itemReorderStarted | Triggered when a reorder started. |
|
68
|
+
| itemReordered | Triggered when a reorder finished. |
|
69
|
+
| dataPopulated | Triggered when a refresh has been called. |
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
### Properties
|
74
|
+
|
75
|
+
| Property | Type | Description |
|
76
|
+
| ------------- | ------------------------------------------------ | ------------------------------------------------------- |
|
77
|
+
| ios | [UICollectionView](https://tinyurl.com/y4ugbfgc) | Gets the native iOS view that represents the user interface for this component. Valid only when running on iOS. |
|
78
|
+
| android | [android.support.v7.widget.RecyclerView](https://tinyurl.com/lvqebpq) | Gets the native android widget that represents the user interface for this component. Valid only when running on Android OS. |
|
79
|
+
| items | `array` or `ItemsSource` | Gets or sets the items collection of the CollectionView. The items property can be set to an array or an object defining length and getItem(index) method. |
|
80
|
+
| itemTemplate | `string` | Gets or sets the item template of the CollectionView. |
|
81
|
+
| rowHeight | `PercentLength` | Gets or sets the height for every row in the CollectionView. |
|
82
|
+
| colWidth | `PercentLength` | Gets or sets the width for every column in the CollectionView. |
|
83
|
+
| spanSize | `function` | Triggered when an item is loaded. Returns the number of columns that the element should occupy taking into account `colWidth` when the device is vertical and `rowHeight` when horizontal. Parameters: (item, index: number). |
|
84
|
+
| scrollOffset | `number` | Gets the current scroll. |
|
85
|
+
| orientation | `vertical` or `horizontal` | Sets the orientation of the CollectionView. Defaults to `vertical`. |
|
86
|
+
|
87
|
+
### Methods
|
88
|
+
|
89
|
+
| Name | Return | Description |
|
90
|
+
| ------------------------------------------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------- |
|
91
|
+
| refresh() | `void` | Forces the CollectionView to reload all its items. |
|
92
|
+
| refreshVisibleItem() | `void` | Forces CollectionView to reload visible items. |
|
93
|
+
| scrollToIndex(index: number, animated: boolean = true) | `void` | Scrolls the CollectionView to the item with the given index. This can be either animated or not. Defaults to animated. |
|
94
|
+
| isItemAtIndexVisible(index: number) | `boolean` | Returns a boolean indicating whether the item is visible. |
|
95
|
+
|
96
|
+
|
97
|
+
[](#usage)
|
98
|
+
|
99
|
+
## Usage
|
100
|
+
You need to add `xmlns:gv="@nstudio/ui-collectionview"` to your page tag, and then simply use `<gv:CollectionView/>` in order to add the widget to your page. Use `<gv:Gridview.itemTemplate/>` to specify the template for each cell:
|
101
|
+
|
102
|
+
### Simple Example
|
103
|
+
|
104
|
+
Create a simple array of objects in your JS/TS file.
|
105
|
+
|
106
|
+
```typescript
|
107
|
+
const items = [
|
108
|
+
{ index: 0, name: 'TURQUOISE', color: '#1abc9c' },
|
109
|
+
{ index: 1, name: 'EMERALD', color: '#2ecc71' },
|
110
|
+
{ index: 2, name: 'PETER RIVER', color: '#3498db' },
|
111
|
+
{ index: 3, name: 'AMETHYST', color: '#9b59b6' },
|
112
|
+
{ index: 4, name: 'WET ASPHALT', color: '#34495e' },
|
113
|
+
{ index: 5, name: 'GREEN SEA', color: '#16a085' },
|
114
|
+
{ index: 6, name: 'NEPHRITIS', color: '#27ae60' },
|
115
|
+
{ index: 7, name: 'BELIZE HOLE', color: '#2980b9' },
|
116
|
+
{ index: 8, name: 'WISTERIA', color: '#8e44ad' },
|
117
|
+
{ index: 9, name: 'MIDNIGHT BLUE', color: '#2c3e50' }
|
118
|
+
];
|
119
|
+
```
|
120
|
+
|
121
|
+
```xml
|
122
|
+
<!-- test-page.xml -->
|
123
|
+
<Page xmlns="http://schemas.nativescript.org/tns.xsd" xmlns:gv="@nstudio/ui-collectionview" loaded="pageLoaded">
|
124
|
+
<GridLayout>
|
125
|
+
<gv:CollectionView items="items" colWidth="50%" rowHeight="100">
|
126
|
+
<gv:CollectionView.itemTemplate>
|
127
|
+
<Label text="value" verticalAlignment="center"/>
|
128
|
+
</gv:CollectionView.itemTemplate>
|
129
|
+
</gv:CollectionView>
|
130
|
+
</GridLayout>
|
131
|
+
</Page>
|
132
|
+
```
|
133
|
+
|
134
|
+
### Templates Example
|
135
|
+
You can also have multiple templates the same way you add them in the builtin `ListView` control:
|
136
|
+
```xml
|
137
|
+
<gv:CollectionView id="gv" row="0" class="cssClass" items="items"
|
138
|
+
colWidth="colWidth" rowHeight="rowHeight" itemTemplateSelector="templateSelector"
|
139
|
+
itemTap="gridViewItemTap" itemLoading="gridViewItemLoading" loadMoreItems="gridViewLoadMoreItems">
|
140
|
+
<gv:CollectionView.itemTemplates>
|
141
|
+
<template key="odd">
|
142
|
+
<GridLayout backgroundColor="#33ffff" style="margin: 10 10 0 0">
|
143
|
+
<Label text="value" verticalAlignment="center"/>
|
144
|
+
</GridLayout>
|
145
|
+
</template>
|
146
|
+
|
147
|
+
<template key="even">
|
148
|
+
<GridLayout backgroundColor="#33ffff" rows="auto, auto" style="margin: 10 10 0 0">
|
149
|
+
<Label row="0" text="value" verticalAlignment="center"/>
|
150
|
+
<Label row="1" text="value" verticalAlignment="center"/>
|
151
|
+
</GridLayout>
|
152
|
+
</template>
|
153
|
+
</gv:CollectionView.itemTemplates>
|
154
|
+
</gv:CollectionView>
|
155
|
+
```
|
156
|
+
```ts
|
157
|
+
export function templateSelector(item: any, index: number, items: any) {
|
158
|
+
return index % 2 === 0 ? "even" : "odd";
|
159
|
+
}
|
160
|
+
```
|
161
|
+
|
162
|
+
|
163
|
+
[](#usage-in-angular)
|
164
|
+
|
165
|
+
## Usage in Angular
|
166
|
+
|
167
|
+
Import the module into your project.
|
168
|
+
|
169
|
+
```typescript
|
170
|
+
import { CollectionViewModule } from '@nstudio/ui-collectionview/angular';
|
171
|
+
|
172
|
+
@NgModule({
|
173
|
+
imports: [
|
174
|
+
CollectionViewModule,
|
175
|
+
],
|
176
|
+
})
|
177
|
+
```
|
178
|
+
### Simple Example
|
179
|
+
|
180
|
+
Create a simple array of objects in your Typescript file.
|
181
|
+
|
182
|
+
```typescript
|
183
|
+
items = [
|
184
|
+
{ index: 0, name: 'TURQUOISE', color: '#1abc9c' },
|
185
|
+
{ index: 1, name: 'EMERALD', color: '#2ecc71' },
|
186
|
+
{ index: 2, name: 'PETER RIVER', color: '#3498db' },
|
187
|
+
{ index: 3, name: 'AMETHYST', color: '#9b59b6' },
|
188
|
+
{ index: 4, name: 'WET ASPHALT', color: '#34495e' },
|
189
|
+
{ index: 5, name: 'GREEN SEA', color: '#16a085' },
|
190
|
+
{ index: 6, name: 'NEPHRITIS', color: '#27ae60' },
|
191
|
+
{ index: 7, name: 'BELIZE HOLE', color: '#2980b9' },
|
192
|
+
{ index: 8, name: 'WISTERIA', color: '#8e44ad' },
|
193
|
+
{ index: 9, name: 'MIDNIGHT BLUE', color: '#2c3e50' }
|
194
|
+
];
|
195
|
+
```
|
196
|
+
|
197
|
+
Add the following to your component HTML.
|
198
|
+
```xml
|
199
|
+
<CollectionView [items]="items" colWidth="50%" rowHeight="100">
|
200
|
+
<ng-template let-item="item">
|
201
|
+
<Label [text]="item.name"></Label>
|
202
|
+
</ng-template>
|
203
|
+
</CollectionView>
|
204
|
+
```
|
205
|
+
|
206
|
+
### Templates Example
|
207
|
+
If you want to use multiple item templates, you can do that very similarly to how you do it for the builtin `ListView` control. The only difference is that due to current limitations instead of using the `nsTemplateKey` directive you need to use the `cvTemplateKey` directive that comes from the CollectionView. (In a future version, once the framework allows it this will be changed and you will be able to use the same directive for the `CollectionView` as well)
|
208
|
+
```html
|
209
|
+
<CollectionView row="1" [items]="items" colWidth="33%" rowHeight="100" [itemTemplateSelector]="templateSelector">
|
210
|
+
<ng-template cvTemplateKey="Defender" let-item="item" let-odd="odd">
|
211
|
+
<StackLayout [nsRouterLink]="['/item', item.id]" borderColor="blue" borderWidth="2" borderRadius="5" verticalAlignment="stretch" class="list-group-item" [class.odd]="odd">
|
212
|
+
<Label verticalAlignment="center" [text]="item.name" class="list-group-item-text" textWrap="true"></Label>
|
213
|
+
</StackLayout>
|
214
|
+
</ng-template>
|
215
|
+
|
216
|
+
<ng-template cvTemplateKey="Goalkeeper" let-item="item" let-odd="odd">
|
217
|
+
<StackLayout [nsRouterLink]="['/item', item.id]" borderColor="black" borderWidth="2" borderRadius="5" verticalAlignment="stretch" class="list-group-item" [class.odd]="odd">
|
218
|
+
<Label verticalAlignment="center" [text]="item.name" class="list-group-item-text" textWrap="true"></Label>
|
219
|
+
</StackLayout>
|
220
|
+
</ng-template>
|
221
|
+
|
222
|
+
<ng-template cvTemplateKey="Midfielder" let-item="item" let-odd="odd">
|
223
|
+
<StackLayout [nsRouterLink]="['/item', item.id]" borderColor="yellow" borderWidth="2" borderRadius="5" verticalAlignment="stretch" class="list-group-item" [class.odd]="odd">
|
224
|
+
<Label verticalAlignment="center" [text]="item.name" class="list-group-item-text" textWrap="true"></Label>
|
225
|
+
</StackLayout>
|
226
|
+
</ng-template>
|
227
|
+
|
228
|
+
<ng-template cvTemplateKey="Forward" let-item="item" let-odd="odd">
|
229
|
+
<StackLayout [nsRouterLink]="['/item', item.id]" borderColor="red" borderWidth="2" borderRadius="5" verticalAlignment="stretch" class="list-group-item" [class.odd]="odd">
|
230
|
+
<Label verticalAlignment="center" [text]="item.name" class="list-group-item-text" textWrap="true"></Label>
|
231
|
+
</StackLayout>
|
232
|
+
</ng-template>
|
233
|
+
</CollectionView>
|
234
|
+
```
|
235
|
+
|
236
|
+
For a more complete example, look in the `demo-ng` directory.
|
237
|
+
|
238
|
+
|
239
|
+
[](#usage-in-vue)
|
240
|
+
|
241
|
+
## Usage in Vue
|
242
|
+
|
243
|
+
Register the plugin in your `app.ts`.
|
244
|
+
|
245
|
+
```typescript
|
246
|
+
import CollectionView from '@nstudio/ui-collectionview/vue';
|
247
|
+
Vue.use(CollectionView);
|
248
|
+
```
|
249
|
+
|
250
|
+
### Simple Example
|
251
|
+
In your component, add the following to make a simple array of objects.
|
252
|
+
|
253
|
+
```typescript
|
254
|
+
export default {
|
255
|
+
// ...
|
256
|
+
data() {
|
257
|
+
const items = [
|
258
|
+
{ index: 0, name: 'TURQUOISE', color: '#1abc9c' },
|
259
|
+
{ index: 1, name: 'EMERALD', color: '#2ecc71' },
|
260
|
+
{ index: 2, name: 'PETER RIVER', color: '#3498db' },
|
261
|
+
{ index: 3, name: 'AMETHYST', color: '#9b59b6' },
|
262
|
+
{ index: 4, name: 'WET ASPHALT', color: '#34495e' },
|
263
|
+
{ index: 5, name: 'GREEN SEA', color: '#16a085' },
|
264
|
+
{ index: 6, name: 'NEPHRITIS', color: '#27ae60' },
|
265
|
+
{ index: 7, name: 'BELIZE HOLE', color: '#2980b9' },
|
266
|
+
{ index: 8, name: 'WISTERIA', color: '#8e44ad' },
|
267
|
+
{ index: 9, name: 'MIDNIGHT BLUE', color: '#2c3e50' }
|
268
|
+
];
|
269
|
+
return {
|
270
|
+
itemList: items
|
271
|
+
};
|
272
|
+
},
|
273
|
+
// ...
|
274
|
+
};
|
275
|
+
```
|
276
|
+
|
277
|
+
Then add the following XML to your component.
|
278
|
+
|
279
|
+
```xml
|
280
|
+
<CollectionView
|
281
|
+
:items="itemList"
|
282
|
+
colWidth="50%"
|
283
|
+
rowHeight="100"
|
284
|
+
>
|
285
|
+
<v-template>
|
286
|
+
<Label :text="item.name"></Label>
|
287
|
+
</v-template>
|
288
|
+
</CollectionView>
|
289
|
+
```
|
290
|
+
|
291
|
+
For a more complete example, look in the `demo-vue` directory.
|
292
|
+
|
293
|
+
|
294
|
+
[](#usage-in-svelte)
|
295
|
+
|
296
|
+
## Usage in Svelte
|
297
|
+
|
298
|
+
Register the plugin in your `app.ts`.
|
299
|
+
|
300
|
+
```typescript
|
301
|
+
import CollectionViewElement from '@nstudio/ui-collectionview/svelte';
|
302
|
+
CollectionViewElement.register();
|
303
|
+
```
|
304
|
+
|
305
|
+
### Simple Example
|
306
|
+
|
307
|
+
In you component, add the following to import Svelte `Templates` and to create a simple array of objects.
|
308
|
+
|
309
|
+
```typescript
|
310
|
+
import { Template } from 'svelte-native/components';
|
311
|
+
|
312
|
+
const items = [
|
313
|
+
{ index: 0, name: 'TURQUOISE', color: '#1abc9c' },
|
314
|
+
{ index: 1, name: 'EMERALD', color: '#2ecc71' },
|
315
|
+
{ index: 2, name: 'PETER RIVER', color: '#3498db' },
|
316
|
+
{ index: 3, name: 'AMETHYST', color: '#9b59b6' },
|
317
|
+
{ index: 4, name: 'WET ASPHALT', color: '#34495e' },
|
318
|
+
{ index: 5, name: 'GREEN SEA', color: '#16a085' },
|
319
|
+
{ index: 6, name: 'NEPHRITIS', color: '#27ae60' },
|
320
|
+
{ index: 7, name: 'BELIZE HOLE', color: '#2980b9' },
|
321
|
+
{ index: 8, name: 'WISTERIA', color: '#8e44ad' },
|
322
|
+
{ index: 9, name: 'MIDNIGHT BLUE', color: '#2c3e50' }
|
323
|
+
];
|
324
|
+
```
|
325
|
+
|
326
|
+
Then add the following XML to your component:
|
327
|
+
|
328
|
+
```xml
|
329
|
+
<collectionView
|
330
|
+
{items}
|
331
|
+
colWidth="50%"
|
332
|
+
rowHeight="100"
|
333
|
+
>
|
334
|
+
<Template let:item>
|
335
|
+
<label text="{item.name}" />
|
336
|
+
</Template>
|
337
|
+
</collectionView>
|
338
|
+
```
|
339
|
+
|
340
|
+
For a more complete example, look in the `demo-svelte` directory.
|
341
|
+
|
342
|
+
|
343
|
+
[](#usage-in-react)
|
344
|
+
|
345
|
+
## Usage in React
|
346
|
+
|
347
|
+
Register the plugin in your `app.ts`.
|
348
|
+
|
349
|
+
```typescript
|
350
|
+
import { registerCollectionView } from '@nstudio/ui-collectionview/react';
|
351
|
+
registerCollectionView();
|
352
|
+
```
|
353
|
+
|
354
|
+
### Simple Example
|
355
|
+
|
356
|
+
In your component, add the following code to create a simple list.
|
357
|
+
|
358
|
+
```tsx
|
359
|
+
import { CollectionView } from '@nstudio/ui-collectionview/react';
|
360
|
+
|
361
|
+
const items = [
|
362
|
+
{ index: 0, name: 'TURQUOISE', color: '#1abc9c' },
|
363
|
+
{ index: 1, name: 'EMERALD', color: '#2ecc71' },
|
364
|
+
{ index: 2, name: 'PETER RIVER', color: '#3498db' },
|
365
|
+
{ index: 3, name: 'AMETHYST', color: '#9b59b6' },
|
366
|
+
{ index: 4, name: 'WET ASPHALT', color: '#34495e' },
|
367
|
+
{ index: 5, name: 'GREEN SEA', color: '#16a085' },
|
368
|
+
{ index: 6, name: 'NEPHRITIS', color: '#27ae60' },
|
369
|
+
{ index: 7, name: 'BELIZE HOLE', color: '#2980b9' },
|
370
|
+
{ index: 8, name: 'WISTERIA', color: '#8e44ad' },
|
371
|
+
{ index: 9, name: 'MIDNIGHT BLUE', color: '#2c3e50' }
|
372
|
+
];
|
373
|
+
|
374
|
+
interface Item {
|
375
|
+
index: number;
|
376
|
+
name: string;
|
377
|
+
color: string;
|
378
|
+
}
|
379
|
+
|
380
|
+
const cellFactory = (item: Item) => (
|
381
|
+
<label text={item.name} />
|
382
|
+
);
|
383
|
+
|
384
|
+
export function First() {
|
385
|
+
return (
|
386
|
+
<CollectionView items={items} colWidth="50%" rowHeight="100" cellFactory={cellFactory} width="100%" height="100%" />
|
387
|
+
);
|
388
|
+
}
|
389
|
+
```
|
390
|
+
|
391
|
+
|
392
|
+
[](#questions)
|
393
|
+
|
394
|
+
## Questions
|
395
|
+
|
396
|
+
If you have any questions/issues/comments please feel free to create an issue or start a conversation in the [NativeScript Community Discord](https://nativescript.org/discord).
|
@@ -0,0 +1,82 @@
|
|
1
|
+
import { AfterContentInit, ComponentRef, DoCheck, ElementRef, EmbeddedViewRef, EventEmitter, IterableDiffers, NgZone, OnDestroy, TemplateRef, ViewContainerRef } from '@angular/core';
|
2
|
+
import { CollectionViewItemEventData } from '@nstudio/ui-collectionview';
|
3
|
+
import { DetachedLoader, NativeScriptRendererFactory } from '@nativescript/angular';
|
4
|
+
import { View } from '@nativescript/core';
|
5
|
+
import * as i0 from "@angular/core";
|
6
|
+
export declare class ItemContext {
|
7
|
+
$implicit?: any;
|
8
|
+
item?: any;
|
9
|
+
index?: number;
|
10
|
+
even?: boolean;
|
11
|
+
odd?: boolean;
|
12
|
+
constructor($implicit?: any, item?: any, index?: number, even?: boolean, odd?: boolean);
|
13
|
+
}
|
14
|
+
export interface SetupItemViewArgs {
|
15
|
+
view: EmbeddedViewRef<any>;
|
16
|
+
data: any;
|
17
|
+
index: number;
|
18
|
+
context: ItemContext;
|
19
|
+
}
|
20
|
+
export declare class CollectionViewComponent implements DoCheck, OnDestroy, AfterContentInit {
|
21
|
+
private _elementRef;
|
22
|
+
private _iterableDiffers;
|
23
|
+
private _renderer;
|
24
|
+
private _ngZone;
|
25
|
+
get nativeElement(): any;
|
26
|
+
get listView(): any;
|
27
|
+
loader: ViewContainerRef;
|
28
|
+
setupItemView: EventEmitter<SetupItemViewArgs>;
|
29
|
+
itemTemplateQuery: TemplateRef<ItemContext>;
|
30
|
+
autoReuseViews: boolean;
|
31
|
+
detachedLoaderFactory(): ComponentRef<DetachedLoader>;
|
32
|
+
get itemTemplate(): any;
|
33
|
+
set itemTemplate(value: any);
|
34
|
+
get items(): any;
|
35
|
+
set items(value: any);
|
36
|
+
private _collectionView;
|
37
|
+
private _items;
|
38
|
+
private _differ;
|
39
|
+
private _itemTemplate;
|
40
|
+
private _templateMap;
|
41
|
+
private _loaders;
|
42
|
+
constructor(_elementRef: ElementRef, _iterableDiffers: IterableDiffers, _renderer: NativeScriptRendererFactory, _ngZone: NgZone);
|
43
|
+
private itemViewLoader;
|
44
|
+
ngAfterContentInit(): void;
|
45
|
+
ngOnDestroy(): void;
|
46
|
+
ngDoCheck(): void;
|
47
|
+
registerTemplate(key: string, template: TemplateRef<ItemContext>): void;
|
48
|
+
onItemLoading(args: CollectionViewItemEventData): void;
|
49
|
+
onItemRecyclingInternal(args: any): void;
|
50
|
+
onItemDisposingInternal(args: any): void;
|
51
|
+
setupViewRef(view: EmbeddedViewRef<ItemContext>, data: any, index: number): void;
|
52
|
+
protected getItemTemplateViewFactory(template: TemplateRef<ItemContext>): () => View;
|
53
|
+
viewPool: Map<TemplateRef<ItemContext>, {
|
54
|
+
scrapSize: number;
|
55
|
+
scrapHead: Set<EmbeddedViewRef<ItemContext>>;
|
56
|
+
}>;
|
57
|
+
private storeViewRef;
|
58
|
+
viewToTemplate: WeakMap<EmbeddedViewRef<any>, TemplateRef<any>>;
|
59
|
+
viewToLoader: WeakMap<EmbeddedViewRef<any>, ComponentRef<DetachedLoader>>;
|
60
|
+
private getOrCreate;
|
61
|
+
private getView;
|
62
|
+
private getViewPool;
|
63
|
+
private setItemTemplates;
|
64
|
+
private detectChangesOnChild;
|
65
|
+
private refresh;
|
66
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<CollectionViewComponent, never>;
|
67
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<CollectionViewComponent, "CollectionView", never, { "autoReuseViews": "autoReuseViews"; "itemTemplate": "itemTemplate"; "items": "items"; }, { "setupItemView": "setupItemView"; }, ["itemTemplateQuery"], never, false, never>;
|
68
|
+
}
|
69
|
+
export interface ComponentView {
|
70
|
+
rootNodes: any[];
|
71
|
+
destroy(): void;
|
72
|
+
}
|
73
|
+
export declare type RootLocator = (nodes: any[], nestLevel: number) => View;
|
74
|
+
export declare function getItemViewRoot(viewRef: ComponentView, rootLocator?: RootLocator): View;
|
75
|
+
export declare class TemplateKeyDirective {
|
76
|
+
private templateRef;
|
77
|
+
private collectionView;
|
78
|
+
constructor(templateRef: TemplateRef<any>, collectionView: CollectionViewComponent);
|
79
|
+
set cvTemplateKey(value: any);
|
80
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<TemplateKeyDirective, [null, { host: true; }]>;
|
81
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<TemplateKeyDirective, "[cvTemplateKey]", never, { "cvTemplateKey": "cvTemplateKey"; }, {}, never, never, false, never>;
|
82
|
+
}
|