Skip to content

Commit 1e1596f

Browse files
authored
fix(refresher): refresher now only activates when pulling down on MD (#23283)
resolves #23245
1 parent f36eabc commit 1e1596f

File tree

2 files changed

+29
-10
lines changed

2 files changed

+29
-10
lines changed

core/src/components/refresher/refresher.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,6 @@ export class Refresher implements ComponentInterface {
307307
canStart: () => this.state !== RefresherState.Refreshing && this.state !== RefresherState.Completing && this.scrollEl!.scrollTop === 0,
308308
onStart: (ev: GestureDetail) => {
309309
ev.data = { animation: undefined, didStart: false, cancelled: false };
310-
this.state = RefresherState.Pulling;
311310
},
312311
onMove: (ev: GestureDetail) => {
313312
if ((ev.velocityY < 0 && this.progress === 0 && !ev.data.didStart) || ev.data.cancelled) {
@@ -318,10 +317,12 @@ export class Refresher implements ComponentInterface {
318317
if (!ev.data.didStart) {
319318
ev.data.didStart = true;
320319

320+
this.state = RefresherState.Pulling;
321+
321322
writeTask(() => this.scrollEl!.style.setProperty('--overflow', 'hidden'));
322323

323324
const animationType = getRefresherAnimationType(contentEl);
324-
const animation = createPullingAnimation(animationType, pullingRefresherIcon);
325+
const animation = createPullingAnimation(animationType, pullingRefresherIcon, this.el);
325326
ev.data.animation = animation;
326327
animation.progressStart(false, 0);
327328
this.ionStart.emit();

core/src/components/refresher/refresher.utils.ts

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ export const getRefresherAnimationType = (contentEl: HTMLIonContentElement): Ref
1515
return hasHeader ? 'translate' : 'scale';
1616
};
1717

18-
export const createPullingAnimation = (type: RefresherAnimationType, pullingSpinner: HTMLElement) => {
19-
return type === 'scale' ? createScaleAnimation(pullingSpinner) : createTranslateAnimation(pullingSpinner);
18+
export const createPullingAnimation = (type: RefresherAnimationType, pullingSpinner: HTMLElement, refresherEl: HTMLElement) => {
19+
return type === 'scale' ? createScaleAnimation(pullingSpinner, refresherEl) : createTranslateAnimation(pullingSpinner, refresherEl);
2020
};
2121

2222
const createBaseAnimation = (pullingRefresherIcon: HTMLElement) => {
@@ -85,24 +85,42 @@ const createBaseAnimation = (pullingRefresherIcon: HTMLElement) => {
8585
return baseAnimation.addAnimation([spinnerArrowContainerAnimation, circleInnerAnimation, circleOuterAnimation]);
8686
};
8787

88-
const createScaleAnimation = (pullingRefresherIcon: HTMLElement) => {
89-
const height = pullingRefresherIcon.clientHeight;
88+
const createScaleAnimation = (pullingRefresherIcon: HTMLElement, refresherEl: HTMLElement) => {
89+
/**
90+
* Do not take the height of the refresher icon
91+
* because at this point the DOM has not updated,
92+
* so the refresher icon is still hidden with
93+
* display: none.
94+
* The `ion-refresher` container height
95+
* is roughly the amount we need to offset
96+
* the icon by when pulling down.
97+
*/
98+
const height = refresherEl.clientHeight;
9099
const spinnerAnimation = createAnimation()
91100
.addElement(pullingRefresherIcon)
92101
.keyframes([
93-
{ offset: 0, transform: `scale(0) translateY(-${height + 20}px)` },
102+
{ offset: 0, transform: `scale(0) translateY(-${height}px)` },
94103
{ offset: 1, transform: 'scale(1) translateY(100px)' }
95104
]);
96105

97106
return createBaseAnimation(pullingRefresherIcon).addAnimation([spinnerAnimation]);
98107
};
99108

100-
const createTranslateAnimation = (pullingRefresherIcon: HTMLElement) => {
101-
const height = pullingRefresherIcon.clientHeight;
109+
const createTranslateAnimation = (pullingRefresherIcon: HTMLElement, refresherEl: HTMLElement) => {
110+
/**
111+
* Do not take the height of the refresher icon
112+
* because at this point the DOM has not updated,
113+
* so the refresher icon is still hidden with
114+
* display: none.
115+
* The `ion-refresher` container height
116+
* is roughly the amount we need to offset
117+
* the icon by when pulling down.
118+
*/
119+
const height = refresherEl.clientHeight;
102120
const spinnerAnimation = createAnimation()
103121
.addElement(pullingRefresherIcon)
104122
.keyframes([
105-
{ offset: 0, transform: `translateY(-${height + 20}px)` },
123+
{ offset: 0, transform: `translateY(-${height}px)` },
106124
{ offset: 1, transform: 'translateY(100px)' }
107125
]);
108126

0 commit comments

Comments
 (0)