Skip to content

Commit

Permalink
fix(Sheet): fix incorrect content height calculation (#1700)
Browse files Browse the repository at this point in the history
  • Loading branch information
mournfulCoroner authored Jul 11, 2024
1 parent 0ae513a commit 7e4dd23
Showing 1 changed file with 13 additions and 13 deletions.
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

0 comments on commit 7e4dd23

Please sign in to comment.