浏览代码

material app

/main
xingwei.zhu 6 年前
当前提交
0c68b388
共有 5 个文件被更改,包括 373 次插入0 次删除
  1. 16
      Runtime/material/theme_data.cs
  2. 13
      Runtime/material/utils.cs
  3. 127
      Runtime/material/app.cs
  4. 66
      Runtime/material/page.cs
  5. 151
      Runtime/material/page_transitions_theme.cs

16
Runtime/material/theme_data.cs


IconThemeData primaryIconTheme = null,
IconThemeData accentIconTheme = null,
MaterialTapTargetSize? materialTapTargetSize = null,
PageTransitionsTheme pageTransitionsTheme = null,
ColorScheme colorScheme = null,
Typography typography = null
) {

hintColor = hintColor ?? (isDark ? new Color(0x80FFFFFF) : new Color(0x8A000000));
errorColor = errorColor ?? Colors.red[700];
pageTransitionsTheme = pageTransitionsTheme ?? new PageTransitionsTheme();
primaryIconTheme = primaryIconTheme ??
(primaryIsDark
? new IconThemeData(color: Colors.white)

D.assert(primaryIconTheme != null);
D.assert(accentIconTheme != null);
D.assert(materialTapTargetSize != null);
D.assert(pageTransitionsTheme != null);
D.assert(colorScheme != null);
D.assert(typography != null);

this.primaryIconTheme = primaryIconTheme;
this.accentIconTheme = accentIconTheme;
this.materialTapTargetSize = materialTapTargetSize ?? MaterialTapTargetSize.padded;
this.pageTransitionsTheme = pageTransitionsTheme;
this.colorScheme = colorScheme;
this.typography = typography;
}

IconThemeData primaryIconTheme,
IconThemeData accentIconTheme,
MaterialTapTargetSize? materialTapTargetSize,
PageTransitionsTheme pageTransitionsTheme,
ColorScheme colorScheme,
Typography typography
) {

D.assert(primaryIconTheme != null);
D.assert(accentIconTheme != null);
D.assert(materialTapTargetSize != null);
D.assert(pageTransitionsTheme != null);
D.assert(colorScheme != null);
D.assert(typography != null);

primaryIconTheme: primaryIconTheme,
accentIconTheme: accentIconTheme,
materialTapTargetSize: materialTapTargetSize,
pageTransitionsTheme: pageTransitionsTheme,
colorScheme: colorScheme,
typography: typography);
}

public readonly MaterialTapTargetSize materialTapTargetSize;
public readonly PageTransitionsTheme pageTransitionsTheme;
public readonly ColorScheme colorScheme;
public readonly Typography typography;

IconThemeData primaryIconTheme,
IconThemeData accentIconTheme,
MaterialTapTargetSize? materialTapTargetSize,
PageTransitionsTheme pageTransitionsTheme,
ColorScheme colorScheme,
Typography typography
) {

primaryIconTheme: primaryIconTheme ?? this.primaryIconTheme,
accentIconTheme: accentIconTheme ?? this.accentIconTheme,
materialTapTargetSize: materialTapTargetSize ?? this.materialTapTargetSize,
pageTransitionsTheme: pageTransitionsTheme ?? this.pageTransitionsTheme,
colorScheme: colorScheme ?? this.colorScheme,
typography: typography ?? this.typography
);

primaryIconTheme: IconThemeData.lerp(a.primaryIconTheme, b.primaryIconTheme, t),
accentIconTheme: IconThemeData.lerp(a.accentIconTheme, b.accentIconTheme, t),
materialTapTargetSize: t < 0.5 ? a.materialTapTargetSize : b.materialTapTargetSize,
pageTransitionsTheme: t < 0.5 ? a.pageTransitionsTheme : b.pageTransitionsTheme,
colorScheme: ColorScheme.lerp(a.colorScheme, b.colorScheme, t),
typography: Typography.lerp(a.typography, b.typography, t)
);

other.primaryIconTheme == this.primaryIconTheme &&
other.accentIconTheme == this.accentIconTheme &&
other.materialTapTargetSize == this.materialTapTargetSize &&
other.pageTransitionsTheme == this.pageTransitionsTheme &&
other.colorScheme == this.colorScheme &&
other.typography == this.typography;
}

hashCode = (hashCode * 397) ^ this.primaryIconTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.accentIconTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.materialTapTargetSize.GetHashCode();
hashCode = (hashCode * 397) ^ this.pageTransitionsTheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.colorScheme.GetHashCode();
hashCode = (hashCode * 397) ^ this.typography.GetHashCode();
return hashCode;

properties.add(new DiagnosticsProperty<IconThemeData>("accentIconTheme", this.accentIconTheme));
properties.add(
new DiagnosticsProperty<MaterialTapTargetSize>("materialTapTargetSize", this.materialTapTargetSize));
properties.add(
new DiagnosticsProperty<PageTransitionsTheme>("pageTransitionsTheme", this.pageTransitionsTheme));
properties.add(new DiagnosticsProperty<ColorScheme>("colorScheme", this.colorScheme,
defaultValue: defaultData.colorScheme));
properties.add(new DiagnosticsProperty<Typography>("typography", this.typography,

13
Runtime/material/utils.cs


using Unity.UIWidgets.ui;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.material {
public static class ThemeDataUtils {

public static class TooltipUtils {
public static readonly TimeSpan _kFadeDuration = new TimeSpan(0, 0, 0, 0, 200);
public static readonly TimeSpan _kShowDuration = new TimeSpan(0, 0, 0, 0, 1500);
}
public static class AppUtils {
public static readonly TextStyle _errorTextStyle = new TextStyle(
color: new Color(0xD0FF0000),
fontFamily: "monospace",
fontSize: 48.0f,
fontWeight: FontWeight.w700,
decoration: TextDecoration.underline,
decorationColor: new Color(0xFFFFFF00),
decorationStyle: TextDecorationStyle.doubleLine
);
}
}

127
Runtime/material/app.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,
window: this.widget.window,
textStyle: AppUtils._errorTextStyle
)
);
return result;
}
}
}

66
Runtime/material/page.cs


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);
}
}
}

151
Runtime/material/page_transitions_theme.cs


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));
}
}
}
正在加载...
取消
保存