diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..c8f4f1b --- /dev/null +++ b/.babelrc @@ -0,0 +1,21 @@ +{ + "whitelist": [ + "es6.modules", + "es6.arrowFunctions", + "es6.blockScoping", + "es6.classes", + "es6.destructuring", + "es6.parameters", + "es6.properties.computed", + "es6.properties.shorthand", + "es6.spread", + "es6.templateLiterals", + "es6.constants", + "es7.trailingFunctionCommas", + "es7.objectRestSpread", + "react", + "es7.classProperties", + "es7.asyncFunctions", + "es7.decorators" + ] +} \ No newline at end of file diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..31a083b --- /dev/null +++ b/.editorconfig @@ -0,0 +1,12 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +[*] +charset = utf-8 +end_of_line = lf +insert_final_newline = true +trim_trailing_whitespace = true +indent_style = space +indent_size = 2 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c1f3fb6 --- /dev/null +++ b/.gitignore @@ -0,0 +1,31 @@ +# OSX +# +.DS_Store + +# Xcode +# +build/ +*.pbxuser +!default.pbxuser +*.mode1v3 +!default.mode1v3 +*.mode2v3 +!default.mode2v3 +*.perspectivev3 +!default.perspectivev3 +xcuserdata +*.xccheckout +*.moved-aside +DerivedData +*.hmap +*.ipa +*.xcuserstate +project.xcworkspace + +# node.js +# +node_modules/ +npm-debug.log + + +/dist diff --git a/README.md b/README.md new file mode 100644 index 0000000..d57a2ed --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +## react-native-dismiss-keyboard ![CircleCi](https://circleci.com/gh/DanielMSchmidt/react-native-dismiss-keyboard.png?circle-token=905f7ed099611e3f8079a5bf72674beab5e55e50) + +A simple way to dismiss the keyboard programmatically in a react native application. + +## Add it to your project + +1. Run `npm install react-native-dismiss-keyboard --save` +2. `var dismissKeyboard = require('react-native-dismiss-keyboard');` +3. Run `dismissKeyboard()` anywhere in your code to close the keyboard. + +## Support + +We currently support `react-native >= 0.11`, if you experience any restrictions or if it works below, please let us know. + +## Contribution + +Please make sure to run the tests before proposing a PR by running `npm test`. diff --git a/index.js b/index.js new file mode 100644 index 0000000..6aa79fa --- /dev/null +++ b/index.js @@ -0,0 +1,11 @@ +import React from 'react-native'; + +const { + TextInput: { + State: TextInputState, + }, +} = React; + +export default function dismissKeyboard() { + TextInputState.blurTextInput(TextInputState.currentlyFocusedField()); +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..7462b82 --- /dev/null +++ b/package.json @@ -0,0 +1,91 @@ +{ + "name": "react-native-dismiss-keyboard", + "version": "0.0.2", + "description": "A simple way to dismiss the keyboard programmatically in a react native application.", + "main": "dist/index.js", + "scripts": { + "babel": "babel *.js --out-dir dist", + "build": "npm run-script clear && npm run-script babel", + "clear": "rm -rf dist/ && mkdir dist/", + "prepublish": "npm run build", + "test": "xo" + }, + "files": [ + "dist/" + ], + "repository": { + "type": "git", + "url": "git@github.com:DanielMSchmidt/react-native-dismiss-keyboard.git" + }, + "author": "Daniel Schmidt (https://github.com/DanielMSchmidt)", + + "xo": { + "ignores": [ + "DismissKeyboardExample/**", + "dist/*" + ], + "esnext": true, + "space": 2, + "plugins": [ + "react" + ], + "rules": { + "babel/object-curly-spacing": [ + 2, + "always" + ], + "comma-dangle": [ + 2, + "always-multiline" + ], + "react/jsx-curly-spacing": 2, + "strict": [ + 2, + "never" + ], + "no-use-before-define": 0, + "one-var": [ + 2, + { + "uninitialized": "always", + "initialized": "never" + } + ], + "react/no-set-state": 1, + "react/prop-types": 2, + "react/jsx-sort-prop-types": 2, + "react/jsx-closing-bracket-location": [ + 2, + { + "selfClosing": "after-props", + "nonEmpty": "after-props" + } + ], + "react/jsx-indent-props": [ + 2, + 2 + ], + "react/self-closing-comp": 2 + } + }, + "keywords": [ + "react", + "react-native", + "ios", + "android", + "keyboard", + "dismiss" + ], + "license": "MIT", + "devDependencies": { + "babel": "^5.8.34", + "babel-eslint": "^5.0.0-beta6", + "eslint": "^1.10.3", + "eslint-config-xo": "^0.9.1", + "eslint-plugin-babel": "^3.0.0", + "eslint-plugin-no-empty-blocks": "0.0.2", + "eslint-plugin-no-use-extend-native": "^0.3.3", + "eslint-plugin-react": "^3.13.1", + "xo": "^0.12.1" + } +}