Skip to content
This repository was archived by the owner on Apr 29, 2021. It is now read-only.

Commit 952de6b

Browse files
committed
fix: floatTween could be nullable in animatedOpacity
1 parent e9c1a03 commit 952de6b

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

Runtime/animation/tween.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,15 @@ public override int lerp(float t) {
186186
}
187187
}
188188

189+
public class NullableFloatTween : Tween<float?> {
190+
public NullableFloatTween(float? begin = null, float? end = null) : base(begin: begin, end: end) {
191+
}
192+
193+
public override float? lerp(float t) {
194+
return this.begin + (this.end - this.begin) * t;
195+
}
196+
}
197+
189198
public class FloatTween : Tween<float> {
190199
public FloatTween(float begin, float end) : base(begin: begin, end: end) {
191200
}

Runtime/widgets/implicit_animations.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,13 @@ public override void dispose() {
215215
}
216216

217217
public bool _shouldAnimateTween<T2>(Tween<T2> tween, T2 targetValue) {
218-
return !targetValue.Equals(tween.end == null ? tween.begin : tween.end);
218+
var curTargetValue = tween.end;
219+
220+
if (tween.end == null || typeof(T2) == typeof(float) &&
221+
(float) Convert.ChangeType(tween.end, typeof(float)) == -1.0f) {
222+
curTargetValue = tween.begin;
223+
}
224+
return !targetValue.Equals(curTargetValue);
219225
}
220226

221227
public void _updateTween<T2>(Tween<T2> tween, T2 targetValue) {
@@ -471,7 +477,7 @@ class _AnimatedOpacityState : ImplicitlyAnimatedWidgetState<AnimatedOpacity> {
471477

472478
protected override void forEachTween(TweenVisitor visitor) {
473479
this._opacity = (FloatTween) visitor.visit(this, this._opacity, this.widget.opacity,
474-
(float value) => new FloatTween(begin: value, end: 1.0f));
480+
(float value) => new FloatTween(begin: value, end: -1.0f));
475481
}
476482

477483
protected override void didUpdateTweens() {

Samples/UIWidgetSample/txt/TextFieldSample.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,13 @@ public override Widget build(BuildContext context) {
4141
),
4242
body: new Padding(
4343
padding: EdgeInsets.all(16.0f),
44-
child: new TextField(controller: this.myController)
44+
child: new TextField(
45+
controller: this.myController,
46+
autofocus: true,
47+
decoration: new InputDecoration(
48+
hintText: "hinthere",
49+
labelText: "pwd",
50+
prefixIcon: new Icon(Unity.UIWidgets.material.Icons.search)))
4551
),
4652
floatingActionButton: new FloatingActionButton(
4753
// When the user presses the button, show an alert dialog with the

0 commit comments

Comments
 (0)