Skip to content
This repository has been archived by the owner on Sep 13, 2020. It is now read-only.

feat: add TypeScript typings #400

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
90 changes: 90 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Type definitions for react-native-side-menu 1.1
// Project: https://github.com/react-native-community/react-native-side-menu#readme
// Definitions by: Jules Samuel Randolph <https://github.com/jsamr>
// Matt Pawley <https://github.com/toughdeveloper>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

import { ReactNode, Component } from "react";
import { GestureResponderEvent, Animated, ViewStyle } from "react-native";

export interface ReactNativeSideMenuProps {
/**
* Menu component
*/
menu: ReactNode;
/**
* Props driven control over menu open state
* @default false
*/
isOpen?: boolean;
/**
* Content view left margin if menu is opened
*/
openMenuOffset?: number;
/**
* Content view left margin if menu is hidden
*/
hiddenMenuOffset?: number;
/**
* Edge distance on content view to open side menu, defaults to 60
*/
edgeHitWidth?: number;
/**
* X axis tolerance
*/
toleranceX?: number;
/**
* Y axis tolerance
*/
toleranceY?: number;
/**
* Disable whether the menu can be opened with gestures or not
* @default false
*/
disableGestures?: boolean;
/**
* Function that accepts event as an argument and specify if side-menu should react on the touch or not.
* Check https://facebook.github.io/react-native/docs/gesture-responder-system.html for more details
*/
onStartShouldSetResponderCapture?: (e: GestureResponderEvent) => boolean;
/**
* Callback on menu open/close. Is passed isOpen as an argument
*/
onChange?: (isOpen: boolean) => void;
/**
* Callback on menu move. Is passed left as an argument
*/
onMove?: (left: number) => void;
/**
* Callback when menu is sliding. It returns a decimal from 0 to 1 which represents the percentage of menu offset between hiddenMenuOffset and openMenuOffset.
*/
onSliding?: (fraction: number) => void;
/**
* @default left
*/
menuPosition?: "left" | "right";
animationFunction?: (
prop: Animated.Value,
value: number
) => Animated.CompositeAnimation;
animationStyle?: (value: number) => ViewStyle;
/**
* Callback when menu animation has completed.
*/
onAnimationComplete?: (event: Animated.EndCallback) => void;
/**
* When true, content view will bounce back to openMenuOffset when dragged further
* @default true
*/
bounceBackOnOverdraw?: boolean;
/**
* When true, menu close automatically as soon as an event occurs
* @default true
*/
autoClosing?: boolean;
}

export default class SideMenu extends Component<ReactNativeSideMenuProps> {
openMenu(isOpen: boolean): void;
moveLeft(offset: number): void;
}
8 changes: 6 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
"version": "1.1.3",
"description": "Simple customizable component to create side menu",
"main": "build/index.js",
"types": "index.d.ts",
"scripts": {
"build": "./build.sh",
"prepublish": "./build.sh"
"prepublish": "./build.sh",
"type-check": "tsc --noEmit"
},
"repository": {
"type": "git",
Expand All @@ -27,6 +29,7 @@
"prop-types": "^15.5.10"
},
"devDependencies": {
"@types/react-native": "^0.62.17",
"babel-cli": "^6.24.1",
"babel-eslint": "^7.2.3",
"babel-preset-flow": "^6.23.0",
Expand All @@ -39,6 +42,7 @@
"eslint-plugin-react": "^7.1.0",
"flow-bin": "0.49",
"react": "16.0.0-alpha.12",
"react-native": "^0.46.3"
"react-native": "^0.46.3",
"typescript": "^3.9.6"
}
}
11 changes: 11 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"compilerOptions": {
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019' or 'ESNEXT'. */,
"module": "commonjs" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": ["es6"],
"jsx": "react" /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */,
/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */
}
}
30 changes: 30 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,26 @@
# yarn lockfile v1


"@types/prop-types@*":
version "15.7.3"
resolved "https://registry.yarnpkg.com/@types/prop-types/-/prop-types-15.7.3.tgz#2ab0d5da2e5815f94b0b9d4b95d1e5f243ab2ca7"
integrity sha512-KfRL3PuHmqQLOG+2tGpRO26Ctg+Cq1E01D2DMriKEATHgWLfeNDmq9e29Q9WIky0dQ3NPkd1mzYH8Lm936Z9qw==

"@types/react-native@^0.62.17":
version "0.62.17"
resolved "https://registry.yarnpkg.com/@types/react-native/-/react-native-0.62.17.tgz#78e630692557ae82a106dab7682560a8b541c49a"
integrity sha512-nkWG9oYS0wNiobzY11GOAjG/spV4vCPIbW+u1QIXx+wnQQ4EhkFz6lqqvncO3puXMzwkRhEGawq/bImMReA/vQ==
dependencies:
"@types/react" "*"

"@types/react@*":
version "16.9.41"
resolved "https://registry.yarnpkg.com/@types/react/-/react-16.9.41.tgz#925137ee4d2ff406a0ecf29e8e9237390844002e"
integrity sha512-6cFei7F7L4wwuM+IND/Q2cV1koQUvJ8iSV+Gwn0c3kvABZ691g7sp3hfEQHOUBJtccl1gPi+EyNjMIl9nGA0ug==
dependencies:
"@types/prop-types" "*"
csstype "^2.2.0"

abbrev@1:
version "1.1.0"
resolved "https://registry.yarnpkg.com/abbrev/-/abbrev-1.1.0.tgz#d0554c2256636e2f56e7c2e5ad183f859428d81f"
Expand Down Expand Up @@ -1286,6 +1306,11 @@ csrf@~3.0.0:
tsscmp "1.0.5"
uid-safe "2.1.4"

csstype@^2.2.0:
version "2.6.11"
resolved "https://registry.yarnpkg.com/csstype/-/csstype-2.6.11.tgz#452f4d024149ecf260a852b025e36562a253ffc5"
integrity sha512-l8YyEC9NBkSm783PFTvh0FmJy7s5pFKrDp49ZL7zBGX3fWkO+N4EEyan1qqp8cwPLDcD0OSdyY6hAMoxp34JFw==

csurf@~1.8.3:
version "1.8.3"
resolved "https://registry.yarnpkg.com/csurf/-/csurf-1.8.3.tgz#23f2a13bf1d8fce1d0c996588394442cba86a56a"
Expand Down Expand Up @@ -4088,6 +4113,11 @@ typedarray@^0.0.6:
version "0.0.6"
resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777"

typescript@^3.9.6:
version "3.9.6"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.6.tgz#8f3e0198a34c3ae17091b35571d3afd31999365a"
integrity sha512-Pspx3oKAPJtjNwE92YS05HQoY7z2SFyOpHo9MqJor3BXAGNaPUs83CuVp9VISFkSjyRfiTpmKuAYGJB7S7hOxw==

ua-parser-js@^0.7.9:
version "0.7.13"
resolved "https://registry.yarnpkg.com/ua-parser-js/-/ua-parser-js-0.7.13.tgz#cd9dd2f86493b3f44dbeeef3780fda74c5ee14be"
Expand Down