[react-native-swipe-gestures]: add type definitions (#35465)

This commit is contained in:
Ian Rudge 2019-05-15 09:07:23 -07:00 committed by Nathan Shively-Sanders
parent a85998b8f2
commit 5845f55fba
4 changed files with 84 additions and 0 deletions

View File

@ -0,0 +1,34 @@
// Type definitions for react-native-swipe-gestures 1.0
// Project: https://github.com/glepur/react-native-swipe-gestures
// Definitions by: Ian <https://github.com/ian-rudge>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
// TypeScript Version: 2.8
import { Component } from 'react';
import { PanResponderGestureState } from 'react-native';
export interface SwipeDirections {
SWIPE_UP: 'SWIPE_UP';
SWIPE_DOWN: 'SWIPE_DOWN';
SWIPE_LEFT: 'SWIPE_LEFT';
SWIPE_RIGHT: 'SWIPE_RIGHT';
}
export const swipeDirections: SwipeDirections;
export interface GestureRecognizerConfig {
velocityThreshold?: number;
directionalOffsetThreshold?: number;
gestureIsClickThreshold?: number;
}
export interface GestureRecognizerProps {
config?: GestureRecognizerConfig;
onSwipe?: (gestureName: string, state: PanResponderGestureState) => void;
onSwipeUp?: (state: PanResponderGestureState) => void;
onSwipeDown?: (state: PanResponderGestureState) => void;
onSwipeLeft?: (state: PanResponderGestureState) => void;
onSwipeRight?: (state: PanResponderGestureState) => void;
}
export default class GestureRecognizer extends Component<GestureRecognizerProps> {}

View File

@ -0,0 +1,25 @@
import * as React from 'react';
import GestureRecognizer, { GestureRecognizerConfig, swipeDirections } from 'react-native-swipe-gestures';
const { SWIPE_UP, SWIPE_DOWN, SWIPE_LEFT, SWIPE_RIGHT } = swipeDirections;
const config: GestureRecognizerConfig = {
velocityThreshold: 0.3,
directionalOffsetThreshold: 80,
gestureIsClickThreshold: 5,
};
class Example extends React.Component {
render() {
return (
<GestureRecognizer
config={config}
onSwipe={(direction, state) => {}}
onSwipeUp={state => {}}
onSwipeDown={state => {}}
onSwipeLeft={state => {}}
onSwipeRight={state => {}}
/>
);
}
}

View File

@ -0,0 +1,24 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true,
"jsx": "react"
},
"files": [
"index.d.ts",
"react-native-swipe-gestures-tests.tsx"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }