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: main axis auto size not including margin #702

Merged
merged 2 commits into from Sep 26, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
188 changes: 188 additions & 0 deletions integration_tests/specs/css/css-flexbox/flex_shrink.ts
Expand Up @@ -873,4 +873,192 @@ describe('flexbox flex-shrink', () => {
await snapshot(0.1);
});

it('should work with child has margin when flex direction is row', async () => {
let div = createElement(
'div',
{
style: {
display: 'flex',
overflow: 'visible',
width: '100vw',
},
}, [
createElement(
'div',
{
style: {
display: 'flex',
flexDirection: 'row',
boxSizing: 'border-box',
overflow: 'visible'
},
}, [
createElement(
'div',
{
style: {
width: '100px',
border: '2px gray solid',
height: '100px',
margin: '20px',
boxSizing: 'border-box',
},
}, [

]),
createElement(
'div',
{
style: {
width: '100px',
border: '2px gray solid',
height: '100px',
margin: '20px',
boxSizing: 'border-box',
},
}, [

]),
createElement(
'div',
{
style: {
width: '100px',
border: '2px gray solid',
height: '100px',
margin: '20px',
boxSizing: 'border-box',
},
}, [

]),
createElement(
'div',
{
style: {
width: '100px',
border: '2px gray solid',
height: '100px',
margin: '20px',
boxSizing: 'border-box',
},
}, [

]),
createElement(
'div',
{
style: {
width: '100px',
border: '2px gray solid',
height: '100px',
margin: '20px',
boxSizing: 'border-box',
},
}, [

]),
])
]);

BODY.appendChild(div);

await snapshot();
});

it('should work with child has margin when flex direction is column', async () => {
let div = createElement(
'div',
{
style: {
display: 'flex',
flexDirection: 'column',
overflow: 'visible',
height: '300px',
},
}, [
createElement(
'div',
{
style: {
display: 'flex',
flexDirection: 'column',
boxSizing: 'border-box',
overflow: 'visible'
},
}, [
createElement(
'div',
{
style: {
width: '100px',
border: '2px gray solid',
height: '100px',
margin: '20px',
boxSizing: 'border-box',
},
}, [

]),
createElement(
'div',
{
style: {
width: '100px',
border: '2px gray solid',
height: '100px',
margin: '20px',
boxSizing: 'border-box',
},
}, [

]),
createElement(
'div',
{
style: {
width: '100px',
border: '2px gray solid',
height: '100px',
margin: '20px',
boxSizing: 'border-box',
},
}, [

]),
createElement(
'div',
{
style: {
width: '100px',
border: '2px gray solid',
height: '100px',
margin: '20px',
boxSizing: 'border-box',
},
}, [

]),
createElement(
'div',
{
style: {
width: '100px',
border: '2px gray solid',
height: '100px',
margin: '20px',
boxSizing: 'border-box',
},
}, [

]),
])
]);

BODY.appendChild(div);

await snapshot();
});


});
2 changes: 1 addition & 1 deletion integration_tests/specs/css/css-position/abspos.ts
Expand Up @@ -1170,7 +1170,7 @@ describe('abspos', () => {
);
BODY.appendChild(p);

await snapshot();
await snapshot(0.1);
});
it('026', async () => {
let p;
Expand Down
10 changes: 10 additions & 0 deletions kraken/lib/src/rendering/flex.dart
Expand Up @@ -1818,6 +1818,16 @@ class RenderFlexLayout extends RenderLayoutBox {
? child.autoMinWidth
: child.autoMinHeight;
}
// Should add main axis margin of child to the main axis auto size of parent.
if (child is RenderBoxModel) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

看起来 child 不太可能既是 RenderTextBox 又是 RenderBoxModel ,所以这里使用 else if 应该会更好

double childMarginTop = child.renderStyle.marginTop.length!;
double childMarginBottom = child.renderStyle.marginBottom.length!;
double childMarginLeft = child.renderStyle.marginLeft.length!;
double childMarginRight = child.renderStyle.marginRight.length!;
runChildMainSize += isHorizontalFlexDirection ?
childMarginLeft + childMarginRight :
childMarginTop + childMarginBottom;
}
runMainExtent += runChildMainSize;
}

Expand Down
6 changes: 6 additions & 0 deletions kraken/lib/src/rendering/flow.dart
Expand Up @@ -1174,6 +1174,12 @@ class RenderFlowLayout extends RenderLayoutBox {
if (runChild is RenderTextBox) {
runChildMainSize = runChild.autoMinWidth;
}
// Should add horizontal margin of child to the main axis auto size of parent.
if (runChild is RenderBoxModel) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

double childMarginLeft = runChild.renderStyle.marginLeft.length!;
double childMarginRight = runChild.renderStyle.marginRight.length!;
runChildMainSize += childMarginLeft + childMarginRight;
}
runMainExtent += runChildMainSize;
}

Expand Down