diff --git a/README.md b/README.md index bc1b2991..0efc5e21 100755 --- a/README.md +++ b/README.md @@ -1,9 +1,7 @@ -This monorepo contains multiple packages: +This monorepo contains multiple packages:

+collectionview -
- collectionview - - + + + +

@nativescript-community/ui-collectionview

+

+ Downloads per month +NPM Version +

+ +

+ Allows you to easily add a collection view (grid list view) to your projects. Supports vertical and horizontal modes, templating, and more.
+ +

+ +
+ + +| | | +| --- | ----------- | +| iOS Demo | Android Demo | + + +[](#table-of-contents) + ## Table of Contents -1. [Installation](#installation) -2. [Configuration](#configuration) -3. [API](#api) -4. [Usage](#usage) -5. [Usage in Angular](#usage-in-angular) -6. [Usage in Vue](#usage-in-vue) -7. [Usage in Svelte](#usage-in-svelte) -8. [Usage in React](#usage-in-react) -9. [Demos](#demos) - +* [Installation](#installation) +* [API](#api) + * [Events](#events) + * [Properties](#properties) + * [Methods](#methods) +* [Usage](#usage) + * [Simple Example:](#simple-example) + * [Templates Example:](#templates-example) +* [Usage in Angular](#usage-in-angular) + * [Simple Example:](#simple-example-1) + * [Templates Example:](#templates-example-1) +* [Usage in Vue](#usage-in-vue) + * [Simple Example:](#simple-example-2) +* [Usage in Svelte](#usage-in-svelte) + * [Simple Example:](#simple-example-3) +* [Usage in React](#usage-in-react) + * [Simple Example:](#simple-example-4) +* [Demos](#demos) +* [Demos and Development](#demos-and-development) + * [Setup](#setup) + * [Build](#build) + * [Demos](#demos-1) +* [Questions](#questions) + + +[](#installation) + ## Installation - Run the following command from the root of your project: `ns plugin add @nativescript-community/ui-collectionview` -This command automatically installs the necessary files, as well as stores @nativescript-community/ui-collectionview as a dependency in your project's package.json file. - -## Configuration - -There is no additional configuration needed! - + +[](#api) + ## API ### Events -| Property | Description | -| ------------------- | ---------------------------------------------------------------------------------------------------------- | -| itemLoading | Triggered when generating an item in the CollectionView. | -| itemTap | Triggered when the user taps on an item in the CollectionView. | -| loadMoreItems | Triggered when the generated items reached the end of the items property. | -| scroll | Triggered on collectionview scroll. | -| scrollEnd | Triggered on collectionview scroll end. | -| itemReorderStarting | Triggered when a reorder is starting. Changing the `returnValue` of the event data allows you to cancel it | -| itemReorderStarted | Triggered when a reorder started. | -| itemReordered | Triggered when a reorder finished. | -| dataPopulated | Triggered when a refresh has been called. | +| Property | Description | +| ------------------- | ---------------------------------------------------------------------------- | +| itemLoading | Triggered when generating an item in the CollectionView. | +| itemTap | Triggered when the user taps on an item in the CollectionView. | +| loadMoreItems | Triggered when the generated items reached the end of the items property. | +| scroll | Triggered on collectionview scroll. | +| scrollEnd | Triggered on collectionview scroll end. | +| itemReorderStarting | Triggered when a reorder is starting. Changing the `returnValue` of the event data allows you to cancel it | +| itemReorderStarted | Triggered when a reorder started. | +| itemReordered | Triggered when a reorder finished. | +| dataPopulated | Triggered when a refresh has been called. | + + ### Properties -| Property | Type | Description | -| ------------------------- | --------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------ | -| 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. | -| 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. | -| 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. | -| itemTemplate | `string` | Gets or sets the item template of the CollectionView. | -| rowHeight | `PercentLength` | Gets or sets the height for every row in the CollectionView. | -| colWidth | `PercentLength` | Gets or sets the width for every column in the CollectionView. | -| spanSize | `Function` | Function to return the span of a cell. For example with `colWidth:50%` a cell with a spanSize of 2 will be `100%` in width | -| orientation | `'horizontal' | 'vertical'` | Set the orientation for the collectionView | -| isBounceEnabled | `boolean` | (iOS) enable/disable CollectionView bounce | -| isScrollEnabled | `boolean` | enable/disable CollectionView scroll | -| reverseLayout | `boolean` | enable/disable CollectionView reversed layout (for message like views) | -| loadMoreThreshold | `number` | set the loadMore threshold (called on the `item.length - loadMoreThreshold` item appearing) | -| reorderEnabled | `boolean` | enable/disable CollectionView reorder feature | -| reorderLongPressEnabled | `boolean` | enable/disable CollectionView longpress to reorder | -| scrollBarIndicatorVisible | `boolean` | enable/disable CollectionView scrollBars | -| nestedScrollingEnabled | `boolean` | (Android) enable/disable CollectionView nested scrolling | +| Property | Type | Description | +| ------------- | ------------------------------------------------ | ------------------------------------------------------- | +| 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. | +| 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. | +| 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. | +| itemTemplate | `string` | Gets or sets the item template of the CollectionView. | +| rowHeight | `PercentLength` | Gets or sets the height for every row in the CollectionView. | +| colWidth | `PercentLength` | Gets or sets the width for every column in the CollectionView. | +| 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). | +| scrollOffset | `number` | Gets the current scroll. | ### Methods | Name | Return | Description | | ------------------------------------------------------ | ------ | ---------------------------------------------------------------------------------------------------------------------- | | refresh() | `void` | Forces the CollectionView to reload all its items. | +| refreshVisibleItem() | `void` | Forces CollectionView to reload visible items. | | 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. | +| isItemAtIndexVisible(index: number) | `boolean` | Returns a boolean indicating whether the item is visible. | + +[](#usage) + ## Usage - You need to add `xmlns:gv="@nativescript-community/ui-collectionview"` to your page tag, and then simply use `` in order to add the widget to your page. Use `` to specify the template for each cell: ### Simple Example: @@ -107,9 +145,9 @@ const items = [ - + - @@ -117,36 +155,36 @@ const items = [ ``` ### Templates Example: - You can also have multiple templates the same way you add them in the builtin `ListView` control: - ```xml - ``` - ```ts export function templateSelector(item: any, index: number, items: any) { - return index % 2 === 0 ? 'even' : 'odd'; + return index % 2 === 0 ? "even" : "odd"; } ``` + +[](#usage-in-angular) + ## Usage in Angular Import the module into your project. @@ -160,7 +198,6 @@ import { CollectionViewModule } from '@nativescript-community/ui-collectionview/ ], }) ``` - ### Simple Example: Create a simple array of objects in your Typescript file. @@ -181,7 +218,6 @@ items = [ ``` Add the following to your component HTML. - ```xml @@ -191,32 +227,30 @@ Add the following to your component HTML. ``` ### Templates Example: - 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) - ```html - + - + - + - + @@ -224,6 +258,9 @@ If you want to use multiple item templates, you can do that very similarly to ho For a more complete example, look in the `demo-ng` directory. + +[](#usage-in-vue) + ## Usage in Vue Register the plugin in your `app.ts`. @@ -234,7 +271,6 @@ Vue.use(CollectionView); ``` ### Simple Example: - In your component, add the following to make a simple array of objects. ```typescript @@ -256,7 +292,7 @@ export default { return { itemList: items }; - } + }, // ... }; ``` @@ -277,6 +313,9 @@ Then add the following XML to your component. For a more complete example, look in the `demo-vue` directory. + +[](#usage-in-svelte) + ## Usage in Svelte Register the plugin in your `app.ts`. @@ -310,8 +349,8 @@ const items = [ Then add the following XML to your component: ```xml - @@ -323,6 +362,9 @@ Then add the following XML to your component: For a more complete example, look in the `demo-svelte` directory. + +[](#usage-in-react) + ## Usage in React Register the plugin in your `app.ts`. @@ -358,19 +400,24 @@ interface Item { color: string; } -const cellFactory = (item: Item) =>