Authored by LakeR

修复bug: 自动滑动至选中位置 review by chenlin

1 'use strict'; 1 'use strict';
2 2
3 -import React, {Component} from 'react';  
4 -import ReactNative, {  
5 - View,  
6 - Text,  
7 - Image,  
8 - ListView,  
9 - StyleSheet,  
10 - Dimensions,  
11 - TouchableOpacity,  
12 -} from 'react-native';  
13 -import Immutable, {Map} from 'immutable';  
14 -import TimeForFocus from './TimeForFocus';  
15 -import TimeForLostFocus from './TimeForLostFocus'; 3 +import React, {Component} from "react";
  4 +import {View, Text, Image, ListView, StyleSheet, Dimensions, TouchableOpacity} from "react-native";
  5 +import Immutable from "immutable";
  6 +import TimeForFocus from "./TimeForFocus";
  7 +import TimeForLostFocus from "./TimeForLostFocus";
16 8
17 let diff; 9 let diff;
18 10
@@ -46,9 +38,10 @@ export default class SeckillTimeListView extends Component { @@ -46,9 +38,10 @@ export default class SeckillTimeListView extends Component {
46 //focus 38 //focus
47 if (this.secKillProductVoList.length >= 1) { 39 if (this.secKillProductVoList.length >= 1) {
48 let listLength = this.secKillProductVoList.length; 40 let listLength = this.secKillProductVoList.length;
49 - let scrollX = 0; 41 + let scrollX;
  42 + let currentScrollX = this.listView ? this.listView.scrollProperties.offset : 0;
50 scrollX = (this.curFocusActivity.get('index') - 1) * (rowContainerWidth + separatorWidth); 43 scrollX = (this.curFocusActivity.get('index') - 1) * (rowContainerWidth + separatorWidth);
51 - if (this.scrollX == scrollX) { 44 + if (this.scrollX == scrollX && ((Math.floor(scrollX) == Math.floor(currentScrollX)) || scrollX != 0)) {
52 return; 45 return;
53 } 46 }
54 this.scrollX = scrollX; 47 this.scrollX = scrollX;
@@ -56,15 +49,16 @@ export default class SeckillTimeListView extends Component { @@ -56,15 +49,16 @@ export default class SeckillTimeListView extends Component {
56 this.listView && this.listView.scrollTo({x: scrollX, y: 0, animated: true}); 49 this.listView && this.listView.scrollTo({x: scrollX, y: 0, animated: true});
57 } 50 }
58 } 51 }
  52 +
59 _searchRightNowStartActivity() { 53 _searchRightNowStartActivity() {
60 this.secKillProductVoList.forEach((activityItem, i) => { 54 this.secKillProductVoList.forEach((activityItem, i) => {
61 if (activityItem.has('wait')) { 55 if (activityItem.has('wait')) {
62 let nowTime = Date.parse(new Date()) / 1000 + diffTime; 56 let nowTime = Date.parse(new Date()) / 1000 + diffTime;
63 - let startTime = activityItem.get('startTime')/1000; 57 + let startTime = activityItem.get('startTime') / 1000;
64 let offsetTime = startTime - nowTime; 58 let offsetTime = startTime - nowTime;
65 if (offsetTime < 0) { 59 if (offsetTime < 0) {
66 activityItem.focus = true; 60 activityItem.focus = true;
67 - this.curFocusActivity= activityItem; 61 + this.curFocusActivity = activityItem;
68 this._scrollToFocusActivity(); 62 this._scrollToFocusActivity();
69 this.props.onFocusToCurStartedActivity && this.props.onFocusToCurStartedActivity(activityItem); 63 this.props.onFocusToCurStartedActivity && this.props.onFocusToCurStartedActivity(activityItem);
70 } 64 }