Skip to content

Commit eecb9a3

Browse files
kungurovsergeyNobleRaccoon
authored andcommitted
Add fill height mode for fixed-row canvas
1 parent 102f869 commit eecb9a3

4 files changed

Lines changed: 63 additions & 12 deletions

File tree

client/packages/lowcoder/src/comps/comps/appSettingsComp.tsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ const childrenMap = {
221221
gridRowCount: withDefault(NumberControl, DEFAULT_ROW_COUNT),
222222
gridPaddingX: withDefault(NumberControl, 0),
223223
gridPaddingY: withDefault(NumberControl, 0),
224+
gridStretchHeight: withDefault(BoolControl, false),
224225
gridBg: ColorControl,
225226
gridBgImage: StringControl,
226227
gridBgImageRepeat: StringControl,
@@ -355,6 +356,7 @@ function AppCanvasSettingsModal(props: ChildrenInstance) {
355356
gridColumns,
356357
gridRowHeight,
357358
gridRowCount,
359+
gridStretchHeight,
358360
gridPaddingX,
359361
gridPaddingY,
360362
gridBg,
@@ -478,6 +480,9 @@ function AppCanvasSettingsModal(props: ChildrenInstance) {
478480
label: trans("appSetting.gridRowCount"),
479481
placeholder: 'Infinity',
480482
})}
483+
{gridRowCount.getView() !== DEFAULT_ROW_COUNT && gridStretchHeight.propertyView({
484+
label: "Stretch canvas to available height",
485+
})}
481486
{gridPaddingX.propertyView({
482487
label: trans("appSetting.gridPaddingX"),
483488
placeholder: '0',
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { DEFAULT_ROW_COUNT } from "@lowcoder-ee/layout/calculateUtils";
2+
import {
3+
shouldShowStretchCanvasHeight,
4+
shouldStretchCanvasHeight,
5+
} from "./canvasView";
6+
7+
describe("canvas stretch height helpers", () => {
8+
it("shows stretch only for fixed row count", () => {
9+
expect(shouldShowStretchCanvasHeight(DEFAULT_ROW_COUNT)).toBe(false);
10+
expect(shouldShowStretchCanvasHeight(24)).toBe(true);
11+
});
12+
13+
it("enables stretch only in runtime for fixed row count", () => {
14+
expect(shouldStretchCanvasHeight(DEFAULT_ROW_COUNT, true, true)).toBe(false);
15+
expect(shouldStretchCanvasHeight(24, false, true)).toBe(false);
16+
expect(shouldStretchCanvasHeight(24, true, false)).toBe(false);
17+
expect(shouldStretchCanvasHeight(24, true, true)).toBe(true);
18+
});
19+
});

client/packages/lowcoder/src/comps/comps/gridLayoutComp/canvasView.tsx

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import { getBackgroundStyle } from "@lowcoder-ee/util/styleUtils";
2727
const UICompContainer = styled.div<{
2828
$maxWidth?: number;
2929
$rowCount?: number;
30+
$fillHeight?: boolean;
3031
readOnly?: boolean;
3132
$bgColor: string;
3233
$bgImage?: string;
@@ -35,8 +36,8 @@ const UICompContainer = styled.div<{
3536
$bgImageOrigin?: string;
3637
$bgImagePosition?: string;
3738
}>`
38-
height: auto;
39-
min-height: ${props => props.$rowCount === Infinity ? '100%' : 'auto'};
39+
height: ${props => props.$fillHeight ? '100%' : 'auto'};
40+
min-height: ${props => props.$fillHeight ? '0' : props.$rowCount === Infinity ? '100%' : 'auto'};
4041
margin: 0 auto;
4142
max-width: ${(props) => props.$maxWidth || 1600}px;
4243
@@ -68,6 +69,18 @@ const gridLayoutCanvasProps = {
6869
isCanvas: true,
6970
};
7071

72+
export function shouldShowStretchCanvasHeight(rowCount: number) {
73+
return rowCount !== DEFAULT_ROW_COUNT;
74+
}
75+
76+
export function shouldStretchCanvasHeight(
77+
rowCount: number,
78+
readOnly: boolean,
79+
gridStretchHeight?: boolean
80+
) {
81+
return readOnly && Boolean(gridStretchHeight) && rowCount !== DEFAULT_ROW_COUNT;
82+
}
83+
7184
function getDragSelectedNames(
7285
items: GridItemsType,
7386
layout: GridLayoutType,
@@ -176,7 +189,7 @@ export const CanvasView = React.memo((props: ContainerBaseProps) => {
176189

177190
const externalState = useContext(ExternalEditorContext);
178191
const {
179-
readOnly,
192+
readOnly = false,
180193
appType,
181194
rootContainerExtraHeight = DEFAULT_EXTRA_HEIGHT,
182195
rootContainerPadding,
@@ -271,6 +284,10 @@ export const CanvasView = React.memo((props: ContainerBaseProps) => {
271284
|| defaultTheme?.gridRowCount
272285
|| DEFAULT_ROW_COUNT;
273286
}, [preventStylesOverwriting, appSettings, currentTheme, defaultTheme]);
287+
const isStretchCanvasHeight = useMemo(
288+
() => shouldStretchCanvasHeight(defaultRowCount ?? DEFAULT_ROW_COUNT, readOnly, (appSettings as any).gridStretchHeight),
289+
[appSettings, defaultRowCount, readOnly]
290+
);
274291

275292
const defaultContainerPadding: [number, number] = useMemo(() => {
276293
const DEFAULT_PADDING = isMobile ? DEFAULT_MOBILE_PADDING : DEFAULT_CONTAINER_PADDING;
@@ -305,10 +322,11 @@ export const CanvasView = React.memo((props: ContainerBaseProps) => {
305322

306323
if (readOnly) {
307324
return (
308-
<UICompContainer
309-
$maxWidth={maxWidth}
310-
$rowCount={defaultRowCount}
311-
readOnly={true}
325+
<UICompContainer
326+
$maxWidth={maxWidth}
327+
$rowCount={defaultRowCount}
328+
$fillHeight={isStretchCanvasHeight}
329+
readOnly={true}
312330
className={CNRootContainer}
313331
$bgColor={bgColor}
314332
$bgImage={bgImage}
@@ -324,6 +342,9 @@ export const CanvasView = React.memo((props: ContainerBaseProps) => {
324342
{...props}
325343
positionParams={positionParams}
326344
{...gridLayoutCanvasProps}
345+
autoHeight={!isStretchCanvasHeight}
346+
rowCount={defaultRowCount}
347+
isRowCountLocked={isStretchCanvasHeight}
327348
bgColor={bgColor}
328349
radius="0px"
329350
emptyRows={defaultRowCount}
@@ -341,6 +362,7 @@ export const CanvasView = React.memo((props: ContainerBaseProps) => {
341362
<UICompContainer
342363
$maxWidth={maxWidth}
343364
$rowCount={defaultRowCount}
365+
$fillHeight={isStretchCanvasHeight}
344366
className={CNRootContainer}
345367
$bgColor={bgColor}
346368
$bgImage={bgImage}
@@ -360,6 +382,9 @@ export const CanvasView = React.memo((props: ContainerBaseProps) => {
360382
overflow={rootContainerOverflow}
361383
{...props}
362384
{...gridLayoutCanvasProps}
385+
autoHeight={!isStretchCanvasHeight}
386+
rowCount={defaultRowCount}
387+
isRowCountLocked={isStretchCanvasHeight}
363388
dragSelectedComps={dragSelectedComps}
364389
scrollContainerRef={scrollContainerRef}
365390
isDroppable={!isModule}

client/packages/lowcoder/src/pages/editor/editorView.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ const Height100Div = lazy(
116116
() => import('pages/common/styledComponent')
117117
.then(module => ({default: module.Height100Div}))
118118
);
119+
const PreviewContainer = styled.div`
120+
height: 100%;
121+
`;
119122
const LeftPanel = lazy(
120123
() => import('pages/common/styledComponent')
121124
.then(module => ({default: module.LeftPanel}))
@@ -539,14 +542,14 @@ function EditorView(props: EditorViewProps) {
539542
deviceType={editorState.deviceType}
540543
deviceOrientation={editorState.deviceOrientation}
541544
>
542-
<div id={PreviewContainerID}>
545+
<PreviewContainer id={PreviewContainerID}>
543546
{uiComp.getView()}
544-
</div>
547+
</PreviewContainer>
545548
</DeviceWrapper>
546549
) : (
547-
<div id={PreviewContainerID}>
550+
<PreviewContainer id={PreviewContainerID}>
548551
{uiComp.getView()}
549-
</div>
552+
</PreviewContainer>
550553
)
551554
)
552555
}, [
@@ -794,4 +797,3 @@ function EditorView(props: EditorViewProps) {
794797
export default React.memo(EditorView, (prevProps, newProps) => {
795798
return isEqual(prevProps, newProps);
796799
});
797-

0 commit comments

Comments
 (0)