-
Notifications
You must be signed in to change notification settings - Fork 101
/
AtoZList.js
128 lines (108 loc) · 3.1 KB
/
AtoZList.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/**
* This is the entry point for your experience that you will run on Exponent.
*
* Start by looking at the render() method of the component called
* FirstExperience. This is where the text and example components are.
*/
'use strict';
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import {
AppRegistry,
Image,
TouchableHighlight,
ScrollView,
StyleSheet,
Text,
PanResponder,
TouchableWithoutFeedback,
View,
Platform,
} from 'react-native';
import _ from 'lodash';
import FixedHeightWindowedListView from './FixedHeightWindowedListView';
import AlphabetPicker from './AlphabetPicker';
export default class AtoZList extends Component {
static propTypes = {
sectionHeaderHeight: PropTypes.number.isRequired,
cellHeight: PropTypes.number.isRequired,
data: PropTypes.object.isRequired,
renderCell: PropTypes.func,
renderSection: PropTypes.func,
onEndReached: PropTypes.func,
onScroll: PropTypes.func,
};
constructor(props, context) {
super(props, context);
let sectionHeight = props.sectionHeaderHeight || 35;
let cellHeight = props.cellHeight || 95;
var dataSource = new FixedHeightWindowedListView.DataSource({
getHeightForSectionHeader: (sectionId) => {
return sectionHeight;
},
getHeightForCell: (sectionId) => {
return cellHeight;
}
});
this.state = {
dataSource: dataSource.cloneWithCellsAndSections(this.props.data),
alphabet: Object.keys(this.props.data)
};
this.dataSource = dataSource;
}
componentWillReceiveProps(nextProps) {
if(this.props.data !== nextProps.data){
this.setState({
dataSource: this.dataSource.cloneWithCellsAndSections(nextProps.data),
alphabet: Object.keys(nextProps.data)
});
}
}
render() {
this._alphabetInstance = (
<View style={styles.alphabetSidebar}>
<AlphabetPicker alphabet={this.state.alphabet} onTouchLetter={this._onTouchLetter.bind(this)} />
</View>
);
return (
<View style={{flex: 1}}>
<View style={styles.container}>
<FixedHeightWindowedListView
ref={view => this._listView = view}
dataSource={this.state.dataSource}
renderCell={this.props.renderCell}
renderSectionHeader={this.props.renderSection}
incrementDelay={16}
initialNumToRender={8}
pageSize={Platform.OS === 'ios' ? 15 : 8}
maxNumToRender={70}
numToRenderAhead={40}
numToRenderBehind={4}
onEndReached={this.props.onEndReached}
onScroll={this.props.onScroll}
/>
</View>
{this._alphabetInstance}
</View>
);
}
_onTouchLetter(letter) {
this._listView.scrollToSectionBuffered(letter);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
paddingTop: 0,
backgroundColor: '#fff',
},
alphabetSidebar: {
position: 'absolute',
backgroundColor: 'transparent',
top: 0,
bottom: 0,
right: 0,
justifyContent: 'center',
alignItems: 'center',
},
});