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(ModalPage): ограничить область контента с помощью bottom-inset #5715

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions packages/vkui/src/components/ModalPage/ModalPage.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,13 @@
height: 100%;
}

.ModalPage__content-in::after {
content: '';
/* существует для того, чтобы использовать в расчёте translateY
* чтобы поднять ModalPage не только на высоту контента, но и на высоту bottom-inset
* особенно важно для ModalPage c динамической высотой
*/
.ModalPage__bottom-inset {
height: var(--vkui_internal--safe_area_inset_bottom);
display: block;
flex-shrink: 0;
}

/**
Expand Down
1 change: 1 addition & 0 deletions packages/vkui/src/components/ModalPage/ModalPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ export const ModalPage = ({
>
<div className={styles['ModalPage__content-in']}>{children}</div>
</div>
<div ref={refs.bottomInset} className={styles['ModalPage__bottom-inset']} />
</div>
{isCloseButtonShown && <ModalDismissButton onClick={onClose || modalContext.onClose} />}
</div>
Expand Down
7 changes: 4 additions & 3 deletions packages/vkui/src/components/ModalRoot/ModalRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -642,9 +642,10 @@ function initModal(modalState: ModalsStateEntry) {
}

function initPageModal(modalState: ModalsStateEntry) {
const { contentElement } = modalState;
const contentHeight = (contentElement?.firstElementChild as HTMLElement).offsetHeight;

const { contentElement, bottomInset } = modalState;
const contentElementHeight = (contentElement?.firstElementChild as HTMLElement).offsetHeight;
const bottomInsetHeight = bottomInset?.offsetHeight || 0;
const contentHeight = contentElementHeight + bottomInsetHeight;
let prevTranslateY = modalState.translateY;

modalState.expandable =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export function useModalRegistry(id: string | undefined, type: ModalType) {
innerElement: (e) => (elements.innerElement = e),
headerElement: (e) => (elements.headerElement = e),
contentElement: (e) => (elements.contentElement = e),
bottomInset: (e) => (elements.bottomInset = e),
}).current;
return { refs };
}
1 change: 1 addition & 0 deletions packages/vkui/src/components/ModalRoot/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface ModalElements {
innerElement?: HTMLElement | null;
headerElement?: HTMLElement | null;
contentElement?: HTMLElement | null;
bottomInset?: HTMLElement | null;
}

export interface ModalsStateEntry extends ModalElements {
Expand Down