浏览代码

bug fixes

add more samples
/siyaoH-1.17-PlatformMessage
xingweizhu 4 年前
当前提交
36254828
共有 10 个文件被更改,包括 378 次插入18 次删除
  1. 30
      com.unity.uiwidgets/Runtime/material/expansion_panel.cs
  2. 2
      com.unity.uiwidgets/Runtime/material/flat_button.cs
  3. 2
      com.unity.uiwidgets/Runtime/material/raised_button.cs
  4. 1
      com.unity.uiwidgets/Runtime/widgets/animated_size.cs
  5. 87
      Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/CustomPaintSample.cs
  6. 11
      Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/CustomPaintSample.cs.meta
  7. 172
      Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/ExpansionPanelSample.cs
  8. 11
      Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/ExpansionPanelSample.cs.meta
  9. 69
      Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/HttpRequestSample.cs
  10. 11
      Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/HttpRequestSample.cs.meta

30
com.unity.uiwidgets/Runtime/material/expansion_panel.cs


public override Widget build(BuildContext context) {
List<MergeableMaterialItem> items = new List<MergeableMaterialItem>();
for (int index = 0; index < widget.children.Count; index++) {
int expandIndex = index;
if (_isChildExpanded(index) && index != 0 && !_isChildExpanded(index - 1)) {
for (int i = 0; i < widget.children.Count; i++) {
int expandIndex = i;
if (_isChildExpanded(expandIndex) && expandIndex != 0 && !_isChildExpanded(expandIndex - 1)) {
key: new _SaltedKey<BuildContext, int>(context, index * 2 - 1)));
key: new _SaltedKey<BuildContext, int>(context, expandIndex * 2 - 1)));
ExpansionPanel child = widget.children[index];
ExpansionPanel child = widget.children[expandIndex];
_isChildExpanded(index)
_isChildExpanded(expandIndex)
margin: (EdgeInsets) (EdgeInsetsGeometry) EdgeInsetsDirectional.only(end: 8.0f),
//margin: (EdgeInsets) (EdgeInsetsGeometry) EdgeInsetsDirectional.only(end: 8.0f),
isExpanded: _isChildExpanded(index),
isExpanded: _isChildExpanded(expandIndex),
? (bool isExpanded) => _handlePressed(isExpanded, index)
? (bool isExpanded) => _handlePressed(isExpanded, expandIndex)
: (ValueChanged<bool>) null
)
);

child: new AnimatedContainer(
duration: widget.animationDuration,
curve: Curves.fastOutSlowIn,
margin: _isChildExpanded(index) ? widget.expandedHeaderPadding : EdgeInsets.zero,
margin: _isChildExpanded(expandIndex) ? widget.expandedHeaderPadding : EdgeInsets.zero,
child: new ConstrainedBox(
constraints: new BoxConstraints(
minHeight: material_._kPanelHeaderCollapsedHeight),

);
if (child.canTapOnHeader) {
header = new InkWell(
onTap: () => _handlePressed(_isChildExpanded(index), index),
onTap: () => _handlePressed(_isChildExpanded(expandIndex), expandIndex),
key: new _SaltedKey<BuildContext, int>(context, index * 2),
key: new _SaltedKey<BuildContext, int>(context, expandIndex * 2),
child: new Column(
children: new List<Widget> {
header,

firstCurve: new Interval(0.0f, 0.6f, curve: Curves.fastOutSlowIn),
secondCurve: new Interval(0.4f, 1.0f, curve: Curves.fastOutSlowIn),
sizeCurve: Curves.fastOutSlowIn,
crossFadeState: _isChildExpanded(index)
crossFadeState: _isChildExpanded(expandIndex)
? CrossFadeState.showSecond
: CrossFadeState.showFirst,
duration: widget.animationDuration

)
);
if (_isChildExpanded(index) && index != widget.children.Count - 1) {
if (_isChildExpanded(expandIndex) && expandIndex != widget.children.Count - 1) {
key: new _SaltedKey<BuildContext, int>(context, index * 2 + 1)));
key: new _SaltedKey<BuildContext, int>(context, expandIndex * 2 + 1)));
}
}

2
com.unity.uiwidgets/Runtime/material/flat_button.cs


return new RawMaterialButton(
onPressed: onPressed,
onLongPress: () => onLongPress(),
onLongPress: () => onLongPress?.Invoke(),
onHighlightChanged: onHighlightChanged,
fillColor: buttonTheme.getFillColor(this),
textStyle: theme.textTheme.button.copyWith(color: buttonTheme.getTextColor(this)),

2
com.unity.uiwidgets/Runtime/material/raised_button.cs


return new RawMaterialButton(
onPressed: onPressed,
onLongPress: () => onLongPress(),
onLongPress: () => onLongPress?.Invoke(),
onHighlightChanged: onHighlightChanged,
clipBehavior: clipBehavior.Value,
fillColor: buttonTheme.getFillColor(this),

1
com.unity.uiwidgets/Runtime/widgets/animated_size.cs


TimeSpan? reverseDuration = null,
TickerProvider vsync = null) : base(key: key, child: child) {
D.assert(duration != null);
D.assert(reverseDuration != null);
D.assert(vsync != null);
this.alignment = alignment ?? Alignment.center;
this.curve = curve ?? Curves.linear;

87
Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/CustomPaintSample.cs


using Unity.UIWidgets.engine2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using ui_ = Unity.UIWidgets.widgets.ui_;
namespace UIWidgetsSample {
public class CustomPaintSample : UIWidgetsPanel {
protected override void main()
{
ui_.runApp(new MyApp());
}
class MyApp : StatelessWidget
{
public override Widget build(BuildContext context)
{
return new WidgetsApp(
home: new Unity.UIWidgets.widgets.CustomPaint(
child: new Container(width: 300, height: 300, color: new Color(0XFFFFFFFF)),
foregroundPainter: new GridPainter(null)
),
pageRouteBuilder: (settings, builder) =>
new PageRouteBuilder(
settings: settings,
pageBuilder: (Buildcontext, animation, secondaryAnimation) => builder(context)
)
);
}
}
}
public class GridPainter : AbstractCustomPainter {
public GridPainter(Listenable repaint) : base(repaint) {
}
public override void paint(Canvas canvas, Size size) {
int numGrid = 4;
var paint = new Paint();
paint.color = new Color(0xFFFF0000);
paint.strokeWidth = 2;
paint.style = PaintingStyle.stroke;
for (int i = 1; i < numGrid; i++) {
float offsetY = size.height * i / numGrid;
canvas.drawLine(new Offset(0, offsetY), new Offset(size.width, offsetY),
paint);
}
for (int i = 1; i < numGrid; i++) {
float offsetx = size.width * i / numGrid;
canvas.drawLine(new Offset(offsetx, 0), new Offset(offsetx, size.height),
paint);
}
// draw a arrow line
canvas.save();
canvas.rotate(0.4f);
canvas.scale(2, 2);
canvas.translate(50, 50);
canvas.drawLine(new Offset(0, 0), new Offset(100, 0),
new Paint() {
color = new Color(0xFFFF0000),
strokeWidth = 2,
style = PaintingStyle.stroke
});
var path = new Path();
var arrowPaint = new Paint() {
color = new Color(0xFFFF0000),
style = PaintingStyle.fill
};
path.moveTo(100, 0);
path.lineTo(100, 5);
path.lineTo(120, 0);
path.lineTo(100, -5);
path.close();
canvas.drawPath(path, arrowPaint);
canvas.restore();
}
public override bool shouldRepaint(CustomPainter oldDelegate) {
return false;
}
}
}

11
Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/CustomPaintSample.cs.meta


fileFormatVersion: 2
guid: 64240ba829347de43abdb2daa8488bc6
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

172
Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/ExpansionPanelSample.cs


using System.Collections.Generic;
using uiwidgets;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.engine2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using Material = Unity.UIWidgets.material.Material;
using ui_ = Unity.UIWidgets.widgets.ui_;
namespace UIWidgetsSample {
public class ExpansionPanelSample : UIWidgetsPanel {
protected override void main() {
ui_.runApp(new MyApp());
}
class MyApp : StatelessWidget
{
int testCaseId = 1;
readonly List<Widget> testCases = new List<Widget> {
new SingleChildScrollWidget(),
new ExpansionPanelWidget()
};
public override Widget build(BuildContext context)
{
return new MaterialApp(
home: this.testCases[this.testCaseId]
);
}
}
}
class SingleChildScrollWidget : StatefulWidget {
public SingleChildScrollWidget(Key key = null) : base(key) {
}
public override State createState() {
return new SingleChildScrollWidgetState();
}
}
class SingleChildScrollWidgetState : State<SingleChildScrollWidget> {
public override Widget build(BuildContext context) {
return new Material(
child: new SingleChildScrollView(
child: new Container(
width: 40.0f,
height: 40.0f,
constraints: BoxConstraints.tight(new Size(40, 600)),
color:Colors.red,
child: new Center(child: new Text("Beijing"))
)
)
);
}
}
class ExpansionPanelWidget : StatefulWidget {
public ExpansionPanelWidget(Key key = null) : base(key) {
}
public override State createState() {
return new ExpansionPanelWidgetState();
}
}
class ExpansionPanelWidgetState : State<ExpansionPanelWidget> {
readonly List<bool> isExpand = new List<bool> {false, false};
public override Widget build(BuildContext context) {
return new Material(
child: new SingleChildScrollView(
child: new ExpansionPanelList(
expansionCallback: (int _index, bool _isExpanded) => {
Debug.Log("<tile " + _index + "> from [" + (_isExpanded ? "Open" : "Close") + "]" +
" to [" + (_isExpanded ? "Close" : "Open") + "]");
this.isExpand[_index] = !_isExpanded;
this.setState(() => { });
},
children: new List<ExpansionPanel> {
new ExpansionPanel(
headerBuilder: (BuildContext subContext, bool isExpanded) => {
return new Container(
color: Colors.black45,
child: new Center(
child: new Text("Beijing")
)
);
},
body: new Container(
child: new Column(
children: new List<Widget> {
new Card(
child: new Container(
color: Colors.black38,
height: 36,
width: 300,
child: new Center(
child: new Text("Beijing")
)
)
)
}
)
),
isExpanded: this.isExpand[0]
),
new ExpansionPanel(
headerBuilder: (BuildContext subContext, bool isExpanded) => {
return new Container(
color: Colors.black45,
child: new Center(
child: new Text("Hebei")
)
);
},
body: new Container(
child: new Column(
children: new List<Widget> {
new Card(
child: new Container(
color: Colors.black38,
height: 36,
width: 300,
child: new Center(
child: new Text("Tianjin")
)
)
),
new Card(
child: new Container(
color: Colors.black38,
height: 36,
width: 300,
child: new Center(
child: new Text("Shijiazhuang")
)
)
),
new Card(
child: new Container(
color: Colors.black38,
height: 36,
width: 300,
child: new Center(
child: new Text("Zhumadian")
)
)
)
}
)
),
isExpanded: this.isExpand[1]
),
}
)
)
);
}
}
}

11
Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/ExpansionPanelSample.cs.meta


fileFormatVersion: 2
guid: 49545bd84f0a8614e866467b68490383
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

69
Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/HttpRequestSample.cs


using System;
using System.Collections.Generic;
using Unity.UIWidgets.engine;
using Unity.UIWidgets.engine2;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.material;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using UnityEngine;
using UnityEngine.Networking;
using ui_ = Unity.UIWidgets.widgets.ui_;
public class HttpRequestSample : UIWidgetsPanel
{
protected override void main() {
ui_.runApp(new MaterialApp(
title: "Http Request Sample",
home: new Scaffold(
body:new AsyncRequestWidget(this.gameObject)
)
));
}
}
public class AsyncRequestWidget : StatefulWidget {
public readonly GameObject gameObjOfUIWidgetsPanel;
public AsyncRequestWidget(GameObject gameObjOfUiWidgetsPanel, Key key = null) : base(key) {
this.gameObjOfUIWidgetsPanel = gameObjOfUiWidgetsPanel;
}
public override State createState() {
return new _AsyncRequestWidgetState();
}
}
[Serializable]
public class TimeData {
public long currentFileTime;
}
class _AsyncRequestWidgetState : State<AsyncRequestWidget> {
long _fileTime;
public override Widget build(BuildContext context) {
var isolate = Isolate.current;
return new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: new List<Widget>() {
new FlatButton(child: new Text("Click To Get Time"), onPressed: () => {
UnityWebRequest www = UnityWebRequest.Get("http://worldclockapi.com/api/json/est/now");
var asyncOperation = www.SendWebRequest();
asyncOperation.completed += operation => {
var timeData = JsonUtility.FromJson<TimeData>(www.downloadHandler.text);
using(Isolate.getScope(isolate))
{
this.setState(() => { this._fileTime = timeData.currentFileTime; });
}
};
}),
new Text($"current file time: {this._fileTime}")
});
}
}

11
Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/HttpRequestSample.cs.meta


fileFormatVersion: 2
guid: b8fdebced4875694db8d21968f82b2c9
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存