Coder Social home page Coder Social logo

catalin-miron-hs / react-native-swipe-flip Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aprct/react-native-swipe-flip

0.0 2.0 0.0 8 KB

A React Native view component that flips front-to-back in response to swipe gestures.

License: Other

JavaScript 100.00%

react-native-swipe-flip's Introduction

react-native-swipe-flip

A React Native view component that flips front-to-back in response to swipe gestures.

Installation

npm install react-native-swipe-flip

Demo

swipeflipdemo

Interaction

The view will respond to the following swipe directions:

  • 'up'
  • 'down'
  • 'left'
  • 'right'

Programmatically flip the card by accessing the component via ref:

<SwipeFlip ref={(c) => { this.swipeFlip = c; }}
           style={{ flex: 1 }}
           front={ this._renderFront() }
           back={ this._renderBack() }
           onFlipped={(val) => { console.log('Flipped: ' + val); }}
           flipEasing={ Easing.out(Easing.ease) }
           flipDuration={ 500 }
           perspective={ 1000 } />

Now you can call the flip(swipeDirection) method and pass a swipe direction as the parameter: this.swipeFlip.flip('left');

Example

'use strict';

import React from 'react';
import { View, Text, Easing } from 'react-native';

import SwipeFlip from 'react-native-swipe-flip';

export default class Playground extends React.Component {

    constructor(props) {
        super(props);
    }
    
    render() {
        return (
            <View style={{ flex: 1, backgroundColor: '#A5D6A7' }}>
                <SwipeFlip style={{ flex: 1 }}
                           front={ this._renderFront() }
                           back={ this._renderBack() }
                           onFlipped={(val) => { console.log('Flipped: ' + val); }}
                           flipEasing={ Easing.out(Easing.ease) }
                           flipDuration={ 500 }
                           perspective={ 1000 } />
            </View>
        )
    }

    _renderFront() {
        return (
            <View style={{ flex: 1, backgroundColor: '#3F51B5', justifyContent: 'center', alignItems: 'center' }}>
                <View style={{ backgroundColor: 'black', padding: 20 }}>
                    <Text style={{ fontSize: 32, color: 'white', textAlign: 'center' }}>
                        { `FRONT\nSwipe to flip!` }
                    </Text>
                </View>
            </View>
        );
    }

    _renderBack() {
        return (
            <View style={{ flex: 1, backgroundColor: '#C2185B', justifyContent: 'center', alignItems: 'center' }}>
                <View style={{ backgroundColor: 'black', padding: 20 }}>
                    <Text style={{ fontSize: 32, color: 'white', textAlign: 'center' }}>
                        { `BACK\nSwipe to flip!` }
                    </Text>
                </View>
            </View>
        );
    }
}

.babelrc:

{
  "retainLines": true,
  "whitelist": [
    "es6.arrowFunctions",
    "es6.blockScoping",
    "es6.classes",
    "es6.constants",
    "es6.destructuring",
    "es6.modules",
    "es6.parameters",
    "es6.properties.computed",
    "es6.properties.shorthand",
    "es6.spread",
    "es6.templateLiterals",
    "es7.asyncFunctions",
    "es7.trailingFunctionCommas",
    "es7.objectRestSpread",
    "es7.classProperties",
    "es7.decorators",
    "flow",
    "react",
    "react.displayName",
    "regenerator"
  ]
}

Thanks

Big thanks to @kevinstumpf for React Native Flip View and @christopherabouabdo for React Native Simple Gesture.

react-native-swipe-flip's People

Contributors

aprct avatar

Watchers

 avatar  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.