fix bug on cupertino/segmented_control and fade_in_image

This commit is contained in:
Xingwei Zhu 2022-08-25 17:55:01 +08:00
Родитель a0f70d850b
Коммит 7ce3f39d32
4 изменённых файлов: 657 добавлений и 571 удалений

Просмотреть файл

@ -1,17 +1,5 @@
using System.Collections.Generic;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using Unity.UIWidgets.widgets;
using Unity.UIWidgets.scheduler;
using System;
using Unity.UIWidgets.gestures;
using Unity.UIWidgets.painting;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;
using Transform = Unity.UIWidgets.widgets.Transform;
namespace Unity.UIWidgets.animation {
public class TweenSequence<T> : Animatable<T> {

Просмотреть файл

@ -11,16 +11,16 @@ using Unity.UIWidgets.rendering;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using Rect = Unity.UIWidgets.ui.Rect;
using TextStyle = Unity.UIWidgets.painting.TextStyle;
namespace Unity.UIWidgets.cupertino {
class CupertinoSegmentedControlsUtils {
static class CupertinoSegmentedControlsUtils {
public static readonly EdgeInsetsGeometry _kHorizontalItemPadding = EdgeInsets.symmetric(horizontal: 16.0f);
public const float _kMinSegmentedControlHeight = 28.0f;
public static readonly TimeSpan _kFadeDuration = TimeSpan.FromMilliseconds(165);
}
public class CupertinoSegmentedControl<T> : StatefulWidget {
public class CupertinoSegmentedControl<T> : StatefulWidget
{
public CupertinoSegmentedControl(
Key key = null,
Dictionary<T, Widget> children = null,
@ -31,8 +31,8 @@ namespace Unity.UIWidgets.cupertino {
Color borderColor = null,
Color pressedColor = null,
EdgeInsetsGeometry padding = null
) :base(key: key)
{ D.assert(children != null);
) : base(key: key) {
D.assert(children != null);
D.assert(children.Count >= 2);
D.assert(onValueChanged != null);
D.assert(
@ -47,8 +47,8 @@ namespace Unity.UIWidgets.cupertino {
this.borderColor = borderColor;
this.pressedColor = pressedColor;
this.padding = padding;
}
public readonly Dictionary<T, Widget> children;
public readonly T groupValue;
public readonly ValueChanged<T> onValueChanged;
@ -62,11 +62,32 @@ namespace Unity.UIWidgets.cupertino {
return new _SegmentedControlState<T>();
}
}
class _SegmentedControlState<T> : TickerProviderStateMixin<CupertinoSegmentedControl<T>> {
T _pressedKey;
public readonly List<AnimationController> _selectionControllers = new List<AnimationController>();
public readonly List<ColorTween> _childTweens = new List<ColorTween>();
class _SegmentedControlState<T> : TickerProviderStateMixin<CupertinoSegmentedControl<T>> {
T __pressedKey = default;
bool __isNull = true;
void setPressedKey(T newkey) {
__pressedKey = newkey;
__isNull = false;
}
void setPressedKeyNull() {
__pressedKey = default;
__isNull = true;
}
bool isPressedKeyNull() {
return __isNull;
}
T getPressedKey() {
return __pressedKey;
}
readonly List<AnimationController> _selectionControllers = new List<AnimationController>();
readonly List<ColorTween> _childTweens = new List<ColorTween>();
ColorTween _forwardBackgroundColorTween;
ColorTween _reverseBackgroundColorTween;
@ -84,7 +105,6 @@ namespace Unity.UIWidgets.cupertino {
);
controller.addListener(() => {
setState(() => {
// State of background/text colors has changed
});
});
return controller;
@ -92,23 +112,26 @@ namespace Unity.UIWidgets.cupertino {
bool _updateColors() {
D.assert(mounted, () => "This should only be called after didUpdateDependencies");
bool changed = false;
Color selectedColor = widget.selectedColor ?? CupertinoTheme.of(context).primaryColor;
var changed = false;
var selectedColor = widget.selectedColor ?? CupertinoTheme.of(context).primaryColor;
if (_selectedColor != selectedColor) {
changed = true;
_selectedColor = selectedColor;
}
Color unselectedColor = widget.unselectedColor ?? CupertinoTheme.of(context).primaryContrastingColor;
var unselectedColor = widget.unselectedColor ?? CupertinoTheme.of(context).primaryContrastingColor;
if (_unselectedColor != unselectedColor) {
changed = true;
_unselectedColor = unselectedColor;
}
Color borderColor = widget.borderColor ?? CupertinoTheme.of(context).primaryColor;
var borderColor = widget.borderColor ?? CupertinoTheme.of(context).primaryColor;
if (_borderColor != borderColor) {
changed = true;
_borderColor = borderColor;
}
Color pressedColor = widget.pressedColor ?? CupertinoTheme.of(context).primaryColor.withOpacity(0.2f);
var pressedColor = widget.pressedColor ?? CupertinoTheme.of(context).primaryColor.withOpacity(0.2f);
if (_pressedColor != pressedColor) {
changed = true;
_pressedColor = pressedColor;
@ -122,28 +145,33 @@ namespace Unity.UIWidgets.cupertino {
begin: _unselectedColor,
end: _selectedColor
);
_textColorTween = new ColorTween(
begin: _selectedColor,
end: _unselectedColor
);
return changed;
}
void _updateAnimationControllers() {
D.assert(mounted, () => "This should only be called after didUpdateDependencies");
foreach ( AnimationController controller in _selectionControllers) {
foreach (var controller in _selectionControllers) {
controller.dispose();
}
_selectionControllers.Clear();
_childTweens.Clear();
foreach ( T key in widget.children.Keys) {
AnimationController animationController = createAnimationController();
foreach (var key in widget.children.Keys) {
var animationController = createAnimationController();
if (widget.groupValue.Equals(key)) {
_childTweens.Add(_reverseBackgroundColorTween);
animationController.setValue(1.0f);
} else {
}
else {
_childTweens.Add(_forwardBackgroundColorTween);
}
_selectionControllers.Add(animationController);
}
}
@ -157,57 +185,65 @@ namespace Unity.UIWidgets.cupertino {
}
public override void didUpdateWidget(StatefulWidget oldWidget) {
oldWidget = (CupertinoSegmentedControl<T>) oldWidget;
var _oldWidget = oldWidget as CupertinoSegmentedControl<T>;
base.didUpdateWidget(oldWidget);
if (_updateColors() || ((CupertinoSegmentedControl<T>) oldWidget).children.Count != widget.children.Count) {
if (_updateColors() || _oldWidget.children.Count != widget.children.Count) {
_updateAnimationControllers();
}
if (!((CupertinoSegmentedControl<T>)oldWidget).groupValue.Equals(widget.groupValue)) {
int index = 0;
foreach ( T key in widget.children.Keys) {
if (!_oldWidget.groupValue.Equals(widget.groupValue)) {
var index = 0;
foreach (var key in widget.children.Keys) {
if (widget.groupValue.Equals(key)) {
_childTweens[index] = _forwardBackgroundColorTween;
_selectionControllers[index].forward();
} else {
}
else {
_childTweens[index] = _reverseBackgroundColorTween;
_selectionControllers[index].reverse();
}
index += 1;
}
}
}
public override void dispose() {
foreach( AnimationController animationController in _selectionControllers) {
foreach (var animationController in _selectionControllers) {
animationController.dispose();
}
base.dispose();
}
void _onTapDown(T currentKey) {
if (_pressedKey == null && !currentKey.Equals(widget.groupValue)) {
if (isPressedKeyNull() && !currentKey.Equals(widget.groupValue)) {
setState(() => {
_pressedKey = currentKey;
setPressedKey(currentKey);
});
}
}
void _onTapCancel() {
setState(()=> {
_pressedKey = default(T);
});
setState(setPressedKeyNull);
}
bool isPressKeyEquals(T currentKey) {
return isPressedKeyNull() && currentKey == null ||
!isPressedKeyNull() && currentKey.Equals(getPressedKey());
}
void _onTap(T currentKey) {
if (!currentKey.Equals( _pressedKey))
if (!isPressKeyEquals(currentKey))
return;
if (!currentKey.Equals(widget.groupValue)) {
widget.onValueChanged(currentKey);
}
_pressedKey = default;
setPressedKeyNull();
}
Color getTextColor(int index, T currentKey) {
@ -223,7 +259,7 @@ namespace Unity.UIWidgets.cupertino {
return _childTweens[index].evaluate(_selectionControllers[index]);
if (widget.groupValue.Equals(currentKey))
return _selectedColor;
if (_pressedKey.Equals(currentKey))
if (isPressKeyEquals(currentKey))
return _pressedColor;
return _unselectedColor;
}
@ -232,29 +268,30 @@ namespace Unity.UIWidgets.cupertino {
List<Widget> _gestureChildren = new List<Widget>();
List<Color> _backgroundColors = new List<Color>();
int index = 0;
int selectedIndex = 0;
int pressedIndex = 0;
foreach ( T currentKey in widget.children.Keys) {
selectedIndex = (widget.groupValue.Equals(currentKey)) ? index : selectedIndex;
pressedIndex = (_pressedKey.Equals(currentKey)) ? index : pressedIndex;
TextStyle textStyle = DefaultTextStyle.of(context).style.copyWith(
color: getTextColor(index, currentKey)
int? selectedIndex = null;
int? pressedIndex = null;
foreach (var currentKey in widget.children.Keys) {
var currentKey2 = currentKey;
selectedIndex = (widget.groupValue.Equals(currentKey2)) ? index : selectedIndex;
pressedIndex = (isPressKeyEquals(currentKey2)) ? index : pressedIndex;
var textStyle = DefaultTextStyle.of(context).style.copyWith(
color: getTextColor(index, currentKey2)
);
IconThemeData iconTheme = new IconThemeData(
color: getTextColor(index, currentKey)
var iconTheme = new IconThemeData(
color: getTextColor(index, currentKey2)
);
Widget child = new Center(
child: widget.children[currentKey]
child: widget.children[currentKey2]
);
child = new GestureDetector(
onTapDown: (TapDownDetails _event) => {
_onTapDown(currentKey);
_onTapDown(currentKey2);
},
onTapCancel: _onTapCancel,
onTap: () => {
_onTap(currentKey);
_onTap(currentKey2);
},
child: new IconTheme(
data: iconTheme,
@ -265,7 +302,7 @@ namespace Unity.UIWidgets.cupertino {
)
);
_backgroundColors.Add(getBackgroundColor(index, currentKey));
_backgroundColors.Add(getBackgroundColor(index, currentKey2));
_gestureChildren.Add(child);
index += 1;
}
@ -287,6 +324,7 @@ namespace Unity.UIWidgets.cupertino {
);
}
}
public class _SegmentedControlRenderWidget<T> : MultiChildRenderObjectWidget {
public _SegmentedControlRenderWidget(
Key key = null,
@ -309,6 +347,7 @@ namespace Unity.UIWidgets.cupertino {
public readonly int? pressedIndex;
public readonly List<Color> backgroundColors;
public readonly Color borderColor;
public override RenderObject createRenderObject(BuildContext context) {
return new _RenderSegmentedControl<T>(
textDirection: Directionality.of(context),
@ -318,6 +357,7 @@ namespace Unity.UIWidgets.cupertino {
borderColor: borderColor
);
}
public override void updateRenderObject(BuildContext context, RenderObject renderObject) {
renderObject = (_RenderSegmentedControl<T>) renderObject;
((_RenderSegmentedControl<T>) renderObject).textDirection = Directionality.of(context);
@ -325,7 +365,6 @@ namespace Unity.UIWidgets.cupertino {
((_RenderSegmentedControl<T>) renderObject).pressedIndex = pressedIndex;
((_RenderSegmentedControl<T>) renderObject).backgroundColors = backgroundColors;
((_RenderSegmentedControl<T>) renderObject).borderColor = borderColor;
}
}
@ -358,71 +397,70 @@ namespace Unity.UIWidgets.cupertino {
if (_selectedIndex == value) {
return;
}
_selectedIndex = value;
markNeedsPaint();
}
}
int? _selectedIndex;
public int? pressedIndex {
get {
return _pressedIndex;
}
get { return _pressedIndex; }
set {
if (_pressedIndex == value) {
return;
}
_pressedIndex = value;
markNeedsPaint();
}
}
int? _pressedIndex;
public TextDirection? textDirection {
get {
return _textDirection;
}
get { return _textDirection; }
set {
if (_textDirection == value) {
return;
}
_textDirection = value;
markNeedsLayout();
}
}
TextDirection? _textDirection;
public List<Color> backgroundColors {
get {
return _backgroundColors;
}
get { return _backgroundColors; }
set {
if (_backgroundColors == value) {
return;
}
_backgroundColors = value;
markNeedsPaint();
}
}
List<Color> _backgroundColors;
public Color borderColor {
get {
return _borderColor;
}
get { return _borderColor; }
set {
if (_borderColor == value) {
return;
}
_borderColor = value;
markNeedsPaint();
}
}
}
Color _borderColor;
@ -430,11 +468,13 @@ namespace Unity.UIWidgets.cupertino {
RenderBox child = firstChild;
float minWidth = 0.0f;
while (child != null) {
_SegmentedControlContainerBoxParentData childParentData = child.parentData as _SegmentedControlContainerBoxParentData;
_SegmentedControlContainerBoxParentData childParentData =
child.parentData as _SegmentedControlContainerBoxParentData;
float childWidth = child.getMinIntrinsicWidth(height);
minWidth = Mathf.Max(minWidth, childWidth);
child = childParentData.nextSibling;
}
return minWidth * childCount;
}
@ -442,11 +482,13 @@ namespace Unity.UIWidgets.cupertino {
RenderBox child = firstChild;
float maxWidth = 0.0f;
while (child != null) {
_SegmentedControlContainerBoxParentData childParentData = child.parentData as _SegmentedControlContainerBoxParentData;
_SegmentedControlContainerBoxParentData childParentData =
child.parentData as _SegmentedControlContainerBoxParentData;
float childWidth = child.getMaxIntrinsicWidth(height);
maxWidth = Mathf.Max(maxWidth, childWidth);
child = childParentData.nextSibling;
}
return maxWidth * childCount;
}
@ -454,22 +496,27 @@ namespace Unity.UIWidgets.cupertino {
RenderBox child = firstChild;
float minHeight = 0.0f;
while (child != null) {
_SegmentedControlContainerBoxParentData childParentData = child.parentData as _SegmentedControlContainerBoxParentData;
_SegmentedControlContainerBoxParentData childParentData =
child.parentData as _SegmentedControlContainerBoxParentData;
float childHeight = child.getMinIntrinsicHeight(width);
minHeight = Mathf.Max(minHeight, childHeight);
child = childParentData.nextSibling;
}
return minHeight;
}
protected internal override float computeMaxIntrinsicHeight(float width) {
RenderBox child = firstChild;
float maxHeight = 0.0f;
while (child != null) {
_SegmentedControlContainerBoxParentData childParentData = child.parentData as _SegmentedControlContainerBoxParentData;
_SegmentedControlContainerBoxParentData childParentData =
child.parentData as _SegmentedControlContainerBoxParentData;
float childHeight = child.getMaxIntrinsicHeight(width);
maxHeight = Mathf.Max(maxHeight, childHeight);
child = childParentData.nextSibling;
}
return maxHeight;
}
@ -488,7 +535,8 @@ namespace Unity.UIWidgets.cupertino {
RenderBox child = leftChild;
float start = 0.0f;
while (child != null) {
_SegmentedControlContainerBoxParentData childParentData = child.parentData as _SegmentedControlContainerBoxParentData;
_SegmentedControlContainerBoxParentData childParentData =
child.parentData as _SegmentedControlContainerBoxParentData;
Offset childOffset = new Offset(start, 0.0f);
childParentData.offset = childOffset;
Rect childRect = Rect.fromLTWH(start, 0.0f, child.size.width, child.size.height);
@ -496,17 +544,21 @@ namespace Unity.UIWidgets.cupertino {
if (child == leftChild) {
rChildRect = RRect.fromRectAndCorners(childRect, topLeft: Radius.circular(3.0f),
bottomLeft: Radius.circular(3.0f));
} else if (child == rightChild) {
}
else if (child == rightChild) {
rChildRect = RRect.fromRectAndCorners(childRect, topRight: Radius.circular(3.0f),
bottomRight: Radius.circular(3.0f));
} else {
}
else {
rChildRect = RRect.fromRectAndCorners(childRect, topRight: Radius.zero);
}
childParentData.surroundingRect = rChildRect;
start += child.size.width;
child = nextChild(child);
}
}
protected override void performLayout() {
BoxConstraints constraints = this.constraints;
float maxHeight = CupertinoSegmentedControlsUtils._kMinSegmentedControlHeight;
@ -515,6 +567,7 @@ namespace Unity.UIWidgets.cupertino {
foreach (RenderBox child in getChildrenAsList()) {
childWidth = Mathf.Max(childWidth, child.getMaxIntrinsicWidth(float.PositiveInfinity));
}
childWidth = Mathf.Min(childWidth, constraints.maxWidth / childCount);
RenderBox child1 = firstChild;
@ -556,6 +609,7 @@ namespace Unity.UIWidgets.cupertino {
size = constraints.constrain(new Size(childWidth * childCount, maxHeight));
}
public override void paint(PaintingContext context, Offset offset) {
RenderBox child = firstChild;
int index = 0;
@ -569,20 +623,23 @@ namespace Unity.UIWidgets.cupertino {
void _paintChild(PaintingContext context, Offset offset, RenderBox child, int childIndex) {
D.assert(child != null);
_SegmentedControlContainerBoxParentData childParentData = child.parentData as _SegmentedControlContainerBoxParentData;
_SegmentedControlContainerBoxParentData childParentData =
child.parentData as _SegmentedControlContainerBoxParentData;
context.canvas.drawRRect(
childParentData.surroundingRect.shift(offset),
new Paint() {
color = backgroundColors[childIndex],
style = PaintingStyle.fill}
style = PaintingStyle.fill
}
);
context.canvas.drawRRect(
childParentData.surroundingRect.shift(offset),
new Paint() {
color = borderColor,
strokeWidth = 1.0f,
style = PaintingStyle.stroke}
style = PaintingStyle.stroke
}
);
context.paintChild(child, childParentData.offset + offset);
@ -592,7 +649,8 @@ namespace Unity.UIWidgets.cupertino {
D.assert(position != null);
RenderBox child = lastChild;
while (child != null) {
_SegmentedControlContainerBoxParentData childParentData = child.parentData as _SegmentedControlContainerBoxParentData;
_SegmentedControlContainerBoxParentData childParentData =
child.parentData as _SegmentedControlContainerBoxParentData;
if (childParentData.surroundingRect.contains(position)) {
Offset center = (Offset.zero & child.size).center;
return result.addWithRawTransform(
@ -604,15 +662,11 @@ namespace Unity.UIWidgets.cupertino {
}
);
}
child = childParentData.previousSibling;
}
return false;
}
}
}

Просмотреть файл

@ -1,15 +1,11 @@
using System;
using System.Collections.Generic;
using System.Runtime.CompilerServices;
using Unity.UIWidgets.animation;
using Unity.UIWidgets.foundation;
using Unity.UIWidgets.painting;
using Unity.UIWidgets.rendering;
using Unity.UIWidgets.ui;
using UnityEngine;
using Color = Unity.UIWidgets.ui.Color;
using Debug = System.Diagnostics.Debug;
using Object = System.Object;
namespace Unity.UIWidgets.widgets {
public class FadeInImage : StatelessWidget {
@ -30,7 +26,6 @@ namespace Unity.UIWidgets.widgets {
Key key = null,
bool matchTextDirection = false
) : base(key) {
D.assert(image != null);
D.assert(fadeOutDuration != null);
D.assert(fadeOutCurve != null);
@ -128,7 +123,6 @@ namespace Unity.UIWidgets.widgets {
int? imageCacheWidth = null,
int? imageCacheHeight = null
) {
fadeOutDuration = fadeOutDuration ?? new TimeSpan(0, 0, 0, 0, 300);
fadeOutCurve = fadeOutCurve ?? Curves.easeOut;
fadeInDuration = fadeInDuration ?? new TimeSpan(0, 0, 0, 0, 700);
@ -143,7 +137,61 @@ namespace Unity.UIWidgets.widgets {
return new FadeInImage(
placeholder: _placeholder,
placeholderErrorBuilder: placeholderErrorBuilder,
image: ResizeImage.resizeIfNeeded(imageCacheWidth, imageCacheHeight, new NetworkImage(image, scale: imageScale)),
image: ResizeImage.resizeIfNeeded(imageCacheWidth, imageCacheHeight,
new NetworkImage(image, scale: imageScale)),
imageErrorBuilder: imageErrorBuilder,
fadeOutDuration: fadeOutDuration,
fadeOutCurve: fadeOutCurve,
fadeInDuration: fadeInDuration,
fadeInCurve: fadeInCurve,
width: width, height: height,
fit: fit,
alignment: alignment,
repeat: repeat,
matchTextDirection: matchTextDirection,
key: key
);
}
public static FadeInImage fileNetwork(
string placeholder,
string image,
ImageErrorWidgetBuilder placeholderErrorBuilder = null,
ImageErrorWidgetBuilder imageErrorBuilder = null,
float? placeholderScale = null,
float imageScale = 1.0f,
TimeSpan? fadeOutDuration = null,
Curve fadeOutCurve = null,
TimeSpan? fadeInDuration = null,
Curve fadeInCurve = null,
float? width = null,
float? height = null,
BoxFit? fit = null,
AlignmentGeometry alignment = null,
ImageRepeat repeat = ImageRepeat.noRepeat,
bool matchTextDirection = false,
Key key = null,
int? placeholderCacheWidth = null,
int? placeholderCacheHeight = null,
int? imageCacheWidth = null,
int? imageCacheHeight = null
) {
fadeOutDuration = fadeOutDuration ?? new TimeSpan(0, 0, 0, 0, 300);
fadeOutCurve = fadeOutCurve ?? Curves.easeOut;
fadeInDuration = fadeInDuration ?? new TimeSpan(0, 0, 0, 0, 700);
fadeInCurve = Curves.easeIn;
alignment = alignment ?? Alignment.center;
var holder = placeholderScale ?? 1.0f;
var _placeholder = placeholderScale != null
? ResizeImage.resizeIfNeeded(placeholderCacheWidth, placeholderCacheHeight,
new FileImage(placeholder, scale: holder))
: ResizeImage.resizeIfNeeded(placeholderCacheWidth, placeholderCacheHeight,
new FileImage(placeholder));
return new FadeInImage(
placeholder: _placeholder,
placeholderErrorBuilder: placeholderErrorBuilder,
image: ResizeImage.resizeIfNeeded(imageCacheWidth, imageCacheHeight,
new NetworkImage(image, scale: imageScale)),
imageErrorBuilder: imageErrorBuilder,
fadeOutDuration: fadeOutDuration,
fadeOutCurve: fadeOutCurve,
@ -190,7 +238,6 @@ namespace Unity.UIWidgets.widgets {
repeat: repeat,
matchTextDirection: matchTextDirection,
gaplessPlayback: true
);
}
@ -227,7 +274,6 @@ namespace Unity.UIWidgets.widgets {
Curve fadeInCurve,
Key key = null
) : base(key: key, duration: fadeInDuration + fadeOutDuration) {
this.target = target;
this.placeholder = placeholder;
this.isTargetLoaded = isTargetLoaded;
@ -260,30 +306,30 @@ namespace Unity.UIWidgets.widgets {
state: this,
tween: _targetOpacity,
targetValue: widget.isTargetLoaded ? 1.0f : 0.0f,
constructor: (float value) => new FloatTween(begin: value, 0));
constructor: (float value) => new FloatTween(begin: 1 - value, 0)); //TODO: in flutter it is "new FloatTween(begin: value, 0)", which doesn't work out in UIWidgets
_placeholderOpacity = (FloatTween) visitor.visit(
state: this,
tween: _placeholderOpacity,
targetValue: widget.isTargetLoaded ? 0.0f : 1.0f,
constructor: (float value) => new FloatTween(begin: value, 0));
constructor: (float value) => new FloatTween(begin: 1 - value, 0)); //TODO: in flutter it is "new FloatTween(begin: value, 0)", which doesn't work out in UIWidgets
}
protected override void didUpdateTweens() {
List<TweenSequenceItem<float>> list = new List<TweenSequenceItem<float>>();
Debug.Assert(widget.fadeOutDuration?.Milliseconds != null,
Debug.Assert(widget.fadeOutDuration?.TotalMilliseconds != null,
"widget.fadeOutDuration?.Milliseconds != null");
list.Add(new TweenSequenceItem<float>(
tween: _placeholderOpacity.chain(new CurveTween(curve: widget.fadeOutCurve)),
weight: (float) widget.fadeOutDuration?.Milliseconds
weight: (float) widget.fadeOutDuration?.TotalMilliseconds
));
Debug.Assert(widget.fadeInDuration?.Milliseconds != null,
Debug.Assert(widget.fadeInDuration?.TotalMilliseconds != null,
"widget.fadeInDuration?.Milliseconds != null");
list.Add(new TweenSequenceItem<float>(
tween: new ConstantTween<float>(0),
weight: (float) widget.fadeInDuration?.Milliseconds
weight: (float) widget.fadeInDuration?.TotalMilliseconds
));
@ -297,11 +343,11 @@ namespace Unity.UIWidgets.widgets {
List<TweenSequenceItem<float>> list2 = new List<TweenSequenceItem<float>>();
list2.Add(new TweenSequenceItem<float>(
tween: new ConstantTween<float>(0),
weight: (float) widget.fadeOutDuration?.Milliseconds
weight: (float) widget.fadeOutDuration?.TotalMilliseconds
));
list2.Add(new TweenSequenceItem<float>(
tween: _targetOpacity.chain(new CurveTween(curve: widget.fadeInCurve)),
weight: (float) widget.fadeInDuration?.Milliseconds
weight: (float) widget.fadeInDuration?.TotalMilliseconds
));
_targetOpacityAnimation = animation.drive(new TweenSequence<float>(list2));
if (!widget.isTargetLoaded && _isValid(_placeholderOpacity) && _isValid(_targetOpacity)) {
@ -313,7 +359,6 @@ namespace Unity.UIWidgets.widgets {
return tween?.begin != null && tween?.end != null;
}
public override Widget build(BuildContext context) {
Widget target = new FadeTransition(
opacity: _targetOpacityAnimation,
@ -345,6 +390,5 @@ namespace Unity.UIWidgets.widgets {
new DiagnosticsProperty<Animation<float>>("placeholderOpacity", _placeholderOpacityAnimation));
}
}
}
}

Просмотреть файл

@ -339,7 +339,7 @@ namespace Unity.UIWidgets.widgets {
}
public class _ImageState : State<Image>, WidgetsBindingObserver {
int _frameNumber;
int? _frameNumber = null;
ImageInfo _imageInfo;
ImageStream _imageStream;
@ -584,7 +584,7 @@ namespace Unity.UIWidgets.widgets {
description.add(new DiagnosticsProperty<ImageStream>("stream", value: _imageStream));
description.add(new DiagnosticsProperty<ImageInfo>("pixels", value: _imageInfo));
description.add(new DiagnosticsProperty<ImageChunkEvent>("loadingProgress", value: _loadingProgress));
description.add(new DiagnosticsProperty<int>("frameNumber", value: _frameNumber));
description.add(new DiagnosticsProperty<int?>("frameNumber", value: _frameNumber));
description.add(new DiagnosticsProperty<bool>("wasSynchronouslyLoaded", value: _wasSynchronouslyLoaded));
}
}