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(applyLayoutTransform): fix calculate matrix not include scrollLef… #1447

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
42 changes: 42 additions & 0 deletions integration_tests/specs/dom/nodes/element.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,48 @@ describe('DOM Element API', () => {
expect(div.hasAttribute('foo')).toBeFalse();
});

it('should work', () => {
const div = document.createElement('div');

div.style.width = div.style.height = '200px';
div.style.padding = '10px';
div.style.margin = '20px';
div.style.backgroundColor = 'grey';
div.style.overflow = 'scroll';
document.body.appendChild(div);

const scrollDiv = document.createElement('div');
scrollDiv.style.width = '100px';
scrollDiv.style.height ='1000px';
div.appendChild(scrollDiv)

const childDiv = document.createElement('div');
childDiv.style.width = childDiv.style.height = '30px';
childDiv.style.marginTop = '150px';
childDiv.style.backgroundColor = 'yellow';
scrollDiv.appendChild(childDiv);


const boundingClientRect = div.getBoundingClientRect();
expect(JSON.parse(JSON.stringify(boundingClientRect))).toEqual({
x: 20.0,
y: 20.0,
width: 200.0,
height: 200.0,
top: 20.0,
left: 20.0,
right: 220.0,
bottom: 220.0,
} as any);

div.setAttribute('foo', 'bar');
expect(div.getAttribute('foo')).toBe('bar');
expect(div.hasAttribute('foo')).toBeTrue();

div.removeAttribute('foo');
expect(div.hasAttribute('foo')).toBeFalse();
});

it('children should only contain elements', () => {
let container = document.createElement('div');
let a = document.createElement('div');
Expand Down
2 changes: 1 addition & 1 deletion kraken/lib/src/css/positioned.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Offset _getPlaceholderToParentOffset(RenderPositionPlaceholder? placeholder, Ren
Offset positionHolderScrollOffset = _getRenderPositionHolderScrollOffset(placeholder, parent) ?? Offset.zero;
// Offset of positioned element should exclude scroll offset to its containing block.
Offset toParentOffset = placeholder.getOffsetToAncestor(Offset.zero, parent, excludeScrollOffset: true);
Offset placeholderOffset = positionHolderScrollOffset + toParentOffset;
Offset placeholderOffset = -positionHolderScrollOffset + toParentOffset;

return placeholderOffset;
}
Expand Down
2 changes: 2 additions & 0 deletions kraken/lib/src/rendering/box_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1092,6 +1092,8 @@ class RenderBoxModel extends RenderBox
final BoxParentData childParentData = child.parentData! as BoxParentData;
Offset offset = childParentData.offset;
if (excludeScrollOffset) {
offset += Offset(scrollLeft, scrollTop);
} else {
offset -= Offset(scrollLeft, scrollTop);
}
transform.translate(offset.dx, offset.dy);
Expand Down