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
.
See react-native-scrollable-decorator for the decorator version of this mixin.
Installation
npm install react-native-scrollable-mixin
Usage
Add ScrollableMixin to your scrollable React components and implement getScrollResponder()
, which must return the underlying scrollable component's scroll responder.
With JavaScript classes
Use Object.assign
to copy ScrollableMixin's functions to your class's prototype as instance methods:
Component static propTypes = ...ScrollViewpropTypes renderScrollComponent: PropTypesfuncisRequired ; /** * IMPORTANT: You must return the scroll responder of the underlying * scrollable component from getScrollResponder() when using ScrollableMixin. */ { return this_scrollView; } { this_scrollView; } { let renderScrollComponent ...props = thisprops; return React; } // Mix in ScrollableMixin's methods as instance methodsObject;
React.createClass
With let ScrollableMixin = ; let InfiniteScrollView = React;
Features
By mixing in ScrollableMixin, your custom component gets the ScrollView
API. For example:
Component { return <ListView ref= this_scrollView = component renderScrollView= <InfiniteScrollView ...props /> dataSource=... renderRow=... /> ; } { // 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; }