Skip to content

Commit

Permalink
Merge pull request lanjingling0510#45 from Asgator/bugfix-empty-ref-s…
Browse files Browse the repository at this point in the history
…croll

Fix empty ref scroll
  • Loading branch information
lanjingling0510 authored Jul 23, 2019
2 parents f66ca96 + 2ff462b commit 279fb4b
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/DatePickerItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class DatePickerItem extends Component<void, Props, State> {
this.translateY = 0; // 容器偏移的距离
this.currentIndex = MIDDLE_INDEX; // 滑动中当前日期的索引
this.moveDateCount = 0; // 一次滑动移动了多少个时间
this._moveToTimer = null;

this.state = {
translateY: MIDDLE_Y,
Expand Down Expand Up @@ -97,6 +98,8 @@ class DatePickerItem extends Component<void, Props, State> {
viewport.removeEventListener('touchmove', this.handleContentTouch, false);
viewport.removeEventListener('touchend', this.handleContentTouch, false);
viewport.removeEventListener('mousedown', this.handleContentMouseDown, false);

clearTimeout(this._moveToTimer);
}

_iniDates(date) {
Expand Down Expand Up @@ -160,26 +163,25 @@ class DatePickerItem extends Component<void, Props, State> {
this._updateDates(-1);
}

this._moveTo(this.refs.scroll, this.currentIndex);
this._moveTo(this.currentIndex);
}

/**
* 添加滑动动画
* @param {DOM} obj DOM对象
* @param {number} angle 角度
* @return {undefined}
*/
_moveTo(obj, currentIndex) {
_moveTo(currentIndex) {
this.animating = true;

addPrefixCss(obj, { transition: 'transform .2s ease-out' });
addPrefixCss(this.refs.scroll, { transition: 'transform .2s ease-out' });

this.setState({
translateY: -currentIndex * DATE_HEIGHT,
});

// NOTE: There is no transitionend, setTimeout is used instead.
setTimeout(() => {
this._moveToTimer = setTimeout(() => {
this.animating = false;
this.props.onSelect(this.state.dates[MIDDLE_INDEX]);
this._clearTransition(this.refs.scroll);
Expand Down

0 comments on commit 279fb4b

Please sign in to comment.