Coder Social home page Coder Social logo

react-native-gestures's Introduction

React Native Gestures

⚠️ This package is still in early stage, it will have a heaps of API changes before it move to 1.0 ⚠️

React Native Composable Gesture Library

Build Status npm version npm version Issue Stats Issue Stats js-standard-style

Showcase

Getting Start

Assuming you are using react-native, because I don't know how it will work in other libraries...

  • Install via npm
npm i -S react-native-gestures

Then write some js like the simple code samples as a React component and render it in your react-native app.

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

import {
  drag,
  pinch,
  GestureView
} from 'react-native-gestures';

export default React.createClass({
  render() {
    onGestureError(err) {
      console.error(err);
    },
    return (
      <View>
        <GestureView
          style={movable}
          gestures={[drag, pinch]}
          toStyle={(layout) => {
            return {
              top: layout.y,
              left: layout.x,
              width: layout.width,
              height: layout.height,
              transform: [{rotate: `${layout.rotate}deg`}]
            }
          }}
          onError={console.error.bind(console)}>
          <Text>HEHE</Text>
          <Text>HEHE</Text>
        </GestureView>
      </View>
    );
  }
});

APIs

As you can see, it's just a very simple React component you can use in this package, maybe it will have more components in the future, or not.

There are few properties it accpets:

  • gestures - a Array of gestures
  • onError - a Function will be called when anything bad happens
  • style - a style same as <View>'s style property
  • toStyle - a mapping function that allow you to pick the changes you want to css style
  • children - ... you know, just React children, nothing special

Example:

let style = { position: 'absolute', backgroundColor: '#F00' };

<GestureView
  style={style}
  onError={console.error.bind(console)}
  gestures={[...]}>
  <Text>This is the children I say</Text>
</GestureView>

Gestures

Every gesture in this module is just a simple combination of two things:

  1. A transducer called calculate(please suggest me a better name)

    This is the actual function that calculates the new positions of the view when the move gesture event comes in.

  2. A number called GESTURE_NUMBER

    This define that the gesture will start calculate when the gesture number matches this number.

    You can set any number you want if your touch screen supports it :p

drag

It's just a simple transducer takes one finger input with the move of the finger and generates new layout of the component.

pinch

It's a pinch gesture, also a zoom gesture. It takes two fingers gestures and generates new layout of the component.

Contribute

Using

js-standard-style

react-native-gestures's People

Contributors

kiddkai avatar phil-allcock avatar sibelius avatar reallistic avatar

Watchers

 avatar

Forkers

react-utils

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.