react-native-scrollable-mixin
Advanced tools
Comparing version 0.0.3 to 0.0.4
{ | ||
"name": "react-native-scrollable-mixin", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "A standard interface for your scrollable React Native components, making it easier to compose components.", | ||
@@ -5,0 +5,0 @@ "main": "ScrollableMixin.js", |
@@ -5,2 +5,4 @@ # ScrollableMixin | ||
See [react-native-scrollable-decorator](https://github.com/exponentjs/react-native-scrollable-decorator) for the decorator version of this mixin. | ||
[![npm package](https://nodei.co/npm/react-native-scrollable-mixin.png?downloads=true&downloadRank=true&stars=true)](https://nodei.co/npm/react-native-scrollable-mixin/) | ||
@@ -17,6 +19,43 @@ | ||
## With JavaScript classes | ||
Use `Object.assign` to copy ScrollableMixin's functions to your class as static methods. | ||
```js | ||
var ScrollableMixin = require('react-native-scrollable-mixin'); | ||
class InfiniteScrollView extends React.Component { | ||
static propTypes = { | ||
...ScrollView.propTypes, | ||
renderScrollComponent: PropTypes.func.isRequired | ||
}; | ||
var InfiniteScrollView = React.createClass({ | ||
/** | ||
* 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() { | ||
let { renderScrollComponent, ...props } = this.props; | ||
return React.cloneElement(renderScrollComponent(props), { | ||
ref: component => { this._scrollView = component; }, | ||
}); | ||
} | ||
} | ||
// Mix in ScrollableMixin's methods as static methods | ||
Object.assign(InfiniteScrollView, ScrollableMixin); | ||
``` | ||
### With `React.createClass` | ||
```js | ||
let ScrollableMixin = require('react-native-scrollable-mixin'); | ||
let InfiniteScrollView = React.createClass({ | ||
mixins: [ScrollableMixin], | ||
@@ -26,3 +65,3 @@ | ||
...ScrollView.propTypes, | ||
renderScrollComponent: React.PropTypes.func.isRequired, | ||
renderScrollComponent: PropTypes.func.isRequired, | ||
}, | ||
@@ -48,5 +87,3 @@ | ||
return React.cloneElement(renderScrollComponent(props), { | ||
ref: component => { | ||
this._scrollView = component; | ||
}, | ||
ref: component => { this._scrollView = component; }, | ||
}); | ||
@@ -53,0 +90,0 @@ }, |
@@ -5,3 +5,3 @@ /** | ||
var ScrollableMixin = { | ||
let ScrollableMixin = { | ||
getInnerViewNode(): any { | ||
@@ -8,0 +8,0 @@ return this.getScrollResponder().getInnerViewNode(); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6014
115