Authored by 孙凯

修改 品牌列表页 快速选择不准的bug review by hongmo

@@ -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,10 +36,25 @@ export default class IndexListView extends React.Component { @@ -31,10 +36,25 @@ 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;  
35 - var index = Math.ceil(Y/(itemHeight+2))-1;  
36 - let sectionID = dataSource[index];  
37 - this.props.onLetterPress && this.props.onLetterPress(index,sectionID); 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 + this.props.onLetterPress && this.props.onLetterPress(i,name);
  47 + break;
  48 + }
  49 + }
  50 + }
  51 +
  52 + onLayout(name,e) {
  53 + let {y} = e.nativeEvent.layout;
  54 + let Y = {'name':name,'y':y}
  55 + let list = this.state.list;
  56 + list.push(Y);
  57 + this.setState(list)
38 } 58 }
39 59
40 render() { 60 render() {
@@ -52,7 +72,9 @@ export default class IndexListView extends React.Component { @@ -52,7 +72,9 @@ export default class IndexListView extends React.Component {
52 if (name == '0-9') { 72 if (name == '0-9') {
53 name = '0'; 73 name = '0';
54 } 74 }
55 - keyData.push(<Text key={i} style={styles.text}>{name}</Text>); 75 +
  76 +
  77 + keyData.push(<View key={i} style={styles.TV} onLayout={this.onLayout.bind(this, name)}><Text style={styles.text}>{name}</Text></View>);
56 } 78 }
57 79
58 return ( 80 return (
@@ -78,13 +100,20 @@ let styles = StyleSheet.create({ @@ -78,13 +100,20 @@ let styles = StyleSheet.create({
78 alignItems: 'center', 100 alignItems: 'center',
79 justifyContent: 'center', 101 justifyContent: 'center',
80 }, 102 },
  103 + TV: {
  104 + width: 12,
  105 + height: 12,
  106 + backgroundColor: 'transparent',
  107 + marginTop: 2,
  108 + justifyContent: 'center',
  109 + },
81 text: { 110 text: {
82 justifyContent: 'center', 111 justifyContent: 'center',
83 textAlign: 'center', 112 textAlign: 'center',
84 fontSize: 11, 113 fontSize: 11,
85 color: 'black', 114 color: 'black',
86 backgroundColor: 'transparent', 115 backgroundColor: 'transparent',
87 - marginTop: 2, 116 +
88 fontWeight: 'bold', 117 fontWeight: 'bold',
89 }, 118 },
90 image: { 119 image: {
@@ -158,19 +158,27 @@ export default function redBrandReducer(state=initialState, action) { @@ -158,19 +158,27 @@ export default function redBrandReducer(state=initialState, action) {
158 case ADD_FAVORITE_SUCCESS: { 158 case ADD_FAVORITE_SUCCESS: {
159 if (action.payload) { 159 if (action.payload) {
160 return state.setIn(['shopIntro', 'is_addFav'], true) 160 return state.setIn(['shopIntro', 'is_addFav'], true)
  161 + .setIn(['receiveCouponResult', 'showMessage'], '收藏成功')
  162 + .setIn(['receiveCouponResult', 'isNeedShow'], true);
161 // .setIn(['shopIntro', 'favoriteCount'],parseInt(state.shopIntro.favoriteCount) +1); 163 // .setIn(['shopIntro', 'favoriteCount'],parseInt(state.shopIntro.favoriteCount) +1);
162 }else { 164 }else {
163 - return state.setIn(['shopIntro', 'is_addFav'], true); 165 + return state.setIn(['shopIntro', 'is_addFav'], true)
164 } 166 }
165 } 167 }
166 case ADD_FAVORITE_FAILURE: { 168 case ADD_FAVORITE_FAILURE: {
167 if (action.payload.code == 413) { 169 if (action.payload.code == 413) {
168 - return state.setIn(['shopIntro', 'is_addFav'], true); 170 + return state.setIn(['shopIntro', 'is_addFav'], true)
  171 + .setIn(['receiveCouponResult', 'showMessage'], '已收藏')
  172 + .setIn(['receiveCouponResult', 'isNeedShow'], true);
169 } 173 }
170 - return state.setIn(['shopIntro', 'is_addFav'], false); 174 + return state.setIn(['shopIntro', 'is_addFav'], false)
  175 + .setIn(['receiveCouponResult', 'showMessage'], '收藏失败')
  176 + .setIn(['receiveCouponResult', 'isNeedShow'], true);
171 } 177 }
172 case CANCEL_FAVORITE_SUCCESS: { 178 case CANCEL_FAVORITE_SUCCESS: {
173 return state.setIn(['shopIntro', 'is_addFav'], action.payload) 179 return state.setIn(['shopIntro', 'is_addFav'], action.payload)
  180 + .setIn(['receiveCouponResult', 'showMessage'], '取消收藏成功')
  181 + .setIn(['receiveCouponResult', 'isNeedShow'], true);
174 // .setIn(['shopIntro', 'favoriteCount'],(parseInt(state.shopIntro.favoriteCount) -1)>0?(parseInt(state.shopIntro.favoriteCount) -1):0); 182 // .setIn(['shopIntro', 'favoriteCount'],(parseInt(state.shopIntro.favoriteCount) -1)>0?(parseInt(state.shopIntro.favoriteCount) -1):0);
175 } 183 }
176 case GET_FAVORITE_COUNT_SUCCESS: { 184 case GET_FAVORITE_COUNT_SUCCESS: {