Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into refactor/remove_host_…
Browse files Browse the repository at this point in the history
…class
  • Loading branch information
andycall committed May 18, 2022
2 parents 65d6f89 + f718aff commit 6a145bd
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
20 changes: 18 additions & 2 deletions kraken/lib/src/css/render_style.dart
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,22 @@ class CSSRenderStyle
RenderStyle? ancestorRenderStyle = _findAncestorWithNoDisplayInline();
// Should ignore renderStyle of display inline when searching for ancestors to stretch width.
if (ancestorRenderStyle != null) {
logicalWidth = ancestorRenderStyle.contentBoxLogicalWidth;
// If parentElement is WidgetElement, should not search for ancestors and get maxWidth of constraints for logicalWidth.
RenderObject? renderObject = renderBoxModel!.parent as RenderObject;


if (ancestorRenderStyle.target.renderObjectManagerType == RenderObjectManagerType.FLUTTER_ELEMENT && renderObject is RenderBox) {
try {
// When renderObject has not layouted, get constraints will trigger assert.
// Such as image resize will get _styleWidth and call this function before layout.
logicalWidth = renderObject.constraints.maxWidth;
} catch(e) {
logicalWidth = ancestorRenderStyle.contentBoxLogicalWidth;
}
} else {
logicalWidth = ancestorRenderStyle.contentBoxLogicalWidth;
}

// Should subtract horizontal margin of own from its parent content width.
if (logicalWidth != null) {
logicalWidth -= renderStyle.margin.horizontal;
Expand Down Expand Up @@ -1126,7 +1141,8 @@ class CSSRenderStyle
RenderStyle renderStyle = this;
RenderStyle? parentRenderStyle = renderStyle.parent;
while(parentRenderStyle != null) {
if (parentRenderStyle.effectiveDisplay != CSSDisplay.inline) {
// If ancestor element is WidgetElement, should return it because should get maxWidth of constraints for logicalWidth.
if (parentRenderStyle.effectiveDisplay != CSSDisplay.inline || parentRenderStyle.target.renderObjectManagerType == RenderObjectManagerType.FLUTTER_ELEMENT) {
break;
}
parentRenderStyle = parentRenderStyle.parent;
Expand Down
13 changes: 12 additions & 1 deletion kraken/lib/src/widget/element_to_widget_adaptor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
* Copyright (C) 2022-present The Kraken authors. All rights reserved.
*/
import 'package:flutter/widgets.dart';
import 'package:kraken/css.dart';
import 'package:kraken/dom.dart' as dom;
import 'package:kraken/rendering.dart';

class KrakenElementToWidgetAdaptor extends RenderObjectWidget {
final dom.Node _krakenNode;
Expand All @@ -19,7 +21,16 @@ class KrakenElementToWidgetAdaptor extends RenderObjectWidget {

@override
RenderObject createRenderObject(BuildContext context) {
return _krakenNode.renderer!;
// Children of custom element need RenderFlowLayout nesting,
// otherwise the parent render layout will not be called when setting properties.
if (_krakenNode is dom.Element) {
CSSRenderStyle renderStyle = CSSRenderStyle(target: _krakenNode as dom.Element);
RenderFlowLayout renderFlowLayout = RenderFlowLayout(renderStyle: renderStyle);
renderFlowLayout.insert(_krakenNode.renderer!);
return renderFlowLayout;
} else {
return _krakenNode.renderer!;
}
}
}

Expand Down

0 comments on commit 6a145bd

Please sign in to comment.