All Projects → rkhayyat → nativescript-swipe-card

rkhayyat / nativescript-swipe-card

Licence: other
Swipe Card plugin for nativescript

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to nativescript-swipe-card

code-samples
Find code samples and building blocks for your NativeScript app in the Marketplace
Stars: ✭ 35 (+66.67%)
Mutual labels:  nativescript
nativescript-appversion
🔢 NativeScript plugin to retrieve your app's package ID and current version
Stars: ✭ 47 (+123.81%)
Mutual labels:  nativescript
nativescript-fabric
Handling App URLs in nativescript apps
Stars: ✭ 29 (+38.1%)
Mutual labels:  nativescript
firebase
Modular Firebase 🔥 implementation for NativeScript. Supports both iOS & Android platforms for all Firebase services.
Stars: ✭ 36 (+71.43%)
Mutual labels:  nativescript
marketplace-feedback
This repository is for feedback regarding NativeScript Marketplace. Use the issues system here to submit feature requests, vote for existing ones or report bugs.
Stars: ✭ 16 (-23.81%)
Mutual labels:  nativescript
nativescript-snackbar
NativeScript plugin for Material Design Snackbar
Stars: ✭ 22 (+4.76%)
Mutual labels:  nativescript
nativescript-getters
A NativeScript plugin that adds six new getters – in addition to the native "getViewById" method – to retrieve one or more views by tag, type, class, style, value pair or property.
Stars: ✭ 12 (-42.86%)
Mutual labels:  nativescript
ui
Add right-to-left support to the NativeScript framework
Stars: ✭ 22 (+4.76%)
Mutual labels:  nativescript
nativescript-whatsapp-template
NativeScript Template Similar to WhatsApp
Stars: ✭ 61 (+190.48%)
Mutual labels:  nativescript
nativescript-auth0
Nativescript Auth0 https://auth0.com/ social authentication plugin
Stars: ✭ 57 (+171.43%)
Mutual labels:  nativescript
nativescript-textinputlayout
Android Material Design TextInputLayout for NativeScript
Stars: ✭ 35 (+66.67%)
Mutual labels:  nativescript
nativescript-vue-typescript-seed
Get started using NativeScript and Vue with TypeScript quick and easy
Stars: ✭ 22 (+4.76%)
Mutual labels:  nativescript
insomnia
😪 NativeScript plugin to keep the device awake (not dim the screen, lock, etc)
Stars: ✭ 40 (+90.48%)
Mutual labels:  nativescript
nativescript-healthcare-app
Healthcare example application built with NativeScript Angular. NativeScript template to quickly prototype your own business idea.
Stars: ✭ 24 (+14.29%)
Mutual labels:  nativescript
nativesapp
Simple WhatsApp clone just for training purposes - Course Angular Native at www.udemy.com/angular-native
Stars: ✭ 19 (-9.52%)
Mutual labels:  nativescript
nativescript-star-printer
🌟 Print directly to Star Micronics printers from your NativeScript app! http://www.starmicronics.com/
Stars: ✭ 28 (+33.33%)
Mutual labels:  nativescript
nativescript-yoonit-websocket
Build modern apps using NativeScript and WebSocket in Android and iOS
Stars: ✭ 62 (+195.24%)
Mutual labels:  nativescript
lazyNinjas
No description or website provided.
Stars: ✭ 25 (+19.05%)
Mutual labels:  nativescript
nativescript-react
Build native application using React and Nativescript.
Stars: ✭ 14 (-33.33%)
Mutual labels:  nativescript
nativescript-app-shortcuts
👇 Home Icon Actions for your NativeScript app, now also for Android!
Stars: ✭ 45 (+114.29%)
Mutual labels:  nativescript

npm npm twitter: @rakhayyat

NPM

Nativescript Swipe Card plugin

This plugin is inspired by https://www.nativescript.org/blog/tinder-style-cards-with-nativescript---love-at-first-swipe

Nativescript-swipe-card

Tender cards, allow you to drag them, and detect swipe events.

Developed with ❤️ by the team NativeBaguette 🥖

To know more about the {N} ambassador's program, you can check this video, or read this article.

Installation

tns plugin add nativescript-swipe-card

Usage

Typescript NativeScript

XML

<Page xmlns="http://schemas.nativescript.org/tns.xsd" 
      xmlns:customControls="nativescript-swipe-card"
      loaded="pageLoaded" class="page">
    <StackLayout>
        <customControls:SwipeCard id="swipe" 
                                  height="90%"
                                  width="80%" 
                                  items="{{ stackCards }}" 
                                  cardHeight="60" 
                                  cardWidth="70"
                                  isRandomColor="1"
                                  cardBorderRadius="20"
                                  cardBorderWidth="2"
                                  />
  </StackLayout>
</Page>

main-page

import * as observable from 'tns-core-modules/data/observable';
import * as pages from 'tns-core-modules/ui/page';
import {HelloWorldModel} from './main-view-model';
import {SwipeEvent} from 'nativescript-swipe-card';

// Event handler for Page 'loaded' event attached in main-page.xml
export function pageLoaded(args: observable.EventData) {
    // Get the event sender
    let page = <pages.Page>args.object;
    page.bindingContext = new HelloWorldModel();
    let swipeCard = page.getViewById("swipe");
    swipeCard.on("swipeEvent", (args:SwipeEvent) => {
        if (args.direction === 1) {
                    //right
                    console.log('Swiped to right');
        } else {
                    //left
                    console.log('Swiped to left');
        }
    });
}

main-view-model

import {Observable} from 'tns-core-modules/data/observable';
import {Layout} from "tns-core-modules/ui/layouts/layout";
import {StackLayout} from "tns-core-modules/ui/layouts/stack-layout";
import {GridLayout, ItemSpec} from "tns-core-modules/ui/layouts/grid-layout";
import {Label} from "tns-core-modules/ui/label";
import {Image} from "tns-core-modules/ui/image";
import {Button} from "tns-core-modules/ui/button";

export class HelloWorldModel extends Observable {
  public stackCards:Layout[];

  constructor() {
    super();

    let Grid = new GridLayout();
    let Label1 = new Label();
    let Label2 = new Label();
    Label1.text = "The Swipable Card plugin";
    Label1.textWrap=true;
    Label2.text = "Welcome to {N} we present you";
    Label2.textWrap=true;
    Grid.addChild(Label1);
    Grid.addChild(Label2);
    // Star and Auto modes for rows behave like corresponding setting for columns but refer to row height.
    var firstRow = new ItemSpec(1, "auto");
    var secondRow = new ItemSpec(1, "auto");
    Grid.addRow(firstRow);
    Grid.addRow(secondRow);
    GridLayout.setRow(Label1,0);
    GridLayout.setRow(Label2,1);


    let stack2 = new StackLayout();
    let image = new Image();
    image.src="~/images/apple.jpg"
    image.height=100;
    image.width=100;
    stack2.verticalAlignment = "middle";
    stack2.addChild(image);
    

    let stack3 = new StackLayout();
    let button = new Button();
    button.text="Click me!";
    button.width=100;
    button.textAlignment = "center";
    stack3.verticalAlignment = "middle";
    stack3.addChild(button);
    this.stackCards = [stack3,stack2,Grid];
  }
  
}

Fun fact! Team Time-Travel (Luna Kang, Stefan Medjo and mentor Jen Looper used the plugin to complete their 'Fetching' app - a Tinder app for dogs that uses the Petfinder API to help dogs to find puppy playdates in their area! https://github.com/jlooper/fetching-app-vanilla

Angular NativeScript

XML

        <SwipeCard  height="75%"
                    width="100%" 
                    [items]="stackCards"
                    (swipeEvent)="swipeEvent($event)"
                    cardHeight="50" 
                    cardWidth="80"
                    isRandomColor="1"
                    cardBorderRadius="15"
                    cardBorderWidth="1">
        </SwipeCard> 

Component

elementRegistryModule.registerElement("SwipeCard", () => require("nativescript-swipe-card").SwipeCard);
import {SwipeEvent} from 'nativescript-swipe-card';
import {Layout} from "tns-core-modules/ui/layouts/layout";
import {StackLayout} from "tns-core-modules/ui/layouts/stack-layout";
import {GridLayout, ItemSpec} from "tns-core-modules/ui/layouts/grid-layout";
import {Label} from "tns-core-modules/ui/label";
import {Image} from "tns-core-modules/ui/image";
import {Button} from "tns-core-modules/ui/button";
import * as elementRegistryModule from 'nativescript-angular/element-registry';

@Component({
    moduleId: module.id,
    templateUrl: "helloworld.html"
})
export class helloworldComponent {

  public stackCards:Array<Layout>=[];
  
  constructor(swipeEvent: SwipeEvent) {
    let Grid = new GridLayout();
    let Label1 = new Label();
    let Label2 = new Label();
    Label1.text = "The Swipable Card plugin";
    Label1.textWrap=true;
    Label2.text = "Welcome to {N} we present you";
    Label2.textWrap=true;
    Grid.addChild(Label1);
    Grid.addChild(Label2);
    // Star and Auto modes for rows behave like corresponding setting for columns but refer to row height.
    var firstRow = new ItemSpec(1, "auto");
    var secondRow = new ItemSpec(1, "auto");
    Grid.addRow(firstRow);
    Grid.addRow(secondRow);
    GridLayout.setRow(Label1,0);
    GridLayout.setRow(Label2,1);

    let stack2 = new StackLayout();
    let image = new Image();
    image.src="~/images/apple.jpg"
    image.height=100;
    image.width=100;
    stack2.verticalAlignment = "middle";
    stack2.addChild(image);

    let stack3 = new StackLayout();
    let button = new Button();
    button.text="Click me!";
    button.width=100;
    button.textAlignment = "center";
    stack3.verticalAlignment = "middle";
    stack3.addChild(button);
    this.stackCards = [stack3,stack2,Grid];
  }
  swipeEvent(args:SwipeEvent) {
        if (args.direction === 1) {
                    //right
                    console.log('Swiped to right');
        } else {
                    //left
                    console.log('Swiped to left');
        }
  };   
}

PS: I used this plugin in other application built in Angular, you can check it here: https://github.com/rkhayyat/SyrianForumFrance

API

Properties

Property Type Default Description
swipeEvent function SwipeEvent Callback called when the layout is swiped to the right or left and the swipe animation is done. Return args:SwipeEvent:
1- direction (1 if right/2 if left),
2- cardIndex contain the card index

Methods

Method Return Description
items Array<Layout> Array of card's layout, in which we can define the content of each card.
cardHeight (optional) number Card's height in percentage of their container's height.
cardWidth (optional) number Card's width in percentage of their container's width.
cardBorderRadius (optional) number Card's border radius.
cardBorderWidth (optional) number Card's border's width.
isRandomColor (optional) number 1: Set card's colors randomly & automatically.
2: Set card's colors manually.
Default is 1.

NativeBaguette 🥖

Jean-Baptiste Aniel Rachid Al Kayat triniwiz BradMartin JenLooper
rhanb rkhayyat triniwiz bradmartin jlooper
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].