Skip to content

Commit

Permalink
Merge pull request #21 from marxsk/master
Browse files Browse the repository at this point in the history
Add compareFunction to change order of sections
  • Loading branch information
sunnylqm committed Oct 7, 2016
2 parents 31e050e + 994f0d7 commit 07ad23c
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions components/SelectableSectionsListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,10 @@ export default class SelectableSectionsListView extends Component {
if (!this.props.useDynamicHeights) {
const cellHeight = this.props.cellHeight;
let sectionHeaderHeight = this.props.sectionHeaderHeight;
const keys = Object.keys(this.props.data);
let keys = Object.keys(this.props.data);
if (typeof(this.props.compareFunction) === "function") {
keys = keys.sort(this.props.compareFunction);
}
const index = keys.indexOf(section);

let numcells = 0;
Expand Down Expand Up @@ -208,6 +211,11 @@ export default class SelectableSectionsListView extends Component {
let sectionList;
let renderSectionHeader;
let dataSource;
let sections = Object.keys(data);

if (typeof(this.props.compareFunction) === "function") {
sections = sections.sort(this.props.compareFunction);
}

if (dataIsArray) {
dataSource = this.state.dataSource.cloneWithRows(data);
Expand All @@ -216,15 +224,15 @@ export default class SelectableSectionsListView extends Component {
<SectionList
style={this.props.sectionListStyle}
onSectionSelect={this.scrollToSection}
sections={Object.keys(data)}
sections={sections}
data={data}
getSectionListTitle={this.props.getSectionListTitle}
component={this.props.sectionListItem}
/> :
null;

renderSectionHeader = this.renderSectionHeader;
dataSource = this.state.dataSource.cloneWithRowsAndSections(data);
dataSource = this.state.dataSource.cloneWithRowsAndSections(data, sections);
}

const renderFooter = this.props.footer ?
Expand Down Expand Up @@ -291,6 +299,11 @@ SelectableSectionsListView.propTypes = {
getSectionTitle: PropTypes.func,
getSectionListTitle: PropTypes.func,

/**
* Function to sort sections. If not provided, the sections order will match data source
*/
compareFunction: PropTypes.func,

/**
* Callback which should be called when a cell has been selected
*/
Expand Down

0 comments on commit 07ad23c

Please sign in to comment.