Skip to content

Commit

Permalink
[canvaskit] fix Path.from (flutter#24382)
Browse files Browse the repository at this point in the history
  • Loading branch information
yjbanov authored and hjfreyer committed Mar 22, 2021
1 parent 4d808e5 commit 3503ecf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/web_ui/lib/src/engine/canvaskit/path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class CkPath extends ManagedSkiaObject<SkPath> implements ui.Path {

CkPath.from(CkPath other)
: _fillType = other.fillType,
super(SkPath(other.skiaObject)) {
super(other.skiaObject.copy()) {
skiaObject.setFillType(toSkFillType(_fillType));
}

Expand Down
19 changes: 19 additions & 0 deletions lib/web_ui/test/canvaskit/path_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,25 @@ void testMain() {
expect(measure1.contourIndex, 1);
expect(measure1.extractPath(0, 15).getBounds(), ui.Rect.fromLTRB(20, 20, 30, 25));
});

test('Path.from', () {
final ui.Rect rect1 = ui.Rect.fromLTRB(0, 0, 10, 10);
final ui.Rect rect2 = ui.Rect.fromLTRB(10, 10, 20, 20);

final ui.Path original = ui.Path();
original.addRect(rect1);
expect(original, isA<CkPath>());
expect(original.getBounds(), rect1);

final ui.Path copy = ui.Path.from(original);
expect(copy, isA<CkPath>());
expect(copy.getBounds(), rect1);

// Test that when copy is mutated, the original is not affected
copy.addRect(rect2);
expect(original.getBounds(), rect1);
expect(copy.getBounds(), rect1.expandToInclude(rect2));
});
},
skip:
isIosSafari); // TODO: https://github.com/flutter/flutter/issues/60040
Expand Down

0 comments on commit 3503ecf

Please sign in to comment.