浏览代码

Tmp store.

/main
Yuncong Zhang 6 年前
当前提交
b7d08cf5
共有 7 个文件被更改,包括 159 次插入92 次删除
  1. 2
      Runtime/foundation/constants.cs
  2. 17
      Runtime/widgets/media_query.cs
  3. 105
      Runtime/widgets/navigator.cs
  4. 3
      Runtime/widgets/notification_listener.cs
  5. 3
      Runtime/widgets/overlay.cs
  6. 1
      Runtime/widgets/routes.cs
  7. 120
      Runtime/widgets/scroll_view.cs

2
Runtime/foundation/constants.cs


namespace Unity.UIWidgets.foundation {
public class FoundationConstants {
public bool kReleaseMode = !Debug.isDebugBuild;
public static bool kReleaseMode = !Debug.isDebugBuild;
}
}

17
Runtime/widgets/media_query.cs


using System;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.service;
using Unity.UIWidgets.ui;
namespace Unity.UIWidgets.widgets {

Size size = null,
float devicePixelRatio = 1.0f,
float textScaleFactor = 1.0f,
Brightness platformBrightness = Brightness.light,
EdgeInsets viewInsets = null,
EdgeInsets padding = null,
bool alwaysUse24HourFormat = false,

this.size = size ?? Size.zero;
this.devicePixelRatio = devicePixelRatio;
this.textScaleFactor = textScaleFactor;
this.platformBrightness = platformBrightness;
this.viewInsets = viewInsets ?? EdgeInsets.zero;
this.padding = padding ?? EdgeInsets.zero;
this.alwaysUse24HourFormat = alwaysUse24HourFormat;

size: window.physicalSize / window.devicePixelRatio,
devicePixelRatio: window.devicePixelRatio,
textScaleFactor: window.textScaleFactor,
// platformBrightness: window.platformBrightness, // TODO: remove comment when window.platformBrightness is ready
viewInsets: EdgeInsets.fromWindowPadding(window.viewInsets, window.devicePixelRatio),
padding: EdgeInsets.fromWindowPadding(window.padding, window.devicePixelRatio)
// accessibleNavigation: window.accessibilityFeatures.accessibleNavigation,

public readonly float textScaleFactor;
public readonly Brightness platformBrightness;
public readonly EdgeInsets viewInsets;
public readonly EdgeInsets padding;

Size size = null,
float? devicePixelRatio = null,
float? textScaleFactor = null,
Brightness? platformBrightness = null,
EdgeInsets viewInsets = null,
EdgeInsets padding = null,
bool? alwaysUse24HourFormat = null,

size: size ?? this.size,
devicePixelRatio: devicePixelRatio ?? this.devicePixelRatio,
textScaleFactor: textScaleFactor ?? this.textScaleFactor,
platformBrightness: platformBrightness ?? this.platformBrightness,
viewInsets: viewInsets ?? this.viewInsets,
padding: padding ?? this.padding,
alwaysUse24HourFormat: alwaysUse24HourFormat ?? this.alwaysUse24HourFormat,

size: this.size,
devicePixelRatio: this.devicePixelRatio,
textScaleFactor: this.textScaleFactor,
platformBrightness: this.platformBrightness,
padding: this.padding.copyWith(
left: removeLeft ? (float?) 0.0 : null,
top: removeTop ? (float?) 0.0 : null,

size: this.size,
devicePixelRatio: this.devicePixelRatio,
textScaleFactor: this.textScaleFactor,
platformBrightness: this.platformBrightness,
padding: this.padding,
viewInsets: this.viewInsets.copyWith(
left: removeLeft ? (float?) 0.0 : null,

return Equals(this.size, other.size) && this.devicePixelRatio.Equals(other.devicePixelRatio) &&
this.textScaleFactor.Equals(other.textScaleFactor) &&
Equals(this.platformBrightness, other.platformBrightness) &&
Equals(this.viewInsets, other.viewInsets) &&
Equals(this.padding, other.padding) &&
this.alwaysUse24HourFormat == other.alwaysUse24HourFormat &&

var hashCode = (this.size != null ? this.size.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ this.devicePixelRatio.GetHashCode();
hashCode = (hashCode * 397) ^ this.textScaleFactor.GetHashCode();
hashCode = (hashCode * 397) ^ this.platformBrightness.GetHashCode();
hashCode = (hashCode * 397) ^ (this.viewInsets != null ? this.viewInsets.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ (this.padding != null ? this.padding.GetHashCode() : 0);
hashCode = (hashCode * 397) ^ this.alwaysUse24HourFormat.GetHashCode();

$"size: {this.size}, " +
$"devicePixelRatio: {this.devicePixelRatio:F1}, " +
$"textScaleFactor: {this.textScaleFactor:F1}, " +
$"platformBrightness: {this.platformBrightness}, " +
$"padding: {this.padding}, " +
$"viewInsets: {this.viewInsets}, " +
$"alwaysUse24HourFormat: {this.alwaysUse24HourFormat}, " +

public static float textScaleFactorOf(BuildContext context) {
return of(context, nullOk: true)?.textScaleFactor ?? 1.0f;
}
public static Brightness platformBrightnessOf(BuildContext context) {
return of(context, nullOk: true)?.platformBrightness ?? Brightness.light;
}
public static bool boldTextOverride(BuildContext context) {

105
Runtime/widgets/navigator.cs


}
public class RouteSettings {
public RouteSettings(string name = null, bool isInitialRoute = false) {
public RouteSettings(string name = null, bool isInitialRoute = false, object arguments = null) {
this.arguments = arguments;
RouteSettings copyWith(string name = null, bool? isInitialRoute = null) {
RouteSettings copyWith(string name = null, bool? isInitialRoute = null, object arguments = null) {
isInitialRoute ?? this.isInitialRoute
isInitialRoute ?? this.isInitialRoute,
arguments ?? this.arguments
);
}

public readonly object arguments;
return $"\"{this.name}\"";
return $"{this.GetType()}(\"{this.name}\", {this.arguments})";
}
}

public static readonly string defaultRouteName = "/";
public static IPromise<object> pushNamed(BuildContext context, string routeName) {
return Navigator.of(context).pushNamed(routeName);
public static IPromise<object> pushNamed(BuildContext context, string routeName, object arguments = null) {
return of(context).pushNamed(routeName, arguments: arguments);
object result = null) {
return Navigator.of(context).pushReplacementNamed(routeName, result: result);
object result = null, object arguments = null) {
return of(context).pushReplacementNamed(routeName, result: result, arguments: arguments);
public static IPromise<object> popAndPushNamed(BuildContext context, string routeName, object result = null) {
return Navigator.of(context).popAndPushNamed(routeName, result: result);
public static IPromise<object> popAndPushNamed(BuildContext context, string routeName, object result = null,
object arguments = null) {
return of(context).popAndPushNamed(routeName, result: result, arguments: arguments);
RoutePredicate predicate) {
return Navigator.of(context).pushNamedAndRemoveUntil(newRouteName, predicate);
RoutePredicate predicate, object arguments = null) {
return of(context).pushNamedAndRemoveUntil(newRouteName, predicate, arguments: arguments);
return Navigator.of(context).push(route);
return of(context).push(route);
return Navigator.of(context).pushReplacement(newRoute, result);
return of(context).pushReplacement(newRoute, result);
return Navigator.of(context).pushAndRemoveUntil(newRoute, predicate);
return of(context).pushAndRemoveUntil(newRoute, predicate);
Navigator.of(context).replace(oldRoute: oldRoute, newRoute: newRoute);
of(context).replace(oldRoute: oldRoute, newRoute: newRoute);
Navigator.of(context).replaceRouteBelow(anchorRoute: anchorRoute, newRoute: newRoute);
of(context).replaceRouteBelow(anchorRoute: anchorRoute, newRoute: newRoute);
NavigatorState navigator = Navigator.of(context, nullOk: true);
NavigatorState navigator = of(context, nullOk: true);
return Navigator.of(context).maybePop(result);
return of(context).maybePop(result);
return Navigator.of(context).pop(result);
return of(context).pop(result);
Navigator.of(context).popUntil(predicate);
of(context).popUntil(predicate);
Navigator.of(context).removeRoute(route);
of(context).removeRoute(route);
Navigator.of(context).removeRouteBelow(anchorRoute);
of(context).removeRouteBelow(anchorRoute);
}
public static NavigatorState of(

readonly GlobalKey<OverlayState> _overlayKey = GlobalKey<OverlayState>.key();
internal readonly List<Route> _history = new List<Route>();
readonly HashSet<Route> _poppedRoutes = new HashSet<Route>();
public readonly FocusScopeNode focusScopeNode = new FocusScopeNode();
readonly List<OverlayEntry> _initialOverlayEntries = new List<OverlayEntry>();

Navigator.defaultRouteName
};
var plannedInitialRoutes = new List<Route> {
this._routeNamed(Navigator.defaultRouteName, true)
this._routeNamed(Navigator.defaultRouteName, arguments: null, true)
};
var routeParts = initialRouteName.Split('/');

routeName += $"/{part}";
plannedInitialRouteNames.Add(routeName);
plannedInitialRoutes.Add(this._routeNamed(routeName, true));
plannedInitialRoutes.Add(this._routeNamed(routeName, arguments: null, true));
}
}

$"ignored and \"{Navigator.defaultRouteName}\" will be used instead.")));
return true;
});
this.push(this._routeNamed(Navigator.defaultRouteName));
} else {
this.push(this._routeNamed(Navigator.defaultRouteName, arguments: null));
}
else {
} else {
}
else {
route = this._routeNamed(initialRouteName, true);
route = this._routeNamed(initialRouteName, arguments: null, true);
route = route ?? this._routeNamed(Navigator.defaultRouteName);
route = route ?? this._routeNamed(Navigator.defaultRouteName, arguments: null);
this.push(route);
}

}
public override void didUpdateWidget(StatefulWidget oldWidget) {
base.didUpdateWidget(oldWidget);
if (((Navigator) oldWidget).observers != this.widget.observers) {

return true;
});
}
public OverlayState overlay {
get { return this._overlayKey.currentState; }
}

bool _debugLocked;
Route _routeNamed(string name, bool allowNull = false) {
Route _routeNamed(string name, object arguments, bool allowNull = false) {
isInitialRoute: this._history.isEmpty()
isInitialRoute: this._history.isEmpty(),
arguments: arguments
var route = (Route) this.widget.onGenerateRoute(settings);
if (route == null && !allowNull) {
D.assert(() => {

return route;
}
public IPromise<object> pushNamed(string routeName) {
return this.push(this._routeNamed(routeName));
public IPromise<object> pushNamed(string routeName, object arguments = null) {
return this.push(this._routeNamed(routeName, arguments: arguments));
public IPromise<object> pushReplacementNamed(string routeName, object result = null) {
return this.pushReplacement(this._routeNamed(routeName), result);
public IPromise<object> pushReplacementNamed(string routeName, object result = null, object arguments = null) {
return this.pushReplacement(this._routeNamed(routeName, arguments: arguments), result);
public IPromise<object> popAndPushNamed(string routeName, object result = null) {
public IPromise<object> popAndPushNamed(string routeName, object result = null, object arguments = null) {
return this.pushNamed(routeName);
return this.pushNamed(routeName, arguments: arguments);
public IPromise<object> pushNamedAndRemoveUntil(string newRouteName, RoutePredicate predicate) {
return this.pushAndRemoveUntil(this._routeNamed(newRouteName), predicate);
public IPromise<object> pushNamedAndRemoveUntil(string newRouteName, RoutePredicate predicate,
object arguments = null) {
return this.pushAndRemoveUntil(this._routeNamed(newRouteName, arguments: arguments), predicate);
}
public IPromise<object> push(Route route) {

this._poppedRoutes.Remove(route);
route.dispose();
}
public bool userGestureInProgress {
get { return this._userGesturesInProgress > 0; }
}

}
});
}
this._activePointers.ToList().ForEach(WidgetsBinding.instance.cancelPointer);
}

3
Runtime/widgets/notification_listener.cs


}
public void dispatch(BuildContext target) {
D.assert(target != null);
target.visitAncestorElements(this.visitAncestor);
target?.visitAncestorElements(this.visitAncestor);
}
public override string ToString() {

3
Runtime/widgets/overlay.cs


internal void _remove(OverlayEntry entry) {
if (this.mounted) {
this._entries.Remove(entry);
/* entry was removed */
this._entries.Remove(entry);
});
}
}

1
Runtime/widgets/routes.cs


break;
case AnimationStatus.dismissed:
D.assert(!this.overlayEntries.first().opaque);
// We might still be the current route if a subclass is controlling the
// the transition and hits the dismissed status. For example, the iOS
// back gesture drives this animation to the dismissed status before

120
Runtime/widgets/scroll_view.cs


using System.Collections.Generic;
using com.unity.uiwidgets.Runtime.rendering;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using UnityEngine;

bool? primary = null,
ScrollPhysics physics = null,
bool shrinkWrap = false,
float? cacheExtent = null
Key center = null,
float anchor = 0.0f,
float? cacheExtent = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.down
D.assert(!shrinkWrap || center == null);
D.assert(anchor >= 0.0f && anchor <= 1.0f);
primary = primary ?? controller == null && scrollDirection == Axis.vertical;
physics = physics ?? (primary.Value ? new AlwaysScrollableScrollPhysics() : null);

this.primary = primary.Value;
this.physics = physics;
this.shrinkWrap = shrinkWrap;
this.center = center;
this.anchor = anchor;
this.dragStartBehavior = dragStartBehavior;
}
public readonly Axis scrollDirection;

public readonly ScrollPhysics physics;
public readonly bool shrinkWrap;
public readonly Key center;
public readonly float anchor;
public readonly DragStartBehavior dragStartBehavior;
protected AxisDirection getDirection(BuildContext context) {
return LayoutUtils.getAxisDirectionFromAxisReverseAndDirectionality(

axisDirection: axisDirection,
offset: offset,
slivers: slivers,
cacheExtent: this.cacheExtent
cacheExtent: this.cacheExtent,
center: this.center,
anchor: this.anchor
);
}

ScrollController scrollController = this.primary ? PrimaryScrollController.of(context) : this.controller;
Scrollable scrollable = new Scrollable(
dragStartBehavior: this.dragStartBehavior,
axisDirection: axisDirection,
controller: scrollController,
physics: this.physics,

bool? primary = null,
ScrollPhysics physics = null,
bool shrinkWrap = false,
Key center = null,
float anchor = 0.0f,
List<Widget> slivers = null
List<Widget> slivers = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.down
) : base(
key: key,
scrollDirection: scrollDirection,

physics: physics,
shrinkWrap: shrinkWrap,
cacheExtent: cacheExtent
center: center,
anchor: anchor,
cacheExtent: cacheExtent,
dragStartBehavior: dragStartBehavior
) {
this.slivers = slivers ?? new List<Widget>();
}

ScrollPhysics physics = null,
bool shrinkWrap = false,
EdgeInsets padding = null,
float? cacheExtent = null
float? cacheExtent = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.down
) : base(
key: key,
scrollDirection: scrollDirection,

physics: physics,
shrinkWrap: shrinkWrap,
cacheExtent: cacheExtent
cacheExtent: cacheExtent,
dragStartBehavior: dragStartBehavior
) {
this.padding = padding;
}

bool addAutomaticKeepAlives = true,
bool addRepaintBoundaries = true,
float? cacheExtent = null,
List<Widget> children = null
List<Widget> children = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.down
) : base(
key: key,
scrollDirection: scrollDirection,

physics: physics,
shrinkWrap: shrinkWrap,
padding: padding,
cacheExtent: cacheExtent
cacheExtent: cacheExtent,
dragStartBehavior: dragStartBehavior
) {
this.itemExtent = itemExtent;
this.childrenDelegate = new SliverChildListDelegate(

int? itemCount = null,
bool addAutomaticKeepAlives = true,
bool addRepaintBoundaries = true,
float? cacheExtent = null
float? cacheExtent = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.down
) : base(key: key,
scrollDirection: scrollDirection,
reverse: reverse,

shrinkWrap: shrinkWrap,
padding: padding,
cacheExtent: cacheExtent
cacheExtent: cacheExtent,
dragStartBehavior: dragStartBehavior
) {
this.itemExtent = itemExtent;
this.childrenDelegate = new SliverChildBuilderDelegate(

int? itemCount = null,
bool addAutomaticKeepAlives = true,
bool addRepaintBoundaries = true,
float? cacheExtent = null
float? cacheExtent = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.down
key,
scrollDirection,
reverse,
controller,
primary,
physics,
shrinkWrap,
padding,
itemExtent,
itemBuilder,
itemCount,
addAutomaticKeepAlives,
addRepaintBoundaries
key: key,
scrollDirection: scrollDirection,
reverse: reverse,
controller: controller,
primary: primary,
physics: physics,
shrinkWrap: shrinkWrap,
padding: padding,
cacheExtent: cacheExtent,
itemExtent: itemExtent,
itemBuilder: itemBuilder,
itemCount: itemCount,
addAutomaticKeepAlives: addAutomaticKeepAlives,
addRepaintBoundaries: addRepaintBoundaries,
dragStartBehavior: dragStartBehavior
);
}

int itemCount = 0,
bool addAutomaticKeepAlives = true,
bool addRepaintBoundaries = true,
float? cacheExtent = null
float? cacheExtent = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.down
) : base(
key: key,
scrollDirection: scrollDirection,

physics: physics,
shrinkWrap: shrinkWrap,
padding: padding,
cacheExtent: cacheExtent
cacheExtent: cacheExtent,
dragStartBehavior: dragStartBehavior
) {
D.assert(itemBuilder != null);
D.assert(separatorBuilder != null);

EdgeInsets padding = null,
SliverGridDelegate gridDelegate = null,
SliverChildDelegate childrenDelegate = null,
float? cacheExtent = null
float? cacheExtent = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.down
) : base(
key: key,
scrollDirection: scrollDirection,

physics: physics,
shrinkWrap: shrinkWrap,
padding: padding,
cacheExtent: cacheExtent
cacheExtent: cacheExtent,
dragStartBehavior: dragStartBehavior
) {
D.assert(gridDelegate != null);
D.assert(childrenDelegate != null);

EdgeInsets padding = null,
SliverGridDelegate gridDelegate = null,
SliverChildDelegate childrenDelegate = null,
float? cacheExtent = null
float? cacheExtent = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.down
) {
return new GridView(
key: key,

padding: padding,
gridDelegate: gridDelegate,
childrenDelegate: childrenDelegate,
cacheExtent: cacheExtent
cacheExtent: cacheExtent,
dragStartBehavior: dragStartBehavior
);
}

bool addAutomaticKeepAlives = true,
bool addRepaintBoundaries = true,
float? cacheExtent = null,
List<Widget> children = null
List<Widget> children = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.down
) : base(
key: key,
scrollDirection: scrollDirection,

physics: physics,
shrinkWrap: shrinkWrap,
padding: padding,
cacheExtent: cacheExtent
cacheExtent: cacheExtent,
dragStartBehavior: dragStartBehavior
) {
this.gridDelegate = new SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: crossAxisCount ?? 0,

bool addAutomaticKeepAlives = true,
bool addRepaintBoundaries = true,
float? cacheExtent = null,
List<Widget> children = null
List<Widget> children = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.down
) {
return new GridView(
key: key,

addAutomaticKeepAlives: addAutomaticKeepAlives,
addRepaintBoundaries: addRepaintBoundaries,
cacheExtent: cacheExtent,
children: children
children: children,
dragStartBehavior: dragStartBehavior
);
}

bool addAutomaticKeepAlives = true,
bool addRepaintBoundaries = true,
bool addSemanticIndexes = true,
List<Widget> children = null
List<Widget> children = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.down
) : base(
key: key,
scrollDirection: scrollDirection,

physics: physics,
shrinkWrap: shrinkWrap,
padding: padding
padding: padding,
dragStartBehavior: dragStartBehavior
) {
this.gridDelegate = new SliverGridDelegateWithMaxCrossAxisExtent(
maxCrossAxisExtent: maxCrossAxisExtent ?? 0,

float childAspectRatio = 1.0f,
bool addAutomaticKeepAlives = true,
bool addRepaintBoundaries = true,
List<Widget> children = null
List<Widget> children = null,
DragStartBehavior dragStartBehavior = DragStartBehavior.down
) {
return new GridView(
key: key,

childAspectRatio: childAspectRatio,
addAutomaticKeepAlives: addAutomaticKeepAlives,
addRepaintBoundaries: addRepaintBoundaries,
children: children
children: children,
dragStartBehavior: dragStartBehavior
);
}

正在加载...
取消
保存