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

patch(v5): pr6538 #6573

Merged
merged 1 commit into from
Feb 15, 2024
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
31 changes: 27 additions & 4 deletions packages/vkui/src/components/ModalRoot/ModalRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -662,15 +662,16 @@ function initModal(modalState: ModalsStateEntry) {

function initPageModal(modalState: ModalsStateEntry) {
const { contentElement, bottomInset } = modalState;
const contentElementHeight = (contentElement?.firstElementChild as HTMLElement).scrollHeight;
const contentElementHeight = calculateModalContentHeight(
contentElement?.firstElementChild as HTMLElement,
modalState.expandable,
);
const bottomInsetHeight = bottomInset?.offsetHeight || 0;
const contentHeight = contentElementHeight + bottomInsetHeight;
let prevTranslateY = modalState.translateY;

modalState.expandable =
contentHeight > (contentElement?.clientHeight ?? 0) ||
modalState.settlingHeight === 100 ||
modalState.expanded;
contentHeight > (contentElement?.clientHeight ?? 0) || modalState.settlingHeight === 100;

let collapsed = false;
let expanded = false;
Expand Down Expand Up @@ -733,3 +734,25 @@ function initPageModal(modalState: ModalsStateEntry) {
function initCardModal(modalState: ModalsStateEntry) {
modalState.translateY = 0;
}

function calculateModalContentHeight(
element: HTMLElement,
isExpandable: ModalsStateEntry['expandable'],
) {
if (!isExpandable) {
return element.scrollHeight;
}

/*
* В режиме expandable мы назначаем контейнеру контента высоту 100%, что не даёт
* получить реальную высоту контента.
* Поэтому мы пересчитываем высоту, временно устанавливая height: auto;
* */
const currentHeightStyle = element.style.height;
element.style.height = 'auto';

const elementHeight = element.scrollHeight;
element.style.height = currentHeightStyle;

return elementHeight;
}
Loading