Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(item-sliding): prevent scrolling during slide gesture #23774

Merged
merged 3 commits into from Aug 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/src/components/item-option/item-option.tsx
Expand Up @@ -104,7 +104,7 @@ export class ItemOption implements ComponentInterface, AnchorInterface, ButtonIn
[mode]: true,
'item-option-disabled': disabled,
'item-option-expandable': expandable,
'ion-activatable': true,
'ion-activatable': true
})}
>
<TagType
Expand Down
23 changes: 23 additions & 0 deletions core/src/components/item-sliding/item-sliding.tsx
Expand Up @@ -43,6 +43,8 @@ export class ItemSliding implements ComponentInterface {
private rightOptions?: HTMLIonItemOptionsElement;
private optsDirty = true;
private gesture?: Gesture;
private closestContent: HTMLIonContentElement | null = null;
private initialContentScrollY = true;

@Element() el!: HTMLIonItemSlidingElement;

Expand All @@ -66,6 +68,8 @@ export class ItemSliding implements ComponentInterface {

async connectedCallback() {
this.item = this.el.querySelector('ion-item');
this.closestContent = this.el.closest('ion-content');

await this.updateOptions();

this.gesture = (await import('../../utils/gesture')).createGesture({
Expand Down Expand Up @@ -252,7 +256,23 @@ export class ItemSliding implements ComponentInterface {
return !!(this.rightOptions || this.leftOptions);
}

private disableContentScrollY() {
if (this.closestContent === null) { return }

this.initialContentScrollY = this.closestContent.scrollY;
this.closestContent.scrollY = false;
}

private restoreContentScrollY() {
if (this.closestContent === null) { return }

this.closestContent.scrollY = this.initialContentScrollY;
}

private onStart() {
// Prevent scrolling during gesture
this.disableContentScrollY();

openSlidingItem = this.el;

if (this.tmr !== undefined) {
Expand Down Expand Up @@ -297,6 +317,9 @@ export class ItemSliding implements ComponentInterface {
}

private onEnd(gesture: GestureDetail) {
// Restore ion-content scrollY to initial value when gesture ends
this.restoreContentScrollY();

const velocity = gesture.velocityX;

let restingPoint = (this.openAmount > 0)
Expand Down