guanghuispark
3 年前
当前提交
e702d769
共有 7 个文件被更改,包括 454 次插入 和 275 次删除
-
430AwesomeUIWidgets/Assets/Scenes/ItemPickerRoom.unity
-
16AwesomeUIWidgets/Assets/Scripts/ChatPage.cs
-
2AwesomeUIWidgets/Assets/Scripts/ChatPanelDemo.cs
-
57AwesomeUIWidgets/Assets/Scripts/DateAndTimePicker.cs
-
2AwesomeUIWidgets/Assets/Scripts/Widgets/chat_list.cs
-
219AwesomeUIWidgets/Assets/Scripts/Widgets/ModalPage.cs
-
3AwesomeUIWidgets/Assets/Scripts/Widgets/ModalPage.cs.meta
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.painting; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace UIWidgetsSample |
|||
{ |
|||
public static class ModalPage |
|||
{ |
|||
public static void popup( |
|||
BuildContext context, |
|||
Widget child, |
|||
Widget overlay = null, |
|||
VoidCallback onPop = null, |
|||
bool justFade = false |
|||
) |
|||
{ |
|||
PopupRoute route; |
|||
if (justFade) |
|||
{ |
|||
route = new _FadePopupRoute( |
|||
cxt => child, |
|||
overlay == null |
|||
? (WidgetBuilder) null |
|||
: ctx => overlay, |
|||
"Dismiss" |
|||
); |
|||
} |
|||
else |
|||
{ |
|||
route = new _ModalPopupRoute( |
|||
cxt => child, |
|||
overlay == null |
|||
? (WidgetBuilder) null |
|||
: ctx => overlay, |
|||
"Dismiss" |
|||
); |
|||
} |
|||
Navigator.push<object>(context, route).then_(_ => onPop?.Invoke()); |
|||
} |
|||
|
|||
public static void dismiss(BuildContext context) |
|||
{ |
|||
// if (Navigator.canPop(context))
|
|||
{ |
|||
Navigator.pop(context); |
|||
} |
|||
} |
|||
} |
|||
|
|||
internal class _ModalPopupRoute : PopupRoute |
|||
{ |
|||
public _ModalPopupRoute( |
|||
WidgetBuilder builder = null, |
|||
WidgetBuilder overlayBuilder = null, |
|||
string barrierLabel = "", |
|||
RouteSettings settings = null |
|||
) : base(settings) |
|||
{ |
|||
this.builder = builder; |
|||
this.barrierLabel = barrierLabel; |
|||
this.overlayBuilder = overlayBuilder; |
|||
} |
|||
|
|||
private readonly WidgetBuilder builder; |
|||
|
|||
private readonly WidgetBuilder overlayBuilder; |
|||
|
|||
public string barrierLabel { get; } |
|||
|
|||
public override Color barrierColor => new Color(0x6604040F); |
|||
|
|||
public override bool barrierDismissible => true; |
|||
|
|||
public override TimeSpan transitionDuration => TimeSpan.FromMilliseconds(335); |
|||
|
|||
private AnimationController _animationController; |
|||
|
|||
private Animation<float> _animation; |
|||
|
|||
private Tween<Offset> _offsetTween; |
|||
|
|||
private Tween<float> _opacityTween; |
|||
|
|||
public override Animation<float> createAnimation() |
|||
{ |
|||
D.assert(_animation == null); |
|||
_animation = new CurvedAnimation( |
|||
base.createAnimation(), |
|||
Curves.linearToEaseOut, |
|||
Curves.linearToEaseOut.flipped |
|||
); |
|||
_offsetTween = new OffsetTween( |
|||
new Offset(0, 1), |
|||
new Offset(0, 0) |
|||
); |
|||
_opacityTween = new FloatTween(0, 1); |
|||
return _animation; |
|||
} |
|||
|
|||
public override Widget buildPage(BuildContext context, Animation<float> animation, |
|||
Animation<float> secondaryAnimation) |
|||
{ |
|||
return builder(context); |
|||
} |
|||
|
|||
public override Widget buildTransitions(BuildContext context, Animation<float> animation, |
|||
Animation<float> secondaryAnimation, Widget child) |
|||
{ |
|||
Widget result = new Align( |
|||
alignment: Alignment.bottomCenter, |
|||
child: new FractionalTranslation( |
|||
translation: _offsetTween.evaluate(_animation), |
|||
child: child |
|||
) |
|||
); |
|||
|
|||
if (overlayBuilder != null) |
|||
{ |
|||
result = new Stack( |
|||
children: new List<Widget> |
|||
{ |
|||
Positioned.fill( |
|||
new Opacity( |
|||
opacity: _opacityTween.evaluate(_animation), |
|||
child: overlayBuilder(context) |
|||
) |
|||
), |
|||
result |
|||
}); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
} |
|||
|
|||
internal class _FadePopupRoute : PopupRoute |
|||
{ |
|||
public _FadePopupRoute( |
|||
WidgetBuilder builder = null, |
|||
WidgetBuilder overlayBuilder = null, |
|||
string barrierLabel = "", |
|||
RouteSettings settings = null |
|||
) : base(settings) |
|||
{ |
|||
this.builder = builder; |
|||
this.barrierLabel = barrierLabel; |
|||
this.overlayBuilder = overlayBuilder; |
|||
} |
|||
|
|||
private readonly WidgetBuilder builder; |
|||
|
|||
private readonly WidgetBuilder overlayBuilder; |
|||
|
|||
public string barrierLabel { get; } |
|||
|
|||
public override Color barrierColor => new Color(0x6604040F); |
|||
|
|||
public override bool barrierDismissible => true; |
|||
|
|||
public override TimeSpan transitionDuration => TimeSpan.FromMilliseconds(335); |
|||
|
|||
private AnimationController _animationController; |
|||
|
|||
private Animation<float> _animation; |
|||
|
|||
private Tween<float> _opacityTween; |
|||
|
|||
public override Animation<float> createAnimation() |
|||
{ |
|||
D.assert(_animation == null); |
|||
_animation = new CurvedAnimation( |
|||
base.createAnimation(), |
|||
Curves.linearToEaseOut, |
|||
Curves.linearToEaseOut.flipped |
|||
); |
|||
_opacityTween = new FloatTween(0, 1); |
|||
return _animation; |
|||
} |
|||
|
|||
public override Widget buildPage(BuildContext context, Animation<float> animation, |
|||
Animation<float> secondaryAnimation) |
|||
{ |
|||
return builder(context); |
|||
} |
|||
|
|||
public override Widget buildTransitions(BuildContext context, Animation<float> animation, |
|||
Animation<float> secondaryAnimation, Widget child) |
|||
{ |
|||
Widget result = new Align( |
|||
alignment: Alignment.bottomCenter, |
|||
child: new Opacity( |
|||
opacity: _opacityTween.evaluate(_animation), |
|||
child: child |
|||
) |
|||
); |
|||
|
|||
if (overlayBuilder != null) |
|||
{ |
|||
result = new Stack( |
|||
children: new List<Widget> |
|||
{ |
|||
Positioned.fill( |
|||
new Opacity( |
|||
opacity: _opacityTween.evaluate(_animation), |
|||
child: overlayBuilder(context) |
|||
) |
|||
), |
|||
result |
|||
}); |
|||
} |
|||
|
|||
return result; |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: b9198d8d6d624e3e80f7e2c2d55145e0 |
|||
timeCreated: 1627638464 |
撰写
预览
正在加载...
取消
保存
Reference in new issue