Skip to content

Commit

Permalink
Merge pull request #838 from openkraken/fix/overflow-hidden
Browse files Browse the repository at this point in the history
fix: overflow hidden and clip
  • Loading branch information
andycall committed Nov 4, 2021
2 parents fae0c43 + e988700 commit 26a2c49
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 2 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions integration_tests/specs/css/css-overflow/overflow-clip.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
describe('clip', () => {
it('should works with basic', async () => {
let image;
let container = createElement('div', {
style: {
width: '80px',
height: '80px',
borderRadius: '10px',
overflow: "clip",
}
}, [
(image = createElement('img', {
src: 'assets/100x100-green.png',
}))
]);

document.body.appendChild(container);

await snapshot(0.1);
});

it('should works with children of appear event', async () => {
let image;
let container = createElement('div', {
style: {
width: '80px',
height: '80px',
borderRadius: '10px',
overflow: "clip",
}
}, [
(image = createElement('img', {
src: 'assets/100x100-green.png',
}))
]);

image.addEventListener('appear', function onAppear() {});

document.body.appendChild(container);

await snapshot(0.1);
});
});
43 changes: 43 additions & 0 deletions integration_tests/specs/css/css-overflow/overflow-hidden.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
describe('hidden', () => {
it('should works with basic', async () => {
let image;
let container = createElement('div', {
style: {
width: '80px',
height: '80px',
borderRadius: '10px',
overflow: "hidden",
}
}, [
(image = createElement('img', {
src: 'assets/100x100-green.png',
}))
]);

document.body.appendChild(container);

await snapshot(0.1);
});

it('should works with children of appear event', async () => {
let image;
let container = createElement('div', {
style: {
width: '80px',
height: '80px',
borderRadius: '10px',
overflow: "hidden",
}
}, [
(image = createElement('img', {
src: 'assets/100x100-green.png',
}))
]);

image.addEventListener('appear', function onAppear() {});

document.body.appendChild(container);

await snapshot(0.1);
});
});
2 changes: 2 additions & 0 deletions kraken/lib/src/css/overflow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ CSSOverflowType _getOverflowType(String definition) {
return CSSOverflowType.scroll;
case AUTO:
return CSSOverflowType.auto;
case CLIP:
return CSSOverflowType.clip;
case VISIBLE:
default:
return CSSOverflowType.visible;
Expand Down
3 changes: 3 additions & 0 deletions kraken/lib/src/css/values/keywords.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const String AUTO = 'auto';
const String VISIBLE = 'visible';
const String HIDDEN = 'hidden';

// Overflow
const String CLIP = 'clip';

// Border
const String SOLID = 'solid';
const String THIN = 'thin'; // A thin border.
Expand Down
9 changes: 7 additions & 2 deletions kraken/lib/src/gesture/scrollable.dart
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,11 @@ mixin RenderOverflowMixin on RenderBox {
PaintingContextCallback painter = (PaintingContext context, Offset offset) {
callback(context, offset + paintOffset);
};

// It needs to create new layer to clip children in case children has its own layer
// for all overflow value which is not visible (auto/scroll/hidden/clip).
bool _needsCompositing = true;

if (decoration != null && decoration.borderRadius != null) {
BorderRadius radius = decoration.borderRadius as BorderRadius;
RRect clipRRect = RRect.fromRectAndCorners(clipRect,
Expand All @@ -389,9 +394,9 @@ mixin RenderOverflowMixin on RenderBox {
bottomLeft: radius.bottomLeft,
bottomRight: radius.bottomRight
);
_oldClipRRectLayer = context.pushClipRRect(needsCompositing, offset, clipRect, clipRRect, painter, oldLayer: _oldClipRRectLayer);
_oldClipRRectLayer = context.pushClipRRect(_needsCompositing, offset, clipRect, clipRRect, painter, oldLayer: _oldClipRRectLayer);
} else {
_oldClipRectLayer = context.pushClipRect(needsCompositing, offset, clipRect, painter, oldLayer: _oldClipRectLayer);
_oldClipRectLayer = context.pushClipRect(_needsCompositing, offset, clipRect, painter, oldLayer: _oldClipRectLayer);
}
} else {
_oldClipRRectLayer = null;
Expand Down

0 comments on commit 26a2c49

Please sign in to comment.