|
@@ -4,6 +4,7 @@ import React from 'react'; |
|
@@ -4,6 +4,7 @@ import React from 'react'; |
4
|
import ReactNative from 'react-native';
|
4
|
import ReactNative from 'react-native';
|
5
|
import {isEmptyObject} from '../../utils/Utils';
|
5
|
import {isEmptyObject} from '../../utils/Utils';
|
6
|
import Immutable, {Map} from 'immutable';
|
6
|
import Immutable, {Map} from 'immutable';
|
|
|
7
|
+import * as _ from 'lodash';
|
7
|
|
8
|
|
8
|
const {
|
9
|
const {
|
9
|
View,
|
10
|
View,
|
|
@@ -19,6 +20,10 @@ export default class IndexListView extends React.Component { |
|
@@ -19,6 +20,10 @@ export default class IndexListView extends React.Component { |
19
|
constructor(props) {
|
20
|
constructor(props) {
|
20
|
super (props);
|
21
|
super (props);
|
21
|
this.onTouchMove = this.onTouchMove.bind(this);
|
22
|
this.onTouchMove = this.onTouchMove.bind(this);
|
|
|
23
|
+
|
|
|
24
|
+ this.state = {
|
|
|
25
|
+ list:[]
|
|
|
26
|
+ };
|
22
|
}
|
27
|
}
|
23
|
|
28
|
|
24
|
shouldComponentUpdate(nextProps){
|
29
|
shouldComponentUpdate(nextProps){
|
|
@@ -31,16 +36,26 @@ export default class IndexListView extends React.Component { |
|
@@ -31,16 +36,26 @@ export default class IndexListView extends React.Component { |
31
|
|
36
|
|
32
|
onTouchMove(e) {
|
37
|
onTouchMove(e) {
|
33
|
let {dataSource} = this.props;
|
38
|
let {dataSource} = this.props;
|
34
|
- let Y = e.nativeEvent.pageY - Math.ceil((viewHeight - dataSource.length * (itemHeight+2))/2) - 8-28;
|
|
|
35
|
- var index = Math.ceil(Y/(itemHeight+2))-1;
|
|
|
36
|
- if (dataSource.length - index < 4) {
|
|
|
37
|
- return;
|
39
|
+ let Y = e.nativeEvent.pageY;
|
|
|
40
|
+ for (var i = 0; i < this.state.list.length; i++) {
|
|
|
41
|
+ if (Y > this.state.list[i].y && Y < this.state.list[i].y + 12) {
|
|
|
42
|
+ let name = this.state.list[i].name;
|
|
|
43
|
+ if (name == '0') {
|
|
|
44
|
+ name = '0-9';
|
|
|
45
|
+ }
|
|
|
46
|
+ console.log(name);
|
|
|
47
|
+ this.props.onLetterPress && this.props.onLetterPress(i,name);
|
|
|
48
|
+ break;
|
|
|
49
|
+ }
|
38
|
}
|
50
|
}
|
39
|
- let sectionID = dataSource[index];
|
|
|
40
|
- if (!sectionID) {
|
|
|
41
|
- return;
|
|
|
42
|
}
|
51
|
}
|
43
|
- this.props.onLetterPress && this.props.onLetterPress(index,sectionID);
|
52
|
+
|
|
|
53
|
+ onLayout(name,e) {
|
|
|
54
|
+ let {y} = e.nativeEvent.layout;
|
|
|
55
|
+ let Y = {'name':name,'y':y}
|
|
|
56
|
+ let list = this.state.list;
|
|
|
57
|
+ list.push(Y);
|
|
|
58
|
+ this.setState(list)
|
44
|
}
|
59
|
}
|
45
|
|
60
|
|
46
|
render() {
|
61
|
render() {
|
|
@@ -58,7 +73,9 @@ export default class IndexListView extends React.Component { |
|
@@ -58,7 +73,9 @@ export default class IndexListView extends React.Component { |
58
|
if (name == '0-9') {
|
73
|
if (name == '0-9') {
|
59
|
name = '0';
|
74
|
name = '0';
|
60
|
}
|
75
|
}
|
61
|
- keyData.push(<Text key={i} style={styles.text}>{name}</Text>);
|
76
|
+
|
|
|
77
|
+
|
|
|
78
|
+ keyData.push(<View key={i} style={styles.TV} onLayout={this.onLayout.bind(this, name)}><Text style={styles.text}>{name}</Text></View>);
|
62
|
}
|
79
|
}
|
63
|
|
80
|
|
64
|
return (
|
81
|
return (
|
|
@@ -71,7 +88,7 @@ export default class IndexListView extends React.Component { |
|
@@ -71,7 +88,7 @@ export default class IndexListView extends React.Component { |
71
|
|
88
|
|
72
|
let {width, height} = Dimensions.get('window');
|
89
|
let {width, height} = Dimensions.get('window');
|
73
|
let itemHeight = 12;
|
90
|
let itemHeight = 12;
|
74
|
-let viewHeight = height - 112;
|
91
|
+let viewHeight = height - 64;
|
75
|
|
92
|
|
76
|
let styles = StyleSheet.create({
|
93
|
let styles = StyleSheet.create({
|
77
|
container: {
|
94
|
container: {
|
|
@@ -80,17 +97,24 @@ let styles = StyleSheet.create({ |
|
@@ -80,17 +97,24 @@ let styles = StyleSheet.create({ |
80
|
height: viewHeight,
|
97
|
height: viewHeight,
|
81
|
bottom : 1,
|
98
|
bottom : 1,
|
82
|
right: 1,
|
99
|
right: 1,
|
83
|
- backgroundColor: 'rgba(255,255,255,0.2)',
|
100
|
+ backgroundColor: 'red',
|
84
|
alignItems: 'center',
|
101
|
alignItems: 'center',
|
85
|
justifyContent: 'center',
|
102
|
justifyContent: 'center',
|
86
|
},
|
103
|
},
|
|
|
104
|
+ TV: {
|
|
|
105
|
+ width: 12,
|
|
|
106
|
+ height: 12,
|
|
|
107
|
+ backgroundColor: 'transparent',
|
|
|
108
|
+ marginTop: 2,
|
|
|
109
|
+ justifyContent: 'center',
|
|
|
110
|
+ },
|
87
|
text: {
|
111
|
text: {
|
88
|
justifyContent: 'center',
|
112
|
justifyContent: 'center',
|
89
|
textAlign: 'center',
|
113
|
textAlign: 'center',
|
90
|
fontSize: 11,
|
114
|
fontSize: 11,
|
91
|
color: 'black',
|
115
|
color: 'black',
|
92
|
backgroundColor: 'transparent',
|
116
|
backgroundColor: 'transparent',
|
93
|
- marginTop: 2,
|
117
|
+
|
94
|
fontWeight: 'bold',
|
118
|
fontWeight: 'bold',
|
95
|
},
|
119
|
},
|
96
|
image: {
|
120
|
image: {
|