Package Exports
- react-native-scrollable-mixin
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (react-native-scrollable-mixin) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
ScrollableMixin
ScrollableMixin lets your scrollable React Native components conform to a standard interface, making it easier to compose components. This lets you compose different types of ScrollView-like components while preserving the ScrollView API, including methods like scrollTo.
Installation
npm install react-native-scrollable-mixinUsage
Add ScrollableMixin to your scrollable React components and implement getScrollResponder(), which must return the underlying scrollable component's scroll responder.
var ScrollableMixin = require('react-native-scrollable-mixin');
var InfiniteScrollView = React.createClass({
mixins: [ScrollableMixin],
propTypes: {
...ScrollView.propTypes,
renderScrollView: React.PropTypes.func.isRequired,
},
/**
* IMPORTANT: You must return the scroll responder of the underlying
* scrollable component from getScrollResponder() when using ScrollableMixin.
*/
getScrollResponder() {
return this._scrollView.getScrollResponder();
},
setNativeProps(props) {
this._scrollView.setNativeProps(props);
},
render() {
var {
renderScrollView,
...props
} = this.props;
return React.cloneElement(renderScrollView(props), {
ref: (ref) => this._scrollView = ref,
});
},
});Features
By mixing in ScrollableMixin, your custom component gets the ScrollView API. For example:
class App extends React.Component {
render() {
return (
<ListView
ref={(ref) => this._scrollView = ref}
renderScrollView={(props) => <InfiniteScrollView {...props} />}
dataSource={...}
renderRow={...}
/>
);
}
_scrollToTop() {
// By having all scrollable components conform to ScrollableMixin's
// standard, calling `scrollTo` on your top-level scrollable component will
// successfully scroll the underlying scroll view.
this._scrollView.scrollTo(0, 0);
}
}