Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
@egman1/react-iscroll
Advanced tools
React component for wrapping iScroll library.
iscroll
to iScroll
and naming is unified across whole package
<ReactIScroll iScroll={iScroll}>
instead of <ReactIScroll iscroll={iScroll}>
style
and className
properties.iScroll is a high performance, small footprint, dependency free, multi-platform javascript scroller.
Works on mobile and desktop, supports zooming, pagging, parallax scrolling, carousels and is incredibly small (4kb compress gzipped).
React components are a great way to compose your application. And they are a great way to handle third party libraries. You can wrap complex logic around a library and expose a simple API, which react users are used to.
npm install react-iscroll
Simple example app. Allow scrolling on long list and catch event when scrolling starts.
var React = require('react'),
ReactIScroll = require('react-iscroll'),
iScroll = require('iscroll');
var ExampleApp = React.createClass({
getDefaultProps: function() {
return ({
options: {
mouseWheel: true,
scrollbars: true
}
})
},
onScrollStart: function() {
console.log("iScroll starts scrolling")
},
render: function() {
var i = 0, len = 1000, listOfLi = [];
for(i; i < len; i++) {
listOfLi.push(<li key={i}>Row {i+1}</li>)
}
return (
<div style={height: '100vh'}>
<h1>Example of scrollable list</h1>
<ReactIScroll iScroll={iScroll}
options={this.props.options}
onScrollStart={this.onScrollStart}>
<ul>
{listOfLi}
</ul>
</ReactIScroll>
</div>
)
}
})
You have to use probe version of iScroll and add probeType
to <ReactIScroll options={{probeType:2}}>
. Check iScroll documentation for more information.
Basic configuration. Just component with iScroll library. You can pick build which you want.
var iScroll = require('iscroll/build/iscroll-lite')
<ReactIScroll iScroll={iScroll}>
<div>Long content...</div>
</ReactIScroll>
You can customize iScroll options with options
property. Supports all from iScroll manual
var iScroll = require('iscroll/build/iscroll-probe')
var options = {
mouseWheel: true,
scrollbars: true,
freeScroll: true,
invertWheelDirection: true,
momentum: false,
indicators: {...}
}
<ReactIScroll iScroll={iScroll}
options={options}>
<div>Long content...</div>
</ReactIScroll>
Component supports all iScroll events. All of them passed iScroll instance to callback.
var iScroll = require('iscroll/build/iscroll-probe')
<ReactIScroll iScroll={iScroll}
onBeforeScrollStart={this.onBeforeScrollStart}
onScrollCancel={this.onScrollCancel}
onScrollStart={this.onScrollStart}
onScroll={this.onScroll}
onScrollEnd={this.onScrollEnd}
onFlick={this.onFlick}
onZoomStart={this.onZoomStart}
onZoomEnd={this.onZoomEnd}>
<div>Long content...</div>
</ReactIScroll>
Plus there is one special event 'onRefresh' which is triggered when iScroll is refreshed. You can then get state of iScroll like iscroll.hasVerticalScroll
, iscroll.x
or iscroll.scale
.
Watch out when updating state by value from iScroll. Always update state only when value changed to prevent circular updating (stack level too deep)
var iScroll = require('iscroll/build/iscroll-lite')
onRefresh: function(iScrollInstance) {
var yScroll = iScrollInstance.y;
console.log("vertical position:" + yScroll)
if(this.state.y != yScroll) {
this.setState({y: yScroll})
}
},
render: function() {
return (
<ReactIScroll iScroll={iScroll}
onRefresh={this.onRefresh}>
<div>Long content...</div>
</ReactIScroll>
)
}
Return iScroll instance if initialized
Run callback with iScroll instance as argument if instance is initialized.
You can pass true
as first argument for call callback after iScroll is initialized
onSomethingClick: function(ev) {
ev.preventDefault()
this.refs.iScroll.withIScroll(function(iScroll) {
iScroll.scrollTo(0,0)
})
},
render: function() {
return(
<div>
<ReactIScroll ref="iScroll"
iScroll={iScroll}
onRefresh={this.onRefresh}>
<div>Long content...</div>
<a class="#" onClick={this.onSomethingClick}>Back to top</a>
</ReactIScroll>
</div>
)
}
Common usecase of horizontal scrolling
var React = require('react'),
ReactIScroll = require('react-iscroll'),
iScroll = require('iscroll');
var HorizontalScroll = React.createClass({
render: function() {
return (
<ReactIScroll iScroll={iScroll}
options={{mouseWheel: true, scrollbars: true, scrollX: true}}>
<div style={{width:'200%'}}>
<ul>
{listOfLi}
</ul>
</div>
</ReactIScroll>
)
}
})
There is example application. You can run it with this commands:
npm install
npm run example
open http://localhost:8080/
shouldComponentUpdate
. Now it is always true because this.props.children
are new object everytime and can't be compared via ==
or ===
. Maybe there is some way how to cheaply compare them.onRefresh
event when iScroll is internally refreshed (e.g. on window resize)require('iscroll')
by itself. Instead pass it in props (there is few different versions of iScroll and you want to pick correct one for you)React iScroll is released under the MIT License.
FAQs
React component for wrapping iScroll library.
The npm package @egman1/react-iscroll receives a total of 0 weekly downloads. As such, @egman1/react-iscroll popularity was classified as not popular.
We found that @egman1/react-iscroll demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.