├── .editorconfig ├── .gitignore ├── .travis.yml ├── HISTORY.md ├── LICENSE.md ├── README.md ├── examples ├── demo.html ├── demo.tsx ├── disable-inner.html ├── disable-inner.tsx ├── disable-outer.html └── disable-outer.tsx ├── index.js ├── package.json ├── src ├── PressEvent.tsx └── index.tsx ├── tests └── index.js ├── tsconfig.json └── typings ├── custom.d.ts └── index.d.ts /.editorconfig: -------------------------------------------------------------------------------- 1 | # top-most EditorConfig file 2 | root = true 3 | 4 | # Unix-style newlines with a newline ending every file 5 | [*.{js,css,md}] 6 | end_of_line = lf 7 | insert_final_newline = true 8 | indent_style = space 9 | indent_size = 2 10 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | *.log 3 | *.log.* 4 | .idea/ 5 | .ipr 6 | .iws 7 | *~ 8 | ~* 9 | *.diff 10 | *.patch 11 | *.bak 12 | .DS_Store 13 | Thumbs.db 14 | .project 15 | .*proj 16 | .svn/ 17 | *.swp 18 | *.swo 19 | *.pyc 20 | *.pyo 21 | .build 22 | node_modules 23 | .cache 24 | dist 25 | *.css 26 | build 27 | lib 28 | coverage 29 | yarn.lock 30 | .vscode 31 | src/*.js 32 | /es/ -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | sudo: false 4 | 5 | notifications: 6 | email: 7 | - yiminghe@gmail.com 8 | 9 | node_js: 10 | - 6.9.1 11 | 12 | before_install: 13 | - | 14 | if ! git diff --name-only $TRAVIS_COMMIT_RANGE | grep -qvE '(\.md$)|(^(docs|examples))/' 15 | then 16 | echo "Only docs were updated, stopping build process." 17 | exit 18 | fi 19 | phantomjs --version 20 | script: 21 | - | 22 | if [ "$TEST_TYPE" = test ]; then 23 | npm test 24 | else 25 | npm run $TEST_TYPE 26 | fi 27 | env: 28 | matrix: 29 | - TEST_TYPE=lint 30 | - TEST_TYPE=test 31 | - TEST_TYPE=coverage 32 | -------------------------------------------------------------------------------- /HISTORY.md: -------------------------------------------------------------------------------- 1 | # History 2 | ---- 3 | 4 | ## 1.3.0 / 2018-07-26 5 | 6 | - support activeStopPropagation 7 | 8 | ## 1.2.0 / 2017-05-15 9 | 10 | - support stopPropagation for onPress and onLongPress 11 | 12 | ## 1.0.0 / 2016-11-29 13 | 14 | - inspired by react-native 15 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014-present yiminghe 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # rc-touchable 2 | --- 3 | 4 | react touchable component. inspired by react-native. 5 | 6 | [![NPM version][npm-image]][npm-url] 7 | [![build status][travis-image]][travis-url] 8 | [![Test coverage][coveralls-image]][coveralls-url] 9 | [![npm download][download-image]][download-url] 10 | 11 | [npm-image]: http://img.shields.io/npm/v/rc-touchable.svg?style=flat-square 12 | [npm-url]: http://npmjs.org/package/rc-touchable 13 | [travis-image]: https://img.shields.io/travis/react-component/touchable.svg?style=flat-square 14 | [travis-url]: https://travis-ci.org/react-component/touchable 15 | [coveralls-image]: https://img.shields.io/coveralls/react-component/touchable.svg?style=flat-square 16 | [coveralls-url]: https://coveralls.io/r/react-component/touchable?branch=master 17 | [gemnasium-image]: http://img.shields.io/gemnasium/react-component/touchable.svg?style=flat-square 18 | [gemnasium-url]: https://gemnasium.com/react-component/touchable 19 | [node-image]: https://img.shields.io/badge/node.js-%3E=_0.10-green.svg?style=flat-square 20 | [node-url]: http://nodejs.org/download/ 21 | [download-image]: https://img.shields.io/npm/dm/rc-touchable.svg?style=flat-square 22 | [download-url]: https://npmjs.org/package/rc-touchable 23 | 24 | ## Install 25 | 26 | [![rc-touchable](https://nodei.co/npm/rc-touchable.png)](https://npmjs.org/package/rc-touchable) 27 | 28 | ## Usage 29 | 30 | ```js 31 | import Touchable from 'rc-touchable'; 32 | ReactDOM.render( 33 |
click
34 |
, container); 35 | ``` 36 | 37 | ## API 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 |
nametypedefaultdescription
disabledbooleanfalse
onPress()=>voidonPress/onTap callback
onLongPress()=>voidonLongPress/onLongTap callback
activeClassNamestringclassName applied to child when active
activeStyleobjectstyle applied to child when active
activeStopPropagationobjectstop child active propagate to parent
87 | 88 | 89 | ## Development 90 | 91 | ``` 92 | npm install 93 | npm start 94 | ``` 95 | 96 | ## Example 97 | 98 | http://localhost:8007/examples/ 99 | 100 | online example: http://react-component.github.io/touchable/ 101 | 102 | 103 | ## Test Case 104 | 105 | ``` 106 | npm test 107 | npm run chrome-test 108 | ``` 109 | 110 | ## Coverage 111 | 112 | ``` 113 | npm run coverage 114 | ``` 115 | 116 | open coverage/ dir 117 | 118 | 119 | ## License 120 | 121 | rc-touchable is released under the MIT license. 122 | -------------------------------------------------------------------------------- /examples/demo.html: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/react-component/touchable/d1ac708448cb7b4edf7440d850b71ec8a47fa986/examples/demo.html -------------------------------------------------------------------------------- /examples/demo.tsx: -------------------------------------------------------------------------------- 1 | /* tslint:disable:no-console */ 2 | 3 | import Touchable from 'rc-touchable'; 4 | import React from 'react'; 5 | import ReactDOM from 'react-dom'; 6 | 7 | const style = ` 8 | .active { 9 | background: red; 10 | } 11 | .x { 12 | display:inline-block; 13 | width:100px; 14 | height:100px; 15 | border:1px solid yellow; 16 | } 17 | .x:active { 18 | background: red; 19 | } 20 | `; 21 | 22 | const Test = React.createClass({ 23 | componentWillMount() { 24 | (window as any).log = this.log; 25 | }, 26 | 27 | onPress(e) { 28 | e.stopPropagation(); 29 | console.log(e.type, e.target.id); 30 | }, 31 | 32 | onLongPress(e) { 33 | e.stopPropagation(); 34 | console.log(e.type, e.target.id); 35 | }, 36 | log(m) { 37 | this.refs.log.innerHTML += `

${m}:${Date.now()}

`; 38 | this.refs.log.scrollTop = this.refs.log.scrollHeight; 39 | }, 40 | render() { 41 | return ( 42 |
43 |
44 |