浏览代码

Merge branch 'shiyun/skia' of https://github.com/Unity-Technologies/com.unity.uiwidgets into shiyun/skia

/siyaoH-1.17-PlatformMessage
Shiyun Wen 4 年前
当前提交
3aa48817
共有 8 个文件被更改,包括 140 次插入332 次删除
  1. 4
      com.unity.uiwidgets/Runtime/widgets/actions.cs
  2. 38
      com.unity.uiwidgets/Runtime/widgets/binding.cs
  3. 47
      com.unity.uiwidgets/Runtime/widgets/debug.cs
  4. 12
      com.unity.uiwidgets/Runtime/widgets/dismissible.cs
  5. 220
      com.unity.uiwidgets/Runtime/widgets/fade_in_image.cs
  6. 105
      com.unity.uiwidgets/Runtime/widgets/framework.cs
  7. 28
      com.unity.uiwidgets/Runtime/widgets/gesture_detector.cs
  8. 18
      com.unity.uiwidgets/Runtime/widgets/media_query.cs

4
com.unity.uiwidgets/Runtime/widgets/actions.cs


public override bool updateShouldNotify(InheritedWidget oldWidget) {
oldWidget = (Actions) oldWidget;
var dispatcherBool = ((Actions) oldWidget).dispatcher != dispatcher;
bool actionBool = false;
if (((Actions) oldWidget).actions == actions)
actionBool = true;
bool actionBool = ((Actions) oldWidget).actions == actions;
foreach (var actionsKey in ((Actions) oldWidget).actions.Keys) {
if (!actions.ContainsKey(actionsKey) ||
actions[actionsKey] != ((Actions) oldWidget).actions[actionsKey]) {

38
com.unity.uiwidgets/Runtime/widgets/binding.cs


void _handleBuildScheduled() {
D.assert(() => {
if (debugBuildingDirtyElements) {
throw new UIWidgetsError(
"Build scheduled during frame.\n" +
"While the widget tree was being built, laid out, and painted, " +
"a new frame was scheduled to rebuild the widget tree. " +
"This might be because setState() was called from a layout or " +
"paint callback. " +
"If a change is needed to the widget tree, it should be applied " +
"as the tree is being built. Scheduling a change for the subsequent " +
"frame instead results in an interface that lags behind by one frame. " +
"If this was done to make your build dependent on a size measured at " +
"layout time, consider using a LayoutBuilder, CustomSingleChildLayout, " +
"or CustomMultiChildLayout. If, on the other hand, the one frame delay " +
"is the desired effect, for example because this is an " +
"animation, consider scheduling the frame in a post-frame callback " +
"using SchedulerBinding.addPostFrameCallback or " +
"using an AnimationController to trigger the animation."
);
throw new UIWidgetsError(new List<DiagnosticsNode>{
new ErrorSummary("Build scheduled during frame."),
new ErrorDescription(
"While the widget tree was being built, laid out, and painted, " +
"a new frame was scheduled to rebuild the widget tree."
),
new ErrorHint(
"This might be because setState() was called from a layout or " +
"paint callback. " +
"If a change is needed to the widget tree, it should be applied " +
"as the tree is being built. Scheduling a change for the subsequent " +
"frame instead results in an interface that lags behind by one frame. " +
"If this was done to make your build dependent on a size measured at " +
"layout time, consider using a LayoutBuilder, CustomSingleChildLayout, " +
"or CustomMultiChildLayout. If, on the other hand, the one frame delay " +
"is the desired effect, for example because this is an " +
"animation, consider scheduling the frame in a post-frame callback " +
"using SchedulerBinding.addPostFrameCallback or " +
"using an AnimationController to trigger the animation."
)
});
}
return true;

47
com.unity.uiwidgets/Runtime/widgets/debug.cs


public static bool debugCheckHasMediaQuery(BuildContext context) {
D.assert(() => {
if (!(context.widget is MediaQuery) && context.findAncestorWidgetOfExactType<MediaQuery>() == null) {
throw new UIWidgetsError(
"No MediaQuery widget found.\n" +
context.widget.GetType() + " widgets require a MediaQuery widget ancestor.\n" +
"The specific widget that could not find a MediaQuery ancestor was:\n" +
" " + context.widget + "\n" +
"The ownership chain for the affected widget is:\n" +
" " + ((Element)context).debugGetCreatorChain(10) + "\n" +
"Typically, the MediaQuery widget is introduced by the MaterialApp or " +
"WidgetsApp widget at the top of your application widget tree."
);
throw new UIWidgetsError(new List<DiagnosticsNode> {
new ErrorSummary("No MediaQuery widget found."),
new ErrorDescription($"{context.widget.GetType()} widgets require a MediaQuery widget ancestor."),
context.describeWidget("The specific widget that could not find a MediaQuery ancestor was"),
context.describeOwnershipChain("The ownership chain for the affected widget is"),
new ErrorHint(
"Typically, the MediaQuery widget is introduced by the MaterialApp or " +
"WidgetsApp widget at the top of your application widget tree."
)
});
}
return true;

D.assert(() => {
if (!(context.widget is Directionality) &&
context.findAncestorWidgetOfExactType<Directionality>() == null) {
throw new UIWidgetsError(
"No Directionality widget found.\n" +
context.widget.GetType() + " widgets require a Directionality widget ancestor.\n" +
"The specific widget that could not find a Directionality ancestor was:\n" +
" " + context.widget + "\n" +
"The ownership chain for the affected widget is:\n" +
" " + ((Element) context).debugGetCreatorChain(10) + "\n" +
"Typically, the Directionality widget is introduced by the MaterialApp " +
"or WidgetsApp widget at the top of your application widget tree. It " +
"determines the ambient reading direction and is used, for example, to " +
"determine how to lay out text, how to interpret \"start\" and \"end\" " +
"values, and to resolve EdgeInsetsDirectional, " +
"AlignmentDirectional, and other *Directional objects.");
throw new UIWidgetsError(new List<DiagnosticsNode>{
new ErrorSummary("No Directionality widget found."),
new ErrorDescription("${context.widget.runtimeType} widgets require a Directionality widget ancestor.\n"),
context.describeWidget("The specific widget that could not find a Directionality ancestor was"),
context.describeOwnershipChain("The ownership chain for the affected widget is"),
new ErrorHint(
"Typically, the Directionality widget is introduced by the MaterialApp " +
"or WidgetsApp widget at the top of your application widget tree. It " +
"determines the ambient reading direction and is used, for example, to " +
"determine how to lay out text, how to interpret \"start\" and \"end\" " +
"values, and to resolve EdgeInsetsDirectional, " +
"AlignmentDirectional, and other *Directional objects."
)
});
}
return true;

12
com.unity.uiwidgets/Runtime/widgets/dismissible.cs


D.assert(() => {
if (_resizeAnimation.status != AnimationStatus.forward) {
D.assert(_resizeAnimation.status == AnimationStatus.completed);
throw new UIWidgetsError(
"A dismissed Dismissible widget is still part of the tree.\n" +
"Make sure to implement the onDismissed handler and to immediately remove the Dismissible\n" +
"widget from the application once that handler has fired."
);
throw new UIWidgetsError(new List<DiagnosticsNode>{
new ErrorSummary("A dismissed Dismissible widget is still part of the tree."),
new ErrorHint(
"Make sure to implement the onDismissed handler and to immediately remove the Dismissible " +
"widget from the application once that handler has fired."
)
});
}
return true;

220
com.unity.uiwidgets/Runtime/widgets/fade_in_image.cs


new DiagnosticsProperty<Animation<float>>("placeholderOpacity", _placeholderOpacityAnimation));
}
}
/*enum FadeInImagePhase {
start,
waiting,
fadeOut,
fadeIn,
completed
}
delegate void _ImageProviderResolverListener();
class _ImageProviderResolver {
public _ImageProviderResolver(
_FadeInImageState state,
_ImageProviderResolverListener listener
) {
this.state = state;
this.listener = listener;
}
readonly _FadeInImageState state;
readonly _ImageProviderResolverListener listener;
FadeInImage widget {
get { return state.widget; }
}
public ImageStream _imageStream;
public ImageInfo _imageInfo;
public void resolve(ImageProvider provider) {
ImageStream oldImageStream = _imageStream;
Size size = null;
if (widget.width != null && widget.height != null) {
size = new Size((int) widget.width, (int) widget.height);
}
_imageStream = provider.resolve(ImageUtils.createLocalImageConfiguration(state.context, size));
D.assert(_imageStream != null);
if (_imageStream.key != oldImageStream?.key) {
oldImageStream?.removeListener(_handleImageChanged);
_imageStream.addListener(_handleImageChanged);
}
}
void _handleImageChanged(ImageInfo imageInfo, bool synchronousCall) {
_imageInfo = imageInfo;
listener();
}
public void stopListening() {
_imageStream?.removeListener(_handleImageChanged);
}
}
class _FadeInImageState : TickerProviderStateMixin<FadeInImage> {
_ImageProviderResolver _imageResolver;
_ImageProviderResolver _placeholderResolver;
AnimationController _controller;
Animation<float> _animation;
FadeInImagePhase _phase = FadeInImagePhase.start;
public override void initState() {
_imageResolver = new _ImageProviderResolver(state: this, _updatePhase);
_placeholderResolver = new _ImageProviderResolver(state: this, listener: () => {
setState(() => {
// Trigger rebuild to display the placeholder image
});
});
_controller = new AnimationController(
value: 1.0f,
vsync: this
);
_controller.addListener(() => {
setState(() => {
// Trigger rebuild to update opacity value.
});
});
_controller.addStatusListener(status => { _updatePhase(); });
base.initState();
}
public override void didChangeDependencies() {
_resolveImage();
base.didChangeDependencies();
}
public override void didUpdateWidget(StatefulWidget oldWidget) {
base.didUpdateWidget(oldWidget);
FadeInImage fadeInImage = oldWidget as FadeInImage;
if (widget.image != fadeInImage.image || widget.placeholder != fadeInImage.placeholder) {
_resolveImage();
}
}
void _resolveImage() {
_imageResolver.resolve(widget.image);
if (_isShowingPlaceholder) {
_placeholderResolver.resolve(widget.placeholder);
}
if (_phase == FadeInImagePhase.start) {
_updatePhase();
}
}
void _updatePhase() {
setState(() => {
switch (_phase) {
case FadeInImagePhase.start:
if (_imageResolver._imageInfo != null) {
_phase = FadeInImagePhase.completed;
}
else {
_phase = FadeInImagePhase.waiting;
}
break;
case FadeInImagePhase.waiting:
if (_imageResolver._imageInfo != null) {
_controller.duration = widget.fadeOutDuration;
_animation = new CurvedAnimation(
parent: _controller,
curve: widget.fadeOutCurve
);
_phase = FadeInImagePhase.fadeOut;
_controller.reverse(1.0f);
}
break;
case FadeInImagePhase.fadeOut:
if (_controller.status == AnimationStatus.dismissed) {
// Done fading out placeholder. Begin target image fade-in.
_controller.duration = widget.fadeInDuration;
_animation = new CurvedAnimation(
parent: _controller,
curve: widget.fadeInCurve
);
_phase = FadeInImagePhase.fadeIn;
_placeholderResolver.stopListening();
_controller.forward(0.0f);
}
break;
case FadeInImagePhase.fadeIn:
if (_controller.status == AnimationStatus.completed) {
// Done finding in new image.
_phase = FadeInImagePhase.completed;
}
break;
case FadeInImagePhase.completed:
// Nothing to do.
break;
}
});
}
public override void dispose() {
_imageResolver.stopListening();
_placeholderResolver.stopListening();
_controller.dispose();
base.dispose();
}
bool _isShowingPlaceholder {
get {
switch (_phase) {
case FadeInImagePhase.start:
case FadeInImagePhase.waiting:
case FadeInImagePhase.fadeOut:
return true;
case FadeInImagePhase.fadeIn:
case FadeInImagePhase.completed:
return false;
}
return true;
}
}
ImageInfo _imageInfo {
get {
return _isShowingPlaceholder
? _placeholderResolver._imageInfo
: _imageResolver._imageInfo;
}
}
public override Widget build(BuildContext context) {
D.assert(_phase != FadeInImagePhase.start);
ImageInfo imageInfo = _imageInfo;
return new RawImage(
image: imageInfo?.image,
width: widget.width,
height: widget.height,
scale: imageInfo?.scale ?? 1.0f,
color: Color.fromRGBO(255, 255, 255, _animation?.value ?? 1.0f),
colorBlendMode: BlendMode.modulate,
fit: widget.fit,
alignment: widget.alignment,
repeat: widget.repeat
);
}
public override void debugFillProperties(DiagnosticPropertiesBuilder properties) {
base.debugFillProperties(properties);
properties.add(new EnumProperty<FadeInImagePhase>("phase", _phase));
properties.add(new DiagnosticsProperty<ImageInfo>("pixels", _imageInfo));
properties.add(new DiagnosticsProperty<ImageStream>("image stream", _imageResolver._imageStream));
properties.add(new DiagnosticsProperty<ImageStream>("placeholder stream",
_placeholderResolver._imageStream));
}
}*/
}
}

105
com.unity.uiwidgets/Runtime/widgets/framework.cs


Element newer = parent;
UIWidgetsError error = null;
if (older.toString() != newer.toString()) {
error = new UIWidgetsError(
"Multiple widgets used the same GlobalKey.\n" +
$"The key {key} was used by multiple widgets. The parents of those widgets were:\n" +
$"- {older.toString()}\n" +
$"- {newer.toString()}\n" +
"A GlobalKey can only be specified on one widget at a time in the widget tree."
);
error = new UIWidgetsError(new List<DiagnosticsNode>{
new ErrorSummary("Multiple widgets used the same GlobalKey."),
new ErrorDescription(
$"The key {key} was used by multiple widgets. The parents of those widgets were:\n" +
$"- {older.toString()}\n" +
$"- {newer.toString()}\n" +
"A GlobalKey can only be specified on one widget at a time in the widget tree."
)
});
error = new UIWidgetsError(
"Multiple widgets used the same GlobalKey.\n" +
$"The key {key} was used by multiple widgets. The parents of those widgets were:\n" +
"different widgets that both had the following description:\n" +
$" {parent.toString()}\n" +
"A GlobalKey can only be specified on one widget at a time in the widget tree."
);
error = new UIWidgetsError(new List<DiagnosticsNode>{
new ErrorSummary("Multiple widgets used the same GlobalKey."),
new ErrorDescription(
"The key $key was used by multiple widgets. The parents of those widgets were " +
"different widgets that both had the following description:\n" +
" ${parent.toString()}\n" +
"A GlobalKey can only be specified on one widget at a time in the widget tree."
)
});
}
if (child._parent != older) {

_debugIllFatedElements.Clear();
if (duplicates != null) {
var buffer = new StringBuilder();
buffer.AppendLine("Multiple widgets used the same GlobalKey.\n");
List<DiagnosticsNode> information = new List<DiagnosticsNode>();
information.Add(new ErrorSummary("Multiple widgets used the same GlobalKey."));
HashSet<Element> elements = duplicates[key];
buffer.AppendLine($"The key {key} was used by {elements.Count} widgets:");
foreach (Element element in elements) {
buffer.AppendLine("- " + element);
}
HashSet<Element> elements = duplicates.getOrDefault(key);
information.Add( Element.describeElements($"The key $key was used by {elements.Count} widgets", elements));
buffer.Append("A GlobalKey can only be specified on one widget at a time in the widget tree.");
throw new UIWidgetsError(buffer.ToString());
information.Add(new ErrorDescription("A GlobalKey can only be specified on one widget at a time in the widget tree."));
throw new UIWidgetsError(information);
}
return true;

public void setState(VoidCallback fn = null) {
D.assert(() => {
if (_debugLifecycleState == _StateLifecycle.defunct) {
throw new UIWidgetsError(
"setState() called after dispose(): " + this + "\n" +
"This error happens if you call setState() on a State object for a widget that " +
"no longer appears in the widget tree (e.g., whose parent widget no longer " +
"includes the widget in its build). This error can occur when code calls " +
"setState() from a timer or an animation callback. The preferred solution is " +
"to cancel the timer or stop listening to the animation in the dispose() " +
"callback. Another solution is to check the \"mounted\" property of this " +
"object before calling setState() to ensure the object is still in the " +
"tree.\n" +
"This error might indicate a memory leak if setState() is being called " +
"because another object is retaining a reference to this State object " +
"after it has been removed from the tree. To avoid memory leaks, " +
"consider breaking the reference to this object during dispose()."
);
throw new UIWidgetsError(new List<DiagnosticsNode> {
new ErrorSummary($"setState() called after dispose(): {this}"),
new ErrorDescription(
"This error happens if you call setState() on a State object for a widget that " +
"no longer appears in the widget tree (e.g., whose parent widget no longer " +
"includes the widget in its build). This error can occur when code calls " +
"setState() from a timer or an animation callback."
),
new ErrorHint(
"The preferred solution is " +
"to cancel the timer or stop listening to the animation in the dispose() " +
"callback. Another solution is to check the \"mounted\" property of this " +
"object before calling setState() to ensure the object is still in the " +
"tree."
),
new ErrorHint(
"This error might indicate a memory leak if setState() is being called " +
"because another object is retaining a reference to this State object " +
"after it has been removed from the tree. To avoid memory leaks, " +
"consider breaking the reference to this object during dispose()."
)
});
throw new UIWidgetsError(
"setState() called in constructor: " + this + "\n" +
"This happens when you call setState() on a State object for a widget that " +
"hasn\"t been inserted into the widget tree yet. It is not necessary to call " +
"setState() in the constructor, since the state is already assumed to be dirty " +
"when it is initially created."
);
throw new UIWidgetsError(new List<DiagnosticsNode>{
new ErrorSummary($"setState() called in constructor: {this}"),
new ErrorHint(
"This happens when you call setState() on a State object for a widget that " +
"hasn't been inserted into the widget tree yet. It is not necessary to call " +
"setState() in the constructor, since the state is already assumed to be dirty " +
"when it is initially created."
)
});
}
return true;

badAncestors.Insert(0, result);
try {
List<ErrorDescription> errors = new List<ErrorDescription>();
foreach (ParentDataElement<ParentData> _ancestor in badAncestors)
foreach (ParentDataElement<ParentData> parentDataElement in badAncestors)
$"- {_ancestor.widget} (typically placed directly inside a {_ancestor.widget.debugTypicalAncestorWidgetClass} widget)"));
$"- {parentDataElement.widget} (typically placed directly inside a {parentDataElement.widget.debugTypicalAncestorWidgetClass} widget)"));
List<DiagnosticsNode> results = new List<DiagnosticsNode>();
results.Add( new ErrorSummary("Incorrect use of ParentDataWidget."));
results.Add(new ErrorDescription("The following ParentDataWidgets are providing parent data to the same RenderObject:"));

28
com.unity.uiwidgets/Runtime/widgets/gesture_detector.cs


bool haveScale = onScaleStart != null || onScaleUpdate != null || onScaleEnd != null;
if (havePan || haveScale) {
if (havePan && haveScale) {
throw new UIWidgetsError(
"Incorrect GestureDetector arguments.\n" +
"Having both a pan gesture recognizer and a scale gesture recognizer is redundant; scale is a superset of pan. Just use the scale gesture recognizer."
);
throw new UIWidgetsError(new List<DiagnosticsNode>{
new ErrorSummary("Incorrect GestureDetector arguments."),
new ErrorDescription(
"Having both a pan gesture recognizer and a scale gesture recognizer is redundant; scale is a superset of pan."
),
new ErrorHint("Just use the scale gesture recognizer.")
});
}
string recognizer = havePan ? "pan" : "scale";

public void replaceGestureRecognizers(Dictionary<Type, GestureRecognizerFactory> gestures) {
D.assert(() => {
if (!context.findRenderObject().owner.debugDoingLayout) {
throw new UIWidgetsError(
"Unexpected call to replaceGestureRecognizers() method of RawGestureDetectorState.\n" +
"The replaceGestureRecognizers() method can only be called during the layout phase. " +
"To set the gesture recognizers at other times, trigger a new build using setState() " +
"and provide the new gesture recognizers as constructor arguments to the corresponding " +
"RawGestureDetector or GestureDetector object.");
throw new UIWidgetsError(new List<DiagnosticsNode> {
new ErrorSummary(
"Unexpected call to replaceGestureRecognizers() method of RawGestureDetectorState."),
new ErrorDescription(
"The replaceGestureRecognizers() method can only be called during the layout phase."),
new ErrorHint(
"To set the gesture recognizers at other times, trigger a new build using setState() " +
"and provide the new gesture recognizers as constructor arguments to the corresponding " +
"RawGestureDetector or GestureDetector object."
)
});
}
return true;

18
com.unity.uiwidgets/Runtime/widgets/media_query.cs


return null;
}
throw new UIWidgetsError(
"MediaQuery.of() called with a context that does not contain a MediaQuery.\n" +
"No MediaQuery ancestor could be found starting from the context that was passed " +
"to MediaQuery.of(). This can happen because you do not have a WidgetsApp or " +
"MaterialApp widget (those widgets introduce a MediaQuery), or it can happen " +
"if the context you use comes from a widget above those widgets.\n" +
"The context used was:\n" +
$" {context}");
throw new UIWidgetsError(new List<DiagnosticsNode>{
new ErrorSummary("MediaQuery.of() called with a context that does not contain a MediaQuery."),
new ErrorDescription(
"No MediaQuery ancestor could be found starting from the context that was passed " +
"to MediaQuery.of(). This can happen because you do not have a WidgetsApp or " +
"MaterialApp widget (those widgets introduce a MediaQuery), or it can happen " +
"if the context you use comes from a widget above those widgets."
),
context.describeElement("The context used was")
});
}
public static float textScaleFactorOf(BuildContext context) {

正在加载...
取消
保存