Giter Site home page Giter Site logo

jnoack331 / nativescript-pager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from triniwiz/nativescript-pager

0.0 0.0 0.0 18.92 MB

License: Apache License 2.0

Shell 0.54% JavaScript 9.36% Ruby 0.04% TypeScript 84.08% CSS 0.82% HTML 3.32% Vue 1.71% SCSS 0.13%

nativescript-pager's Introduction

npm npm Build Status

NativeScript Pager

Install

  • tns plugin add @triniwiz/nativescript-pager

NativeScript 6x

  • tns plugin add nativescript-pager

NativeScript 5x

NativeScript 4x

NativeScript 3x

NativeScript 2x

Usage

Note v11+

Pager for NativeScript supports the core ObservableArray module part of the core NativeScript modules collection. Using an ObservableArray instance as a source for Pager will ensure that changes in the source collection will be automatically taken care of by the control.

IMPORTANT: Make sure you include xmlns:pager="nativescript-pager" on the Page element any element can be used in the pager

<pager:Pager items="{{items}}" row="2" id="pager" spacing="2%" peaking="10%" transformers="scale" pagesCount="10" showIndicator="true" backgroundColor="lightsteelblue">
            <pager:Pager.itemTemplate>
                <GridLayout rows="auto, *" columns="*" backgroundColor="red">
                    <Label text="{{title}}"/>
                    <Image row="1" src="{{image}}"/>
                </GridLayout>
            </pager:Pager.itemTemplate>
</pager:Pager>

Multi Template

<c:Pager selectedIndexChange="selectedIndexChange" itemTemplateSelector="$index % 2 === 0 ? 'even' : 'odd'" selectedIndex="5" items="{{items}}" row="4" id="pager" pagesCount="10" showIndicator="true" backgroundColor="lightsteelblue">
      <Pager.itemTemplates>
        <template key="even">
          <GridLayout rows="auto,auto,*" columns="*">
            <Label text="Even"/>
            <Label row="1" text="{{title}}"/>
            <Image loaded="loadedImage" row="2" src="{{image}}"/>
          </GridLayout>
        </template>
        <template key="odd">
          <GridLayout rows="auto,auto ,auto,*" columns="*" backgroundColor="white">
            <Label text="Odd"/>
            <Label row="1" text="{{title}}"/>
            <StackLayout row="2">
              <Label text="{{image}}"/>
            </StackLayout>
            <Image loaded="loadedImage" row="3" src="{{image}}"/>
          </GridLayout>
        </template>
      </Pager.itemTemplates>
      <!-- <Pager.itemTemplate><GridLayout rows="auto,*" columns="*"><Label row="1" text="{{title}}"/><Image loaded="loadedImage" row="2" src="{{image}}"/></GridLayout></Pager.itemTemplate> -->
    </c:Pager>

Static Views

<c:Pager selectedIndexChange="selectedIndexChange" row="4" id="pager"
                 showIndicator="true" backgroundColor="lightsteelblue">
            <c:PagerItem backgroundColor="red">
                <Label text="First"></Label>
            </c:PagerItem>
            <c:PagerItem backgroundColor="white">
                <Label text="Second" ></Label>
            </c:PagerItem>
            <c:PagerItem backgroundColor="black">
                <Label text="Third" color="white"></Label>
            </c:PagerItem>
            <c:PagerItem backgroundColor="green">
                <Label text="Fourth"></Label>
            </c:PagerItem>
        </c:Pager>

Vue

import Vue from 'nativescript-vue';
import Pager from 'nativescript-pager/vue';

Vue.use(Pager);
<template>
    <Pager for="item in items">
        <v-template>
            <GridLayout class="pager-item" rows="auto, *" columns="*">
                <Label :text="item.title" />
                <Image  stretch="fill" row="1" :src="item.image" />
            </GridLayout>
        </v-template>
        <v-template if="$odd">
            <GridLayout class="pager-item" rows="auto, *" columns="*">
                <Image  stretch="fill" :src="item.image" />
                <Label :text="item.title" row="1"/>
            </GridLayout>
        </v-template>
    </Pager>
</template>

Static Views

<Pager height="100%" :selectedIndex="1">
  <PagerItem backgroundColor="red"> <label text="First"></label> </PagerItem>
  <PagerItem backgroundColor="white"> <label text="Second"></label> </PagerItem>
  <PagerItem backgroundColor="black">
    <label text="Third" color="white"></label>
  </PagerItem>
  <PagerItem backgroundColor="green"> <label text="Fourth"></label> </PagerItem>
</Pager>

Angular

import { PagerModule } from "nativescript-pager/angular";

@NgModule({
    imports: [
    PagerModule
    ],
    declarations: [
        AppComponent
    ],
    bootstrap: [AppComponent]
})

Angular v2

<Pager
  [items]="items"
  #pager
  [selectedIndex]="currentPagerIndex"
  (selectedIndexChange)="onIndexChanged($event)"
  class="pager"
>
  <template let-i="index" let-item="item">
    <GridLayout
      class="pager-item"
      rows="auto, *"
      columns="*"
      backgroundColor="red"
    >
      <label [text]="item.title"></label>
      <image row="1" [src]="item.image"></image>
    </GridLayout>
  </template>
</Pager>

Angular v4+

<Pager
  [items]="items"
  #pager
  [selectedIndex]="currentPagerIndex"
  (selectedIndexChange)="onIndexChanged($event)"
  class="pager"
>
  <ng-template let-i="index" let-item="item">
    <GridLayout
      class="pager-item"
      rows="auto, *"
      columns="*"
      backgroundColor="red"
    >
      <label [text]="item.title"></label>
      <image row="1" [src]="item.image"></image>
    </GridLayout>
  </ng-template>
</Pager>

Multi Template

 public templateSelector = (item: any, index: number, items: any) => {
    return index % 2 === 0 ? 'even' : 'odd';
  }
<Pager
  row="1"
  [items]="items | async"
  [itemTemplateSelector]="templateSelector"
  #pager
  [selectedIndex]="currentPagerIndex"
  (selectedIndexChange)="onIndexChanged($event)"
  class="pager"
  backgroundColor="lightsteelblue"
>
  <ng-template pagerTemplateKey="even" let-i="index" let-item="item">
    <GridLayout class="pager-item" rows="auto,auto,*" columns="*">
      <label text="Even"></label> <label row="1" [text]="item.title"></label>
      <image loaded="loadedImage" row="2" [src]="item.image"></image>
    </GridLayout>
  </ng-template>

  <ng-template pagerTemplateKey="odd" let-i="index" let-item="item">
    <GridLayout
      class="pager-item"
      rows="auto,auto,auto,*"
      columns="*"
      backgroundColor="white"
    >
      <label text="Odd"></label> <label row="1" [text]="item.title"></label>
      <StackLayout row="2"> <label [text]="item.image"></label> </StackLayout>
      <image loaded="loadedImage" row="3" [src]="item.image"></image>
    </GridLayout>
  </ng-template>
</Pager>

Static Views

<Pager
  backgroundColor="orange"
  row="1"
  #pager
  [selectedIndex]="1"
  height="100%"
>
  <StackLayout *pagerItem backgroundColor="red">
    <label text="First"></label>
  </StackLayout>
  <StackLayout *pagerItem backgroundColor="white">
    <label text="Second"></label>
  </StackLayout>
  <StackLayout *pagerItem backgroundColor="black">
    <label text="Third" color="white"></label>
  </StackLayout>
  <StackLayout *pagerItem backgroundColor="green">
    <label text="Fourth"></label>
  </StackLayout>
</Pager>

React

import {$Pager} from 'nativescript-pager/react';
return (
<$Pager
                height={{ unit: "%", value: 100 }}
                   selectedIndex={this.selectedIndex}
                   selectedIndexChange={this.selectedIndexChange.bind(this)}
                    items={this.items}
                     cellFactory={
                    (item, ref) => {
                        return (
                            <$StackLayout id={item.title} ref={ref}>
                                <$Label text={item.title}/>
                                <$ImageCacheIt stretch={'aspectFill'}
                                        src={item.image}/>
                            </$StackLayout>
                        );
                    }
                }/>
)

Static Views

return(<$Pager row={0} col={0} selectedIndex={this.selectedIndex} height={{unit: '%', value: 100}}>
                           <$PagerItem backgroundColor={'red'}>
                               <$Label text={'First'}/>
                           </$PagerItem>
                           <$PagerItem backgroundColor={'white'}>
                               <$Label text={'Second'}/>
                           </$PagerItem>
                           <$PagerItem backgroundColor={'black'}>
                               <$Label text={'Third'} color={new Color('white')}/>
                           </$PagerItem>
                           <$PagerItem backgroundColor={'green'}>
                               <$Label text={'Fourth'}/>
                           </$PagerItem>
                           <$PagerItem backgroundColor={'pink'}>
                               <$Label text={'Fifth'}/>
                           </$PagerItem>
                       </$Pager>)

Config

<Pager cache="false" disableSwipe="true" disableAnimation="true" selectedIndex="5">
IOS Android
ios android

nativescript-pager's People

Contributors

bradmartin avatar danielgek avatar ddfreiling avatar eddyverbruggen avatar edusperoni avatar farfromrefug avatar franciz avatar hamdiwanis avatar heer0 avatar mailiam avatar mapo80 avatar mikkou avatar mrmonat avatar nathanwalker avatar rigor789 avatar shiv19 avatar sis0k0 avatar triniwiz avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.