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

Revert "fix(ModalRoot): Исправляет скролл при touch-событиях" #3416

Merged
merged 1 commit into from
Oct 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions src/components/ModalRoot/ModalRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ class ModalRootTouchComponent extends React.Component<
this.frameIds = {};
}

private documentScrolling = false;
private readonly maskElementRef: React.RefObject<HTMLDivElement>;
private readonly viewportRef = React.createRef<HTMLDivElement>();
private maskAnimationFrame: number | undefined = undefined;
Expand Down Expand Up @@ -143,6 +144,7 @@ class ModalRootTouchComponent extends React.Component<
}

componentWillUnmount() {
this.toggleDocumentScrolling(true);
this.window!.removeEventListener(
"resize",
this.updateModalTranslate,
Expand Down Expand Up @@ -194,8 +196,47 @@ class ModalRootTouchComponent extends React.Component<
this.restoreFocusTo.focus();
this.restoreFocusTo = null;
}

this.toggleDocumentScrolling(
!this.props.activeModal && !this.props.exitingModal
);
}

/* Отключает скролл документа */
toggleDocumentScrolling(enabled: boolean) {
if (this.documentScrolling === enabled) {
return;
}
this.documentScrolling = enabled;

if (enabled) {
// Здесь нужен последний аргумент с такими же параметрами, потому что
// некоторые браузеры на странных вендорах типа Meizu не удаляют обработчик.
// https://github.com/VKCOM/VKUI/issues/444
this.window!.removeEventListener("touchmove", this.preventTouch, {
// @ts-ignore (В интерфейсе EventListenerOptions нет поля passive)
passive: false,
});
} else {
this.window!.addEventListener("touchmove", this.preventTouch, {
passive: false,
});
}
}

preventTouch = (event: any) => {
if (!event) {
return false;
}
while (event.originalEvent) {
event = event.originalEvent;
}
if (event.preventDefault) {
event.preventDefault();
}
return false;
};

updateModalTranslate = () => {
const modalState = this.getModalState(this.props.activeModal);
modalState && this.animateTranslate(modalState, modalState.translateY);
Expand Down