Skip to content

Commit

Permalink
[improvement] extract resetScroll function (#3869)
Browse files Browse the repository at this point in the history
  • Loading branch information
chenjiahan authored Jul 16, 2019
1 parent cc445df commit e653484
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 17 deletions.
11 changes: 2 additions & 9 deletions src/field/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ import Icon from '../icon';
import Cell from '../cell';
import { cellProps } from '../cell/shared';
import { preventDefault } from '../utils/dom/event';
import { getRootScrollTop, setRootScrollTop } from '../utils/dom/scroll';
import { resetScroll } from '../utils/dom/reset-scroll';
import { createNamespace, isObj, isDef, addUnit } from '../utils';
import { isIOS } from '../utils/validate/system';

const [createComponent, bem] = createNamespace('field');

Expand Down Expand Up @@ -134,13 +133,7 @@ export default createComponent({
onBlur(event) {
this.focused = false;
this.$emit('blur', event);

// Hack for iOS12 page scroll
// https://developers.weixin.qq.com/community/develop/doc/00044ae90742f8c82fb78fcae56800
/* istanbul ignore next */
if (isIOS()) {
setRootScrollTop(getRootScrollTop());
}
resetScroll();
},

onClick(event) {
Expand Down
10 changes: 2 additions & 8 deletions src/stepper/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createNamespace, isDef, addUnit } from '../utils';
import { getRootScrollTop, setRootScrollTop } from '../utils/dom/scroll';
import { isIOS } from '../utils/validate/system';
import { resetScroll } from '../utils/dom/reset-scroll';

const [createComponent, bem] = createNamespace('stepper');

Expand Down Expand Up @@ -156,12 +155,7 @@ export default createComponent({
event.target.value = this.currentValue;
}

// Hack for iOS12 page scroll
// https://developers.weixin.qq.com/community/develop/doc/00044ae90742f8c82fb78fcae56800
/* istanbul ignore next */
if (isIOS()) {
setRootScrollTop(getRootScrollTop());
}
resetScroll();
},

longPressStep() {
Expand Down
16 changes: 16 additions & 0 deletions src/utils/dom/reset-scroll.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/**
* Hack for iOS12 page scroll
* https://developers.weixin.qq.com/community/develop/doc/00044ae90742f8c82fb78fcae56800
*/

import { isIOS as checkIsIOS } from '../validate/system';
import { getRootScrollTop, setRootScrollTop } from './scroll';

const isIOS = checkIsIOS();

/* istanbul ignore next */
export function resetScroll() {
if (isIOS) {
setRootScrollTop(getRootScrollTop());
}
}

0 comments on commit e653484

Please sign in to comment.