浏览代码

update tests.

/main
kg 6 年前
当前提交
2bcb0aa4
共有 5 个文件被更改,包括 128 次插入60 次删除
  1. 89
      Assets/UIWidgets/Tests/Widgets.cs
  2. 14
      Assets/UIWidgets/rendering/automatic_keep_alive.cs
  3. 44
      Assets/UIWidgets/widgets/basic.cs
  4. 39
      Assets/UIWidgets/widgets/framework.cs
  5. 2
      Assets/UIWidgets/widgets/sliver.cs

89
Assets/UIWidgets/Tests/Widgets.cs


const double headerHeight = 80.0;
double _offsetY = 0.0;
int _index = -1;
child: new Flex(
direction: Axis.horizontal,
child: new Row(
new Row(
children: new List<Widget> {
new Text(
"Today",
style: new TextStyle(
fontSize: (34.0 / headerHeight) * (headerHeight - _offsetY),
color: CLColors.white
)
),
new CustomButton(
padding: EdgeInsets.all(8.0),
child: new Icon(
Icons.notifications,
size: 28.0,
color: CLColors.icon2
)
),
new CustomButton(
padding: EdgeInsets.all(8.0),
child: new Icon(
Icons.account_circle,
size: 28.0,
color: CLColors.icon2
)
new Flexible(
flex: 1,
fit: FlexFit.tight,
child: new Text(
"Today",
style: new TextStyle(
fontSize: (34.0 / headerHeight) * (headerHeight - _offsetY),
color: CLColors.white
}
)),
new CustomButton(
padding: EdgeInsets.only(8.0, 0.0, 8.0, 0.0),
child: new Icon(
Icons.notifications,
size: 18.0,
color: CLColors.icon2
)
),
new CustomButton(
padding: EdgeInsets.only(8.0, 0.0, 16.0, 0.0),
child: new Icon(
Icons.account_circle,
size: 18.0,
color: CLColors.icon2
)
)
}
)

bool _onNotification(ScrollNotification notification, BuildContext context) {
double pixels = notification.metrics.pixels;
if (pixels >= 0.0) {
if (pixels <= headerHeight) {
setState(() => {
_offsetY = pixels / 2.0;
});
}
} else {
if (_offsetY != 0.0) {
setState(() => {
_offsetY = 0.0;
});
}
}
return true;
}
_onNotification(notification, context);
child: new Container()
child: new Flexible(
child: ListView.builder(
itemCount: 20,
itemExtent: 100,
physics: new AlwaysScrollableScrollPhysics(),
itemBuilder: (BuildContext context1, int index) => {
return new Container(
color: Color.fromARGB(255, (index * 10) % 256, (index * 10) % 256, (index * 10) % 256)
);
}
)
)
);
}

14
Assets/UIWidgets/rendering/automatic_keep_alive.cs


handle.addListener(this._handles[handle]);
if (!this._keepingAlive) {
this._keepingAlive = true;
ParentDataElement<SliverMultiBoxAdaptorWidget> childElement = this._getChildElement();
ParentDataElement childElement = this._getChildElement();
ParentDataElement<SliverMultiBoxAdaptorWidget> childElement1 = this._getChildElement();
ParentDataElement childElement1 = this._getChildElement();
D.assert(childElement1 != null);
this._updateParentDataOfChild(childElement1);
});

return false;
}
ParentDataElement<SliverMultiBoxAdaptorWidget> _getChildElement() {
ParentDataElement _getChildElement() {
D.assert(childElement == null || childElement is ParentDataElement<SliverMultiBoxAdaptorWidget>);
return (ParentDataElement<SliverMultiBoxAdaptorWidget>) childElement;
D.assert(childElement == null || childElement is ParentDataElement);
return (ParentDataElement) childElement;
void _updateParentDataOfChild(ParentDataElement<SliverMultiBoxAdaptorWidget> childElement) {
childElement.applyWidgetOutOfTurn((ParentDataWidget<SliverMultiBoxAdaptorWidget>) this.build(this.context));
void _updateParentDataOfChild(ParentDataElement childElement) {
childElement.applyWidgetOutOfTurn((ParentDataWidget) this.build(this.context));
}
VoidCallback _createCallback(Listenable handle) {

44
Assets/UIWidgets/widgets/basic.cs


}
}
public class Flexible : ParentDataWidget {
public Flexible(
Key key = null,
int flex = 1,
FlexFit fit = FlexFit.loose,
Widget child = null
) : base(key: key, child: child) {
this.flex = flex;
this.fit = fit;
}
public readonly int flex;
public readonly FlexFit fit;
public override void applyParentData(RenderObject renderObject) {
D.assert(renderObject.parentData is FlexParentData);
FlexParentData parentData = (FlexParentData) renderObject.parentData;
bool needsLayout = false;
if (parentData.flex != this.flex) {
parentData.flex = this.flex;
needsLayout = true;
}
if (parentData.fit != this.fit) {
parentData.fit = this.fit;
needsLayout = true;
}
if (needsLayout) {
var targetParent = renderObject.parent;
if (targetParent is RenderObject) {
((RenderObject) targetParent).markNeedsLayout();
}
}
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new IntProperty("flex", this.flex));
}
}
public class Padding : SingleChildRenderObjectWidget {
public Padding(
Key key = null,

39
Assets/UIWidgets/widgets/framework.cs


public readonly Widget child;
}
public abstract class ParentDataWidget<T> : ProxyWidget where T : RenderObjectWidget {
public abstract class ParentDataWidget : ProxyWidget {
return new ParentDataElement<T>(this);
return new ParentDataElement(this);
D.assert(typeof(T) != typeof(RenderObjectWidget));
return ancestor is T;
return ancestor is RenderObjectWidget;
}
public virtual string debugDescribeInvalidAncestorChain(

D.assert(typeof(T) != typeof(RenderObjectWidget));
"{2} has no {1} ancestor at all.\n", this.GetType(), typeof(T), description);
"{2} has no {1} ancestor at all.\n", this.GetType(), typeof(RenderObjectWidget), description);
this.GetType(), typeof(T), description);
this.GetType(), typeof(RenderObjectWidget), description);
foreach (Widget ancestor in badAncestors) {
if (ancestor.GetType() == this.GetType()) {

}
}
result += "These widgets cannot come between a " + this.GetType() + " and its " + typeof(T) + ".\n";
result += "These widgets cannot come between a " + this.GetType() + " and its " + typeof(RenderObjectWidget) + ".\n";
}
result += "The ownership chain for the parent of the offending "

public abstract void notifyClients(ProxyWidget oldWidget);
}
public class ParentDataElement<T> : ProxyElement where T : RenderObjectWidget {
public ParentDataElement(ParentDataWidget<T> widget) : base(widget) {
public class ParentDataElement : ProxyElement {
public ParentDataElement(ParentDataWidget widget) : base(widget) {
public new ParentDataWidget<T> widget {
get { return (ParentDataWidget<T>) base.widget; }
public new ParentDataWidget widget {
get { return (ParentDataWidget) base.widget; }
}
public override void mount(Element parent, object newSlot) {

while (ancestor != null) {
if (ancestor is ParentDataElement<RenderObjectWidget>) {
if (ancestor is ParentDataElement) {
badAncestors.Add(ancestor.widget);
} else if (ancestor is RenderObjectElement) {
if (this.widget.debugIsValidAncestor(((RenderObjectElement) ancestor).widget)) {

base.mount(parent, newSlot);
}
void _applyParentData(ParentDataWidget<T> widget) {
void _applyParentData(ParentDataWidget widget) {
D.assert(!(child is ParentDataElement<RenderObjectWidget>));
D.assert(!(child is ParentDataElement));
child.visitChildren(applyParentDataToChild);
}
};

public void applyWidgetOutOfTurn(ParentDataWidget<T> newWidget) {
public void applyWidgetOutOfTurn(ParentDataWidget newWidget) {
D.assert(newWidget != null);
D.assert(newWidget.debugCanApplyOutOfTurn());
D.assert(newWidget.child == this.widget.child);

return ancestor as RenderObjectElement;
}
ParentDataElement<RenderObjectWidget> _findAncestorParentDataElement() {
ParentDataElement _findAncestorParentDataElement() {
var element = ancestor as ParentDataElement<RenderObjectWidget>;
var element = ancestor as ParentDataElement;
if (element != null) {
return element;
}

this.widget.didUnmountRenderObject(this.renderObject);
}
internal void _updateParentData<T>(ParentDataWidget<T> parentData) where T : RenderObjectWidget {
internal void _updateParentData(ParentDataWidget parentData) {
parentData.applyParentData(this.renderObject);
}

this._ancestorRenderObjectElement.insertChildRenderObject(this.renderObject, newSlot);
}
ParentDataElement<RenderObjectWidget> parentDataElement = this._findAncestorParentDataElement();
ParentDataElement parentDataElement = this._findAncestorParentDataElement();
if (parentDataElement != null) {
this._updateParentData(parentDataElement.widget);
}

2
Assets/UIWidgets/widgets/sliver.cs


}
}
public class KeepAlive : ParentDataWidget<SliverMultiBoxAdaptorWidget> {
public class KeepAlive : ParentDataWidget{
public KeepAlive(
Key key = null,
bool keepAlive = true,

正在加载...
取消
保存