...
|
...
|
@@ -20,6 +20,7 @@ export default class SeckillTimeListView extends Component { |
|
|
super(props);
|
|
|
this._renderRow = this._renderRow.bind(this);
|
|
|
this._renderSeparator = this._renderSeparator.bind(this);
|
|
|
this._scrollToFocusActivity = this._scrollToFocusActivity.bind(this);
|
|
|
|
|
|
this.dataSource = new ListView.DataSource({
|
|
|
rowHasChanged: (r1, r2) => r1.key != r2.key,
|
...
|
...
|
@@ -35,11 +36,43 @@ export default class SeckillTimeListView extends Component { |
|
|
};
|
|
|
}
|
|
|
|
|
|
_scrollToFocusActivity = () => {
|
|
|
//focus
|
|
|
if (this.secKillProductVoList.length >= 1) {
|
|
|
let listLength = this.secKillProductVoList.length;
|
|
|
let curFocusIndex = 0;
|
|
|
let scrollX = 0;
|
|
|
this.secKillProductVoList.forEach((activityItem, i) => {
|
|
|
if (activityItem.get('activityId') === this.curFocusActivity.get('activityId')) {
|
|
|
curFocusIndex = i;
|
|
|
}
|
|
|
});
|
|
|
// if (curFocusIndex > 1 && curFocusIndex < listLength-2) {
|
|
|
scrollX = (curFocusIndex - 1) * rowContainerWidth;
|
|
|
this.listView && this.listView.scrollTo({x: scrollX, y: 0, animated: false});
|
|
|
|
|
|
// }
|
|
|
}
|
|
|
}
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
|
let jumpToTimeoutActivity = () => {
|
|
|
this.secKillProductVoList.forEach((activityItem, i) => {
|
|
|
let nowTime = Date.parse(new Date()) / 1000 + diffTime;
|
|
|
let startTime = activityItem.get('startTime') / 1000;
|
|
|
let offsetTime = nowTime - startTime;
|
|
|
if (activityItem.get('focus') == false && Math.abs(offsetTime) <= 2) {
|
|
|
this.props.onFocusToCurStartedActivity && this.props.onFocusToCurStartedActivity(activityItem.toJS());
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
this.timer = setInterval(function () {
|
|
|
if (!this.curFocusActivity && this.curFocusActivity.size > 0 && !this.curFocusActivity.has('over')) {
|
|
|
return;
|
|
|
}
|
|
|
jumpToTimeoutActivity();
|
|
|
let nowTime = Date.parse(new Date()) / 1000 + diffTime;
|
|
|
let time = this.curFocusActivity.has('now') ? this.curFocusActivity.get('endTime'): this.curFocusActivity.get('startTime') / 1000;
|
|
|
let offsetTime = time - nowTime;
|
...
|
...
|
@@ -48,13 +81,15 @@ export default class SeckillTimeListView extends Component { |
|
|
let second = offsetTime % 60;
|
|
|
|
|
|
if (offsetTime <= 0) {
|
|
|
if (!this.state.tickTimeOut) {
|
|
|
this.props.onFocusToCurStartedActivity && this.props.onFocusToCurStartedActivity(this.curFocusActivity.toJS());
|
|
|
}
|
|
|
this.setState({
|
|
|
tickHour: '00',
|
|
|
tickMinute: '00',
|
|
|
tickSecond: '00',
|
|
|
tickTimeOut: true,
|
|
|
});
|
|
|
this.props.onPressTimeItem && this.props.onPressTimeItem(this.curFocusActivity.toJS());
|
|
|
} else {
|
|
|
this.setState({
|
|
|
tickHour: hour < 0 ? '00' : (hour < 10 ? ('0' + hour) : hour),
|
...
|
...
|
@@ -65,23 +100,7 @@ export default class SeckillTimeListView extends Component { |
|
|
}
|
|
|
|
|
|
}.bind(this), 1000);
|
|
|
|
|
|
//focus
|
|
|
if (this.secKillProductVoList.length >= 1) {
|
|
|
let listLength = this.secKillProductVoList.length;
|
|
|
let curFocusIndex = 0;
|
|
|
let scrollX = 0;
|
|
|
this.secKillProductVoList.forEach((activityItem, i) => {
|
|
|
if (activityItem.get('activityId') === this.curFocusActivity.get('activityId')) {
|
|
|
curFocusIndex = i;
|
|
|
}
|
|
|
});
|
|
|
if (curFocusIndex > 1 && curFocusIndex < listLength-2) {
|
|
|
scrollX = (curFocusIndex - 1) * rowContainerWidth;
|
|
|
this.listView.scrollTo({x: scrollX, y: 0, animated: false});
|
|
|
|
|
|
}
|
|
|
}
|
|
|
this._scrollToFocusActivity();
|
|
|
|
|
|
}
|
|
|
|
...
|
...
|
@@ -89,6 +108,15 @@ export default class SeckillTimeListView extends Component { |
|
|
this.timer && clearInterval(this.timer);
|
|
|
}
|
|
|
|
|
|
componentWillReceiveProps(nextProps) {
|
|
|
if (nextProps.resource && nextProps.resource.length > 0) {
|
|
|
let focusActivity = nextProps.resource.find(activityTimeItem => activityTimeItem.get('focus'));
|
|
|
this.curFocusActivity = focusActivity;
|
|
|
}
|
|
|
this._scrollToFocusActivity();
|
|
|
|
|
|
}
|
|
|
|
|
|
_renderRow(rowData, sectionID, rowID) {
|
|
|
rowData = rowData.toJS();
|
|
|
let colorStyle = rowData.focus ? {color: '#d30018'} : {color: '#3e3e3e'};
|
...
|
...
|
@@ -176,15 +204,19 @@ export default class SeckillTimeListView extends Component { |
|
|
}
|
|
|
diffTime = diff;
|
|
|
this.secKillProductVoList = resource;
|
|
|
backgroundWidth = Math.max(rowContainerWidth * (resource.length - 1) + rowContainerFocusWidth, width);
|
|
|
|
|
|
return (
|
|
|
<View style={[styles.container]}>
|
|
|
<ListView
|
|
|
contentContainerStyle={[styles.contentContainer]}
|
|
|
ref={(ref)=>this.listView=ref}
|
|
|
contentContainerStyle={[styles.contentContainer,{width:backgroundWidth}]}
|
|
|
enableEmptySections={true}
|
|
|
dataSource={this.dataSource.cloneWithRows(resource)}
|
|
|
renderSeparator={this._renderSeparator}
|
|
|
renderRow={this._renderRow}
|
|
|
scrollEnabled={false}
|
|
|
scrollEnabled={true}
|
|
|
horizontal={true}
|
|
|
scrollsToTop={false}
|
|
|
/>
|
|
|
</View>
|
...
|
...
|
@@ -202,7 +234,7 @@ let rowContainerFocusWidth = Math.ceil((294 * width) / 750); |
|
|
let styles = StyleSheet.create({
|
|
|
container: {
|
|
|
marginLeft: -1,
|
|
|
width: width + 2,
|
|
|
width: backgroundWidth + 2,
|
|
|
height: backgroundHeight,
|
|
|
borderTopColor: 'transparent',
|
|
|
borderBottomColor: '#e5e5e5',
|
...
|
...
|
|