xingweizhu
4 年前
当前提交
f3ca9f8d
共有 9 个文件被更改,包括 442 次插入 和 1 次删除
-
15com.unity.uiwidgets/Runtime/widgets/navigator.cs
-
52Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/LongPressSample.cs
-
11Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/LongPressSample.cs.meta
-
228Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/NavigationSample.cs
-
11Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/NavigationSample.cs.meta
-
45Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/PageViewSample.cs
-
11Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/PageViewSample.cs.meta
-
59Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/ScrollbarSample.cs
-
11Samples/UIWidgetsSamples_2019_4/Assets/WidgetsSample/ScrollbarSample.cs.meta
|
|||
using uiwidgets; |
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.widgets; |
|||
using UnityEngine; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class LongPressSample : UIWidgetsPanel { |
|||
protected override void main() { |
|||
ui_.runApp(new MyApp()); |
|||
} |
|||
} |
|||
|
|||
class MyApp : StatelessWidget |
|||
{ |
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new WidgetsApp( |
|||
home: new LongPressSampleWidget(), |
|||
pageRouteBuilder: (settings, builder) => |
|||
new PageRouteBuilder( |
|||
settings: settings, |
|||
pageBuilder: (Buildcontext, animation, secondaryAnimation) => builder(context) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
public class LongPressSampleWidget : StatefulWidget { |
|||
public override State createState() { |
|||
return new _LongPressSampleWidgetState(); |
|||
} |
|||
} |
|||
|
|||
class _LongPressSampleWidgetState : State<LongPressSampleWidget> { |
|||
public override Widget build(BuildContext context) { |
|||
return new GestureDetector( |
|||
onLongPressStart: (value) => { Debug.Log($"Long Press Drag Start: {value}"); }, |
|||
onLongPressMoveUpdate: (value) => { Debug.Log($"Long Press Drag Update: {value}"); }, |
|||
onLongPressEnd: (value) => { Debug.Log($"Long Press Drag Up: {value}"); }, |
|||
onLongPressUp: () => { Debug.Log($"Long Press Up"); }, |
|||
onLongPress: () => { Debug.Log($"Long Press"); }, |
|||
child: new Center( |
|||
child: new Container( |
|||
width: 200, |
|||
height: 200, |
|||
color: Colors.blue |
|||
) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b77689aad2545fb4bb66d5d41126fab2 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using uiwidgets; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.gestures; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.rendering; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using DialogUtils = Unity.UIWidgets.widgets.DialogUtils; |
|||
using TextStyle = Unity.UIWidgets.painting.TextStyle; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class NavigationSample : UIWidgetsPanel { |
|||
|
|||
protected override void main() |
|||
{ |
|||
ui_.runApp(new MyApp()); |
|||
} |
|||
|
|||
|
|||
|
|||
|
|||
class MyApp : StatelessWidget |
|||
{ |
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new WidgetsApp( |
|||
initialRoute: "/", |
|||
textStyle: new TextStyle(fontSize: 24), |
|||
pageRouteBuilder: (settings, builder) => |
|||
new PageRouteBuilder( |
|||
settings: settings, |
|||
pageBuilder: (BuildContext subContext, Animation<float> animation, |
|||
Animation<float> secondaryAnimation) => builder(subContext), |
|||
transitionsBuilder: (BuildContext subContext, Animation<float> |
|||
animation, Animation<float> secondaryAnimation, Widget child) => |
|||
new _FadeUpwardsPageTransition( |
|||
routeAnimation: animation, |
|||
child: child |
|||
) |
|||
), |
|||
routes: new Dictionary<string, WidgetBuilder> { |
|||
{"/", (subContext) => new HomeScreen()}, |
|||
{"/detail", (subContext) => new DetailScreen()} |
|||
} |
|||
); |
|||
} |
|||
} |
|||
} |
|||
|
|||
public class CustomButton : StatelessWidget { |
|||
public CustomButton( |
|||
Key key = null, |
|||
GestureTapCallback onPressed = null, |
|||
EdgeInsets padding = null, |
|||
Color backgroundColor = null, |
|||
Widget child = null |
|||
) : base(key: key) { |
|||
this.onPressed = onPressed; |
|||
this.padding = padding ?? EdgeInsets.all(8.0f); |
|||
this.backgroundColor = backgroundColor ?? Colors.white; |
|||
this.child = child; |
|||
} |
|||
|
|||
public readonly GestureTapCallback onPressed; |
|||
public readonly EdgeInsets padding; |
|||
public readonly Widget child; |
|||
public readonly Color backgroundColor; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new GestureDetector( |
|||
onTap: this.onPressed, |
|||
child: new Container( |
|||
padding: this.padding, |
|||
color: this.backgroundColor, |
|||
child: this.child |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
|
|||
class HomeScreen : StatelessWidget { |
|||
public override Widget build(BuildContext context) { |
|||
return new NavigationPage( |
|||
body: new Container( |
|||
color: new Color(0xFF888888), |
|||
child: new Center( |
|||
child: new CustomButton(onPressed: () => { Navigator.pushNamed(context, "/detail"); }, |
|||
child: new Text("Go to Detail")) |
|||
)), |
|||
title: "Home" |
|||
); |
|||
} |
|||
} |
|||
|
|||
class DetailScreen : StatelessWidget { |
|||
public override Widget build(BuildContext context) { |
|||
return new NavigationPage( |
|||
body: new Container( |
|||
color: new Color(0xFF1389FD), |
|||
child: new Center( |
|||
child: new Column( |
|||
children: new List<Widget>() { |
|||
new CustomButton(onPressed: () => { Navigator.pop<object>(context); }, child: new Text("Back")), |
|||
new CustomButton( |
|||
onPressed: () => { |
|||
_Dialog.showDialog(context, builder: (BuildContext c) => new Dialog()); |
|||
}, child: new Text("Show Dialog")) |
|||
} |
|||
) |
|||
)), |
|||
title: "Detail"); |
|||
} |
|||
} |
|||
|
|||
class Dialog : StatelessWidget { |
|||
public override Widget build(BuildContext context) { |
|||
return new Center(child: new Container( |
|||
color: new Color(0xFFFF0000), |
|||
width: 100, |
|||
height: 80, |
|||
child: new Center( |
|||
child: new Text("Hello Dialog") |
|||
))); |
|||
} |
|||
} |
|||
|
|||
class _FadeUpwardsPageTransition : StatelessWidget { |
|||
internal _FadeUpwardsPageTransition( |
|||
Key key = null, |
|||
Animation<float> routeAnimation = null, // The route's linear 0.0 - 1.0 animation.
|
|||
Widget child = null |
|||
) : base(key: key) { |
|||
this._positionAnimation = _bottomUpTween.chain(_fastOutSlowInTween).animate(routeAnimation); |
|||
this._opacityAnimation = _easeInTween.animate(routeAnimation); |
|||
this.child = child; |
|||
} |
|||
|
|||
static Tween<Offset> _bottomUpTween = new OffsetTween( |
|||
begin: new Offset(0.0f, 0.25f), |
|||
end: Offset.zero |
|||
); |
|||
|
|||
static Animatable<float> _fastOutSlowInTween = new CurveTween(curve: Curves.fastOutSlowIn); |
|||
static Animatable<float> _easeInTween = new CurveTween(curve: Curves.easeIn); |
|||
|
|||
readonly Animation<Offset> _positionAnimation; |
|||
readonly Animation<float> _opacityAnimation; |
|||
public readonly Widget child; |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
return new SlideTransition( |
|||
position: this._positionAnimation, |
|||
child: new FadeTransition( |
|||
opacity: this._opacityAnimation, |
|||
child: this.child |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
class NavigationPage : StatelessWidget { |
|||
public readonly Widget body; |
|||
public readonly string title; |
|||
|
|||
public NavigationPage(Widget body = null, string title = null) { |
|||
this.title = title; |
|||
this.body = body; |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
Widget back = null; |
|||
if (Navigator.of(context).canPop()) { |
|||
back = new CustomButton(onPressed: () => { Navigator.pop<object>(context); }, |
|||
child: new Text("Go Back")); |
|||
back = new Column(mainAxisAlignment: MainAxisAlignment.center, children: new List<Widget>() {back}); |
|||
} |
|||
|
|||
|
|||
return new Container( |
|||
child: new Column( |
|||
children: new List<Widget>() { |
|||
new ConstrainedBox(constraints: new BoxConstraints(maxHeight: 80), |
|||
child: new DecoratedBox( |
|||
decoration: new BoxDecoration(color: new Color(0XFFE1ECF4)), |
|||
child: new NavigationToolbar(leading: back, |
|||
middle: new Text(this.title, textAlign: TextAlign.center)))), |
|||
new Flexible(child: this.body) |
|||
} |
|||
) |
|||
); |
|||
} |
|||
} |
|||
|
|||
static class _Dialog { |
|||
public static void showDialog(BuildContext context, |
|||
bool barrierDismissible = true, WidgetBuilder builder = null) { |
|||
DialogUtils.showGeneralDialog<object>( |
|||
context: context, |
|||
pageBuilder: (BuildContext buildContext, Animation<float> animation, |
|||
Animation<float> secondaryAnimation) => { |
|||
return builder(buildContext); |
|||
}, |
|||
barrierDismissible: barrierDismissible, |
|||
barrierColor: new Color(0x8A000000), |
|||
transitionDuration: TimeSpan.FromMilliseconds(150), |
|||
transitionBuilder: _buildMaterialDialogTransitions |
|||
); |
|||
} |
|||
|
|||
static Widget _buildMaterialDialogTransitions(BuildContext context, |
|||
Animation<float> animation, Animation<float> secondaryAnimation, Widget child) { |
|||
return new FadeTransition( |
|||
opacity: new CurvedAnimation( |
|||
parent: animation, |
|||
curve: Curves.easeOut |
|||
), |
|||
child: child |
|||
); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 351f52ea9be972a48ad92328d8a99951 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class PageViewSample : UIWidgetsPanel { |
|||
|
|||
protected override void main() |
|||
{ |
|||
ui_.runApp(new MyApp()); |
|||
} |
|||
|
|||
class MyApp : StatelessWidget |
|||
{ |
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new WidgetsApp( |
|||
home: new Container( |
|||
width: 200, |
|||
height: 400, |
|||
child: new PageView( |
|||
children: new List<Widget>() { |
|||
new Container( |
|||
color: new Color(0xFFE91E63) |
|||
), |
|||
new Container( |
|||
color: new Color(0xFF00BCD4) |
|||
), |
|||
new Container( |
|||
color: new Color(0xFF673AB7) |
|||
) |
|||
} |
|||
)), |
|||
pageRouteBuilder: (settings, builder) => |
|||
new PageRouteBuilder( |
|||
settings: settings, |
|||
pageBuilder: (Buildcontext, animation, secondaryAnimation) => builder(context) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: dfec4b1201ff9494e83d2f2cc6e22f82 |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.engine2; |
|||
using Unity.UIWidgets.material; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
using ui_ = Unity.UIWidgets.widgets.ui_; |
|||
|
|||
namespace UIWidgetsSample { |
|||
public class ScrollbarSample : UIWidgetsPanel { |
|||
protected override void main() |
|||
{ |
|||
ui_.runApp(new MyApp()); |
|||
} |
|||
|
|||
class MyApp : StatelessWidget |
|||
{ |
|||
public override Widget build(BuildContext context) |
|||
{ |
|||
return new WidgetsApp( |
|||
home: new Container( |
|||
decoration: new BoxDecoration( |
|||
border: Border.all(color: new Color(0xFFFFFF00)) |
|||
), |
|||
child: new Scrollbar( |
|||
child: new ListView( |
|||
children: new List<Widget> { |
|||
new Container(height: 40.0f, child: new Text("0")), |
|||
new Container(height: 40.0f, child: new Text("1")), |
|||
new Container(height: 40.0f, child: new Text("2")), |
|||
new Container(height: 40.0f, child: new Text("3")), |
|||
new Container(height: 40.0f, child: new Text("4")), |
|||
new Container(height: 40.0f, child: new Text("5")), |
|||
new Container(height: 40.0f, child: new Text("6")), |
|||
new Container(height: 40.0f, child: new Text("7")), |
|||
new Container(height: 40.0f, child: new Text("8")), |
|||
new Container(height: 40.0f, child: new Text("9")), |
|||
new Container(height: 40.0f, child: new Text("10")), |
|||
new Container(height: 40.0f, child: new Text("11")), |
|||
new Container(height: 40.0f, child: new Text("12")), |
|||
new Container(height: 40.0f, child: new Text("13")), |
|||
new Container(height: 40.0f, child: new Text("14")), |
|||
new Container(height: 40.0f, child: new Text("15")), |
|||
new Container(height: 40.0f, child: new Text("16")), |
|||
new Container(height: 40.0f, child: new Text("17")), |
|||
} |
|||
) |
|||
) |
|||
), |
|||
pageRouteBuilder: (settings, builder) => |
|||
new PageRouteBuilder( |
|||
settings: settings, |
|||
pageBuilder: (Buildcontext, animation, secondaryAnimation) => builder(context) |
|||
) |
|||
); |
|||
} |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0666abb393df1e44bb00b1cff94ad6ca |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue