-
Notifications
You must be signed in to change notification settings - Fork 59
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added tap / click elements example to readme #55
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,6 +210,41 @@ var HorizontalScroll = React.createClass({ | |
}) | ||
``` | ||
|
||
## Tap / Click Elements inside IScroll | ||
|
||
To override the native scrolling iScroll has to inhibit some default browser behaviors, such as mouse clicks. See [iScroll manual](http://iscrolljs.com/) options.click and options.tap. The following is an example of including a clickable element. | ||
|
||
```js | ||
constructor(props) { | ||
super(props); | ||
this.refDict = []; | ||
} | ||
|
||
componentDidMount() { | ||
this.refDict[0].addEventListener("tap", () => this.handleTap(this.refDict[0])); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With binded handler to class you can do simple .addEventListener("tap", this.handleTap) |
||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And when you add listener, you have to remove it too componentWillUnmount() {
if(this.myElementRef) {
this.myElementRef.removeEventListener("tap", this.handleTap)
}
} |
||
handleTap(e) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Bind tap handler in constructor: this.handleTap = this.handleTap.bind(this) or use class props syntax: handleTap = (ev) => {
....
} Then you dont need to call it |
||
console.log(e.id); | ||
} | ||
|
||
render(){ | ||
return( | ||
<ReactIScroll iScroll={iScroll} | ||
options={{ | ||
tap: true | ||
}} | ||
> | ||
<div> | ||
<div id={0} ref={el => this.refDict[0] = el}> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With simple example like this you can save ref directly. ref={el => this.myElementRef = el} |
||
Click me in react-iscroll | ||
</div> | ||
</div> | ||
</ReactIScroll> | ||
) | ||
} | ||
``` | ||
|
||
## Example | ||
|
||
There is example application. You can run it with this commands: | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With comlicated code it would be better to check presence of element