浏览代码
Merge branch 'material' into 'master'
Merge branch 'material' into 'master'
Material app See merge request upm-packages/ui-widgets/com.unity.uiwidgets!93/main
Shenhua Gu
6 年前
当前提交
671eeb8d
共有 6 个文件被更改,包括 374 次插入 和 4 次删除
-
16Runtime/material/theme_data.cs
-
13Runtime/material/utils.cs
-
6Samples/UIWidgetSample/MaterialSample.cs
-
126Runtime/material/app.cs
-
66Runtime/material/page.cs
-
151Runtime/material/page_transitions_theme.cs
|
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.material { |
|||
public class MaterialApp : StatefulWidget { |
|||
public MaterialApp( |
|||
Key key = null, |
|||
GlobalKey<NavigatorState> navigatorKey = null, |
|||
Widget home = null, |
|||
Dictionary<string, WidgetBuilder> routes = null, |
|||
string initialRoute = null, |
|||
RouteFactory onGenerateRoute = null, |
|||
RouteFactory onUnknownRoute = null, |
|||
List<NavigatorObserver> navigatorObservers = null, |
|||
TransitionBuilder builder = null, |
|||
string title = "", |
|||
Color color = null, |
|||
ThemeData theme = null, |
|||
bool showPerformanceOverlay = false, |
|||
Window window = null) : base(key: key) { |
|||
D.assert(window != null); |
|||
this.window = window; |
|||
this.navigatorKey = navigatorKey; |
|||
this.home = home; |
|||
this.routes = routes ?? new Dictionary<string, WidgetBuilder>(); |
|||
this.initialRoute = initialRoute; |
|||
this.onGenerateRoute = onGenerateRoute; |
|||
this.onUnknownRoute = onUnknownRoute; |
|||
this.navigatorObservers = navigatorObservers ?? new List<NavigatorObserver>(); |
|||
this.builder = builder; |
|||
this.title = title; |
|||
this.color = color; |
|||
this.theme = theme; |
|||
this.showPerformanceOverlay = showPerformanceOverlay; |
|||
} |
|||
|
|||
public readonly GlobalKey<NavigatorState> navigatorKey; |
|||
|
|||
public readonly Widget home; |
|||
|
|||
public readonly Dictionary<string, WidgetBuilder> routes; |
|||
|
|||
public readonly string initialRoute; |
|||
|
|||
public readonly RouteFactory onGenerateRoute; |
|||
|
|||
public readonly RouteFactory onUnknownRoute; |
|||
|
|||
public readonly List<NavigatorObserver> navigatorObservers; |
|||
|
|||
public readonly TransitionBuilder builder; |
|||
|
|||
public readonly string title; |
|||
|
|||
public readonly ThemeData theme; |
|||
|
|||
public readonly Color color; |
|||
|
|||
public readonly bool showPerformanceOverlay; |
|||
|
|||
public readonly Window window; |
|||
|
|||
|
|||
public override State createState() { |
|||
return new _MaterialAppState(); |
|||
} |
|||
} |
|||
|
|||
|
|||
class _MaterialAppState : State<MaterialApp> { |
|||
public override void initState() { |
|||
base.initState(); |
|||
this._updateNavigator(); |
|||
} |
|||
|
|||
public override void didUpdateWidget(StatefulWidget oldWidget) { |
|||
base.didUpdateWidget(oldWidget); |
|||
this._updateNavigator(); |
|||
} |
|||
|
|||
List<NavigatorObserver> _navigatorObservers; |
|||
|
|||
void _updateNavigator() { |
|||
if (this.widget.home != null || |
|||
this.widget.routes.isNotEmpty() || |
|||
this.widget.onGenerateRoute != null || |
|||
this.widget.onUnknownRoute != null) { |
|||
this._navigatorObservers = new List<NavigatorObserver>(this.widget.navigatorObservers); |
|||
} |
|||
else { |
|||
this._navigatorObservers = null; |
|||
} |
|||
} |
|||
|
|||
RectTween _createRectTween(Rect begin, Rect end) { |
|||
return new MaterialRectArcTween(begin: begin, end: end); |
|||
} |
|||
|
|||
public override Widget build(BuildContext context) { |
|||
ThemeData theme = this.widget.theme ?? ThemeData.fallback(); |
|||
Widget result = new AnimatedTheme( |
|||
data: theme, |
|||
isMaterialAppTheme: true, |
|||
child: new WidgetsApp( |
|||
key: new GlobalObjectKey<State>(this), |
|||
navigatorKey: this.widget.navigatorKey, |
|||
navigatorObservers: this._navigatorObservers, |
|||
pageRouteBuilder: (RouteSettings settings, WidgetBuilder builder) => |
|||
new MaterialPageRoute(settings: settings, builder: builder), |
|||
home: this.widget.home, |
|||
routes: this.widget.routes, |
|||
initialRoute: this.widget.initialRoute, |
|||
onGenerateRoute: this.widget.onGenerateRoute, |
|||
onUnknownRoute: this.widget.onUnknownRoute, |
|||
builder: this.widget.builder, |
|||
textStyle: AppUtils._errorTextStyle |
|||
) |
|||
); |
|||
|
|||
return result; |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.material { |
|||
public class MaterialPageRoute : PageRoute { |
|||
public MaterialPageRoute( |
|||
WidgetBuilder builder = null, |
|||
RouteSettings settings = null, |
|||
bool maintainState = true, |
|||
bool fullscreenDialog = false) : base(settings: settings, fullscreenDialog: fullscreenDialog) { |
|||
D.assert(builder != null); |
|||
this.builder = builder; |
|||
this.maintainState = maintainState; |
|||
D.assert(this.opaque); |
|||
} |
|||
|
|||
public readonly WidgetBuilder builder; |
|||
|
|||
public override bool maintainState { get; } |
|||
|
|||
public override TimeSpan transitionDuration { |
|||
get { return new TimeSpan(0, 0, 0, 0, 300); } |
|||
} |
|||
|
|||
public override Color barrierColor { |
|||
get { return null; } |
|||
} |
|||
|
|||
public override string barrierLabel { |
|||
get { return null; } |
|||
} |
|||
|
|||
public override bool canTransitionFrom(TransitionRoute previousRoute) { |
|||
return previousRoute is MaterialPageRoute; |
|||
} |
|||
|
|||
public override bool canTransitionTo(TransitionRoute nextRoute) { |
|||
return nextRoute is MaterialPageRoute && !((MaterialPageRoute) nextRoute).fullscreenDialog; |
|||
} |
|||
|
|||
public override Widget buildPage(BuildContext context, Animation<float> animation, |
|||
Animation<float> secondaryAnimation) { |
|||
Widget result = this.builder(context); |
|||
D.assert(() => { |
|||
if (result == null) { |
|||
throw new UIWidgetsError( |
|||
"The builder for route " + this.settings.name + "returned null. \n" + |
|||
"Route builders must never return null." |
|||
); |
|||
} |
|||
|
|||
return true; |
|||
}); |
|||
return result; |
|||
} |
|||
|
|||
public override Widget buildTransitions(BuildContext context, Animation<float> animation, |
|||
Animation<float> secondaryAnimation, Widget child) { |
|||
PageTransitionsTheme theme = Theme.of(context).pageTransitionsTheme; |
|||
return theme.buildTranstions(this, context, animation, secondaryAnimation, child); |
|||
} |
|||
} |
|||
} |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using Unity.UIWidgets.animation; |
|||
using Unity.UIWidgets.foundation; |
|||
using Unity.UIWidgets.ui; |
|||
using Unity.UIWidgets.widgets; |
|||
|
|||
namespace Unity.UIWidgets.material { |
|||
public class _FadeUpwardsPageTransition : StatelessWidget { |
|||
public _FadeUpwardsPageTransition( |
|||
Key key = null, |
|||
Animation<float> routeAnimation = null, |
|||
Widget child = null) : base(key: key) { |
|||
D.assert(routeAnimation != null); |
|||
D.assert(child != null); |
|||
this._positionAnimation = routeAnimation.drive(_bottomUpTween.chain(_fastOutSlowInTween)); |
|||
this._opacityAnimation = routeAnimation.drive(_easeInTween); |
|||
this.child = child; |
|||
} |
|||
|
|||
static readonly Tween<Offset> _bottomUpTween = new OffsetTween( |
|||
begin: new Offset(0.0f, 0.25f), |
|||
end: Offset.zero |
|||
); |
|||
|
|||
static readonly Animatable<float> _fastOutSlowInTween = new CurveTween( |
|||
curve: Curves.fastOutSlowIn); |
|||
|
|||
static readonly Animatable<float> _easeInTween = new CurveTween( |
|||
curve: Curves.easeIn); |
|||
|
|||
public readonly Animation<Offset> _positionAnimation; |
|||
public 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)); |
|||
} |
|||
} |
|||
|
|||
public abstract class PageTransitionsBuilder { |
|||
public PageTransitionsBuilder() { |
|||
} |
|||
|
|||
public abstract Widget buildTransitions( |
|||
PageRoute route, |
|||
BuildContext context, |
|||
Animation<float> animation, |
|||
Animation<float> secondaryAnimation, |
|||
Widget child); |
|||
} |
|||
|
|||
|
|||
public class FadeUpwardsPageTransitionsBuilder : PageTransitionsBuilder { |
|||
public FadeUpwardsPageTransitionsBuilder() { |
|||
} |
|||
|
|||
public override Widget buildTransitions( |
|||
PageRoute route, |
|||
BuildContext context, |
|||
Animation<float> animation, |
|||
Animation<float> secondaryAnimation, |
|||
Widget child) { |
|||
return new _FadeUpwardsPageTransition( |
|||
routeAnimation: animation, |
|||
child: child); |
|||
} |
|||
} |
|||
|
|||
public class PageTransitionsTheme : Diagnosticable, IEquatable<PageTransitionsTheme> { |
|||
public PageTransitionsTheme( |
|||
PageTransitionsBuilder builder = null) { |
|||
this._builder = builder; |
|||
} |
|||
|
|||
static PageTransitionsBuilder _defaultBuilder = new FadeUpwardsPageTransitionsBuilder(); |
|||
|
|||
public PageTransitionsBuilder builder { |
|||
get { return this._builder ?? _defaultBuilder; } |
|||
} |
|||
|
|||
readonly PageTransitionsBuilder _builder; |
|||
|
|||
public Widget buildTranstions( |
|||
PageRoute route, |
|||
BuildContext context, |
|||
Animation<float> animation, |
|||
Animation<float> secondaryAnimation, |
|||
Widget child) { |
|||
PageTransitionsBuilder matchingBuilder = this.builder; |
|||
return matchingBuilder.buildTransitions(route, context, animation, secondaryAnimation, child); |
|||
} |
|||
|
|||
List<PageTransitionsBuilder> _all(PageTransitionsBuilder builder) { |
|||
return new List<PageTransitionsBuilder> {this.builder}; |
|||
} |
|||
|
|||
public bool Equals(PageTransitionsTheme other) { |
|||
if (ReferenceEquals(null, other)) { |
|||
return false; |
|||
} |
|||
|
|||
if (ReferenceEquals(this, other)) { |
|||
return true; |
|||
} |
|||
|
|||
return this._all(this.builder) == this._all(other.builder); |
|||
} |
|||
|
|||
public override bool Equals(object obj) { |
|||
if (ReferenceEquals(null, obj)) { |
|||
return false; |
|||
} |
|||
|
|||
if (ReferenceEquals(this, obj)) { |
|||
return true; |
|||
} |
|||
|
|||
if (obj.GetType() != this.GetType()) { |
|||
return false; |
|||
} |
|||
|
|||
return this.Equals((PageTransitionsTheme) obj); |
|||
} |
|||
|
|||
public static bool operator ==(PageTransitionsTheme left, PageTransitionsTheme right) { |
|||
return Equals(left, right); |
|||
} |
|||
|
|||
public static bool operator !=(PageTransitionsTheme left, PageTransitionsTheme right) { |
|||
return !Equals(left, right); |
|||
} |
|||
|
|||
public override int GetHashCode() { |
|||
unchecked { |
|||
var hashCode = this._all(this.builder).GetHashCode(); |
|||
return hashCode; |
|||
} |
|||
} |
|||
|
|||
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) { |
|||
base.debugFillProperties(properties); |
|||
properties.add(new DiagnosticsProperty<PageTransitionsBuilder>("builder", this.builder, |
|||
defaultValue: _defaultBuilder)); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue