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(Sheet): fix incorrect content height calculation #1700

Merged
merged 1 commit into from
Jul 11, 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
26 changes: 13 additions & 13 deletions src/components/Sheet/SheetContent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class SheetContent extends React.Component<SheetContentInnerProps, SheetContentS
this.addListeners();
this.show();

const initialHeight = this.getResultHeight(this.sheetFullHeight);
const initialHeight = this.getAvailableContentHeight(this.sheetContentHeight);

this.setInitialStyles(initialHeight);
this.setState({
Expand Down Expand Up @@ -221,8 +221,8 @@ class SheetContent extends React.Component<SheetContentInnerProps, SheetContentS
return this.sheetContentRef.current?.scrollTop || 0;
}

private get sheetFullHeight() {
return this.sheetTitleHeight + this.innerContentHeight + this.sheetTopHeight;
private get sheetContentHeight() {
return this.sheetTitleHeight + this.innerContentHeight;
}

private setInitialStyles(initialHeight: number) {
Expand Down Expand Up @@ -252,14 +252,14 @@ class SheetContent extends React.Component<SheetContentInnerProps, SheetContentS
this.sheetRef.current.style.transform = translate;
};

private getResultHeight = (sheetHeight: number) => {
private getAvailableContentHeight = (sheetHeight: number) => {
const availableViewportHeight =
window.innerHeight * MAX_CONTENT_HEIGHT_FROM_VIEWPORT_COEFFICIENT - this.sheetTopHeight;

const resultHeight =
const availableContentHeight =
sheetHeight >= availableViewportHeight ? availableViewportHeight : sheetHeight;

return resultHeight;
return availableContentHeight;
};

private show = () => {
Expand Down Expand Up @@ -435,22 +435,22 @@ class SheetContent extends React.Component<SheetContentInnerProps, SheetContentS
return;
}

const sheetHeight = this.sheetFullHeight;
const sheetContentHeight = this.sheetContentHeight;

if (sheetHeight === this.state.prevSheetHeight && !this.state.inWindowResizeScope) {
if (sheetContentHeight === this.state.prevSheetHeight && !this.state.inWindowResizeScope) {
return;
}

const resultHeight = this.getResultHeight(sheetHeight);
const availableContentHeight = this.getAvailableContentHeight(sheetContentHeight);

this.sheetContentRef.current.style.transition =
this.state.prevSheetHeight > sheetHeight
this.state.prevSheetHeight > sheetContentHeight
? `height 0s ease ${TRANSITION_DURATION}`
: 'none';

this.sheetContentRef.current.style.height = `${resultHeight - this.sheetTopHeight}px`;
this.sheetRef.current.style.transform = `translate3d(0, -${resultHeight}px, 0)`;
this.setState({prevSheetHeight: sheetHeight, inWindowResizeScope: false});
this.sheetContentRef.current.style.height = `${availableContentHeight}px`;
this.sheetRef.current.style.transform = `translate3d(0, -${availableContentHeight + this.sheetTopHeight}px, 0)`;
this.setState({prevSheetHeight: sheetContentHeight, inWindowResizeScope: false});
};

private addListeners() {
Expand Down
Loading