Authored by 孙凯

添加 indexListView 逻辑 review by 张丽霞

@@ -23,6 +23,7 @@ import NewHotBannerListCell from './NewHotBannerListCell'; @@ -23,6 +23,7 @@ import NewHotBannerListCell from './NewHotBannerListCell';
23 import BrandSearch from './search/BrandSearch'; 23 import BrandSearch from './search/BrandSearch';
24 import LoadingIndicator from '../../../common/components/LoadingIndicator'; 24 import LoadingIndicator from '../../../common/components/LoadingIndicator';
25 import IndexListView from './IndexListView'; 25 import IndexListView from './IndexListView';
  26 +import {ScrollToIndex} from '../../utils/Utils';
26 27
27 export default class Brand extends Component { 28 export default class Brand extends Component {
28 constructor(props) { 29 constructor(props) {
@@ -31,7 +32,8 @@ export default class Brand extends Component { @@ -31,7 +32,8 @@ export default class Brand extends Component {
31 this.renderSectionHeader = this.renderSectionHeader.bind(this); 32 this.renderSectionHeader = this.renderSectionHeader.bind(this);
32 this.renderRow = this.renderRow.bind(this); 33 this.renderRow = this.renderRow.bind(this);
33 this.renderHeader = this.renderHeader.bind(this); 34 this.renderHeader = this.renderHeader.bind(this);
34 - 35 + this.scrollToSection = this.scrollToSection.bind(this);
  36 + this.scrollData = [];
35 this.dataSource = new ListView.DataSource({ 37 this.dataSource = new ListView.DataSource({
36 rowHasChanged: (r1, r2) => !Immutable.is(r1, r2), 38 rowHasChanged: (r1, r2) => !Immutable.is(r1, r2),
37 sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2), 39 sectionHeaderHasChanged: (s1, s2) => !Immutable.is(s1, s2),
@@ -47,6 +49,11 @@ export default class Brand extends Component { @@ -47,6 +49,11 @@ export default class Brand extends Component {
47 49
48 } 50 }
49 51
  52 + scrollToSection(sessionID){
  53 + let newSrc = ScrollToIndex(sessionID,this.scrollData);
  54 + this.listView.scrollTo({x: 0, y:443+newSrc , animated: false});
  55 + }
  56 +
50 renderHeader(){ 57 renderHeader(){
51 let data = this.props.reourceForBoy; 58 let data = this.props.reourceForBoy;
52 let brandFliter = this.props.brandFliter; 59 let brandFliter = this.props.brandFliter;
@@ -146,12 +153,14 @@ export default class Brand extends Component { @@ -146,12 +153,14 @@ export default class Brand extends Component {
146 let listDataSource; 153 let listDataSource;
147 let contentContainerStyle; 154 let contentContainerStyle;
148 let renderSectionHeader = null; 155 let renderSectionHeader = null;
  156 + let showIndexForListView = false;
149 157
150 if (brandFliter == 0) { 158 if (brandFliter == 0) {
151 list = data?data.all_list:null; 159 list = data?data.all_list:null;
152 listDataSource = list?this.dataSource.cloneWithRowsAndSections(list):null; 160 listDataSource = list?this.dataSource.cloneWithRowsAndSections(list):null;
153 contentContainerStyle = styles.contentContainerOne; 161 contentContainerStyle = styles.contentContainerOne;
154 renderSectionHeader = this.renderSectionHeader; 162 renderSectionHeader = this.renderSectionHeader;
  163 + showIndexForListView = true;
155 } else if (brandFliter == 1) { 164 } else if (brandFliter == 1) {
156 list = data?data.new_list:null; 165 list = data?data.new_list:null;
157 listDataSource = list?this.dataSource.cloneWithRows(list):null; 166 listDataSource = list?this.dataSource.cloneWithRows(list):null;
@@ -165,12 +174,14 @@ export default class Brand extends Component { @@ -165,12 +174,14 @@ export default class Brand extends Component {
165 if (!list) { 174 if (!list) {
166 return null; 175 return null;
167 } 176 }
  177 + this.scrollData = list;
168 178
169 return ( 179 return (
170 <View style={styles.container}> 180 <View style={styles.container}>
171 <ChannelFliter selectID={channelFliter} onChannelPressFliter={this.props.onChannelPressFliter}/> 181 <ChannelFliter selectID={channelFliter} onChannelPressFliter={this.props.onChannelPressFliter}/>
172 182
173 <ListView 183 <ListView
  184 + ref={(ref)=>this.listView=ref}
174 contentContainerStyle={contentContainerStyle} 185 contentContainerStyle={contentContainerStyle}
175 enableEmptySections={true} 186 enableEmptySections={true}
176 dataSource={listDataSource} 187 dataSource={listDataSource}
@@ -180,6 +191,8 @@ export default class Brand extends Component { @@ -180,6 +191,8 @@ export default class Brand extends Component {
180 /> 191 />
181 192
182 <IndexListView dataSource={list}/> 193 <IndexListView dataSource={list}/>
  194 + {showIndexForListView?<IndexListView dataSource={list} onLetterPress={this.scrollToSection}/>: null}
  195 + {showSearch ? <BrandSearch style={styles.search} data={search}/> : null}
183 196
184 <LoadingIndicator 197 <LoadingIndicator
185 isVisible={isFetching} 198 isVisible={isFetching}
@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 import React from 'react'; 3 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 7
7 const { 8 const {
8 View, 9 View,
@@ -17,8 +18,30 @@ export default class IndexListView extends React.Component { @@ -17,8 +18,30 @@ export default class IndexListView extends React.Component {
17 18
18 constructor(props) { 19 constructor(props) {
19 super (props); 20 super (props);
  21 + this.onTouchMove = this.onTouchMove.bind(this);
20 } 22 }
21 23
  24 + onTouchMove(e) {
  25 + let {dataSource} = this.props;
  26 + let data = Immutable.fromJS(dataSource)
  27 + let Y = e.nativeEvent.pageY - Math.ceil((viewHeight - data.size * (itemHeight+2))/2);
  28 + var index = Math.ceil(Y/(itemHeight+2));
  29 +
  30 + let i = 0;
  31 + let sessionID = [];
  32 + for(var k in dataSource) {
  33 + let name = k;
  34 + i++;
  35 + if (i == index) {
  36 + sessionID = name;
  37 + break;
  38 + }
  39 + }
  40 +
  41 + this.props.onLetterPress && this.props.onLetterPress(sessionID);
  42 + }
  43 +
  44 +
22 render() { 45 render() {
23 46
24 let {dataSource} = this.props; 47 let {dataSource} = this.props;
@@ -39,7 +62,7 @@ export default class IndexListView extends React.Component { @@ -39,7 +62,7 @@ export default class IndexListView extends React.Component {
39 } 62 }
40 63
41 return ( 64 return (
42 - <View style={styles.container}> 65 + <View style={styles.container} onTouchStart={this.onTouchMove} onTouchMove={this.onTouchMove} >
43 {keyData.map((elem, index) => {return elem;})} 66 {keyData.map((elem, index) => {return elem;})}
44 </View> 67 </View>
45 ); 68 );
@@ -47,11 +70,14 @@ export default class IndexListView extends React.Component { @@ -47,11 +70,14 @@ export default class IndexListView extends React.Component {
47 } 70 }
48 71
49 let {width, height} = Dimensions.get('window'); 72 let {width, height} = Dimensions.get('window');
  73 +let itemHeight = 12;
  74 +let viewHeight = height - 112;
  75 +
50 let styles = StyleSheet.create({ 76 let styles = StyleSheet.create({
51 container: { 77 container: {
52 position: 'absolute', 78 position: 'absolute',
53 width: 10, 79 width: 10,
54 - top: 35, 80 + height: viewHeight,
55 bottom : 1, 81 bottom : 1,
56 right: 1, 82 right: 1,
57 backgroundColor: 'rgba(255,255,255,0.2)', 83 backgroundColor: 'rgba(255,255,255,0.2)',
@@ -28,3 +28,16 @@ export function isEmptyObject(obj) { @@ -28,3 +28,16 @@ export function isEmptyObject(obj) {
28 } 28 }
29 return true; 29 return true;
30 } 30 }
  31 +
  32 +export function ScrollToIndex(sessionID,list) {
  33 +
  34 + let index = 0;
  35 + for(var k in list) {
  36 + let name = k;
  37 + if (name == sessionID) {
  38 + break;
  39 + }
  40 + index += 20 + list[k].length * 44;
  41 + }
  42 + return index;
  43 +}