- Notifications
You must be signed in to change notification settings - Fork83
An invertible ScrollView for React Native
License
expo/react-native-invertible-scroll-view
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
InvertibleScrollView is a React Native scroll view that can be inverted so that content is rendered starting from the bottom, and the user must scroll down to reveal more. This is a common design in chat applications and the command-line terminals. InvertibleScrollView also supports horizontal scroll views to present content from right to left.
It conforms toScrollableMixin so you can compose it with other scrollable components.
Use this with react-native 0.8.0-rc or later.
npm install react-native-invertible-scroll-viewCompose InvertibleScrollView with the scrollable component you would like to invert. In the case of a ListView, you would write:
importReactfrom'react-native';let{ ListView, Text, TouchableHighlight, View, StyleSheet,}=React;importInvertibleScrollViewfrom'react-native-invertible-scroll-view';classInvertedScrollComponentextendsReact.Component{constructor(props,context){super(props,context);this._data=[];this.state={dataSource:newListView.DataSource({rowHasChanged:(r1,r2)=>r1!==r2,}),};}render(){return(<ListViewrenderScrollComponent={props=><InvertibleScrollView{...props}inverted/>}dataSource={this.state.dataSource}renderHeader={this._renderHeader.bind(this)}renderRow={this._renderRow.bind(this)}style={styles.container}/>);}_renderHeader(){return(<TouchableHighlightonPress={this._onPress.bind(this)}style={styles.button}><Text>Add a row</Text></TouchableHighlight>);}_renderRow(row){return<Textkey={row}style={styles.row}>{row}</Text>}_onPress(){this._data.push(`${newDate}`);varrows=this._data;// It's important to keep row IDs consistent to avoid extra rendering. You// may need to reverse the list of row IDs so the so that the inversion// will order the rows correctly.varrowIds=rows.map((row,index)=>index).reverse();this.setState({dataSource:this.state.dataSource.cloneWithRows(rows,rowIds),});}}letstyles=StyleSheet.create({container:{flex:1,justifyContent:'center',alignItems:'center',backgroundColor:'#F5FCFF',},button:{padding:20,borderStyle:'solid',borderWidth:1,borderColor:'black',},row:{padding:4,},});
NOTE: When inverting a ListView, you must create a ListView that delegates to an InvertibleScrollView as shown above and not the other way around. Otherwise it will not be able to invert the rows and the content will look upside down. This is true for any scroll view that adds its own children, not just ListView.
- Horizontal scroll views are supported
- To scroll to the bottom, call
scrollTo(0)on a ref to the scroll view - When the scroll view is inverted, InvertibleScrollView wraps each child in a View that is flipped
- Scroll views that add children (ex: ListViews) must delegate to InvertibleScrollViews so that the children can be properly inverted
- List section headers are unsupported
- Styles like
paddingare not corrected, so top padding will actually pad the bottom of the component - Properties like
contentOffsetandcontentInsetare not flipped; for example, the top inset adjusts the bottom of an inverted scroll view
InvertibleScrollView uses a scale transformation to efficiently invert the view. The scroll view's viewport is inverted to flip the entire component, and then each child is inverted again so that the content appears unflipped.
About
An invertible ScrollView for React Native
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors9
Uh oh!
There was an error while loading.Please reload this page.
