react-native-selectablesectionlistview
Advanced tools
@@ -42,2 +42,33 @@ 'use strict'; | ||
| componentDidMount() { | ||
| // push measuring into the next tick | ||
| setTimeout(() => { | ||
| UIManager.measure(this.refs.view.getNodeHandle(), (x,y,w,h) => { | ||
| this.containerHeight = h; | ||
| }); | ||
| }, 0); | ||
| // only if we have an object, the sidebar will show | ||
| // without it we don't need to know the total height | ||
| if (!Array.isArray(this.props.data)) { | ||
| this.calculateTotalHeight(); | ||
| } | ||
| } | ||
| componentWillReceiveProps(nextProps) { | ||
| if (nextProps.data !== this.props.data) { | ||
| this.calculateTotalHeight(nextProps.data); | ||
| } | ||
| } | ||
| calculateTotalHeight(data) { | ||
| data = data || this.props.data; | ||
| this.totalHeight = Object.keys(data) | ||
| .reduce((carry, key) => { | ||
| carry += data[key].length * this.props.cellHeight; | ||
| carry += this.props.sectionHeaderHeight; | ||
| return carry; | ||
| }, 0); | ||
| } | ||
| updateTagInSectionMap(tag, section) { | ||
@@ -52,3 +83,2 @@ this.sectionTagMap[section] = tag; | ||
| scrollToSection(section) { | ||
| if (!this.props.useDynamicHeights) { | ||
@@ -67,4 +97,6 @@ var cellHeight = this.props.cellHeight; | ||
| var y = numcells * cellHeight + sectionHeaderHeight; | ||
| var maxY = this.totalHeight-this.containerHeight; | ||
| y = y > maxY ? maxY : y; | ||
| this.refs.listview.refs.listviewscroll.scrollTo(y, 0); | ||
| } else { | ||
@@ -182,3 +214,3 @@ // this breaks, if not all of the listview is pre-rendered! | ||
| return ( | ||
| <View style={[styles.container, this.props.style]}> | ||
| <View ref="view" style={[styles.container, this.props.style]}> | ||
| <ListView | ||
@@ -185,0 +217,0 @@ ref="listview" |
+1
-1
| { | ||
| "name": "react-native-selectablesectionlistview", | ||
| "version": "0.2.0", | ||
| "version": "0.2.1", | ||
| "description": "A Listview with a sidebar to jump to sections directly", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
16726
6.02%440
7.06%