Commit 972417f5 authored by Viktor Lidholt's avatar Viktor Lidholt

Merge branch 'master' of github.com:domokit/sky_engine

parents 27181225 6d304c03
...@@ -9,6 +9,7 @@ dart_pkg("sky") { ...@@ -9,6 +9,7 @@ dart_pkg("sky") {
"CHANGELOG.md", "CHANGELOG.md",
"bin/init.dart", "bin/init.dart",
"lib/animation/animated_simulation.dart", "lib/animation/animated_simulation.dart",
"lib/animation/animated_value.dart",
"lib/animation/animation_performance.dart", "lib/animation/animation_performance.dart",
"lib/animation/curves.dart", "lib/animation/curves.dart",
"lib/animation/forces.dart", "lib/animation/forces.dart",
......
## 0.0.20
- 167 changes: https://github.com/domokit/mojo/compare/f2830c7...603f589
## 0.0.19 ## 0.0.19
- 49 changes: https://github.com/domokit/mojo/compare/a64559a...1b8968c - 49 changes: https://github.com/domokit/mojo/compare/a64559a...1b8968c
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
Use of this source code is governed by a BSD-style license that can be Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file. found in the LICENSE file.
--> -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.domokit.sky.demo" android:versionCode="19" android:versionName="0.0.19"> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="org.domokit.sky.demo" android:versionCode="20" android:versionName="0.0.20">
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" /> <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="21" />
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
......
...@@ -14,7 +14,6 @@ import 'package:sky/widgets/drawer_item.dart'; ...@@ -14,7 +14,6 @@ import 'package:sky/widgets/drawer_item.dart';
import 'package:sky/widgets/floating_action_button.dart'; import 'package:sky/widgets/floating_action_button.dart';
import 'package:sky/widgets/icon_button.dart'; import 'package:sky/widgets/icon_button.dart';
import 'package:sky/widgets/icon.dart'; import 'package:sky/widgets/icon.dart';
import 'package:sky/widgets/ink_well.dart';
import 'package:sky/widgets/material.dart'; import 'package:sky/widgets/material.dart';
import 'package:sky/widgets/navigator.dart'; import 'package:sky/widgets/navigator.dart';
import 'package:sky/widgets/scaffold.dart'; import 'package:sky/widgets/scaffold.dart';
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
import 'package:sky/editing/input.dart'; import 'package:sky/editing/input.dart';
import 'package:sky/widgets/basic.dart'; import 'package:sky/widgets/basic.dart';
import 'package:sky/widgets/flat_button.dart';
import 'package:sky/widgets/icon_button.dart'; import 'package:sky/widgets/icon_button.dart';
import 'package:sky/widgets/ink_well.dart'; import 'package:sky/widgets/ink_well.dart';
import 'package:sky/widgets/material.dart'; import 'package:sky/widgets/material.dart';
......
...@@ -148,26 +148,27 @@ void doFrame(double timeStamp) { ...@@ -148,26 +148,27 @@ void doFrame(double timeStamp) {
break; break;
} }
} else { } else {
assert(node is sky.Text); // assert(node is sky.Text); //
final sky.Text text = node;
if (pickThis(0.1)) { if (pickThis(0.1)) {
report("appending a new text node (ASCII)"); report("appending a new text node (ASCII)");
node.appendData(generateCharacter(0x20, 0x7F)); text.appendData(generateCharacter(0x20, 0x7F));
break; break;
} else if (pickThis(0.05)) { } else if (pickThis(0.05)) {
report("appending a new text node (Latin1)"); report("appending a new text node (Latin1)");
node.appendData(generateCharacter(0x20, 0xFF)); text.appendData(generateCharacter(0x20, 0xFF));
break; break;
} else if (pickThis(0.025)) { } else if (pickThis(0.025)) {
report("appending a new text node (BMP)"); report("appending a new text node (BMP)");
node.appendData(generateCharacter(0x20, 0xFFFF)); text.appendData(generateCharacter(0x20, 0xFFFF));
break; break;
} else if (pickThis(0.0125)) { } else if (pickThis(0.0125)) {
report("appending a new text node (Unicode)"); report("appending a new text node (Unicode)");
node.appendData(generateCharacter(0x20, 0x10FFFF)); text.appendData(generateCharacter(0x20, 0x10FFFF));
break; break;
} else if (node.length > 1 && pickThis(0.1)) { } else if (text.length > 1 && pickThis(0.1)) {
report("deleting character from Text node"); report("deleting character from Text node");
node.deleteData(random.nextInt(node.length), 1); text.deleteData(random.nextInt(text.length), 1);
break; break;
} }
} }
...@@ -178,7 +179,7 @@ void doFrame(double timeStamp) { ...@@ -178,7 +179,7 @@ void doFrame(double timeStamp) {
int count = 1; int count = 1;
while (node != null) { while (node != null) {
if (node is sky.Element && node.firstChild != null) { if (node is sky.Element && node.firstChild != null) {
node = node.firstChild; node = (node as sky.Element).firstChild;
count += 1; count += 1;
} else { } else {
while (node != null && node.nextSibling == null) while (node != null && node.nextSibling == null)
......
...@@ -20,7 +20,7 @@ void main() { ...@@ -20,7 +20,7 @@ void main() {
TextStyle style = const TextStyle(color: const Color(0xFF000000)); TextStyle style = const TextStyle(color: const Color(0xFF000000));
RenderParagraph paragraph = new RenderParagraph(new InlineStyle(style, [new InlineText("${alignItems}")])); RenderParagraph paragraph = new RenderParagraph(new InlineStyle(style, [new InlineText("${alignItems}")]));
table.add(new RenderPadding(child: paragraph, padding: new EdgeDims.only(top: 20.0))); table.add(new RenderPadding(child: paragraph, padding: new EdgeDims.only(top: 20.0)));
var row = new RenderFlex(alignItems: alignItems, baseline: TextBaseline.alphabetic); var row = new RenderFlex(alignItems: alignItems, textBaseline: TextBaseline.alphabetic);
style = new TextStyle(fontSize: 15.0, color: const Color(0xFF000000)); style = new TextStyle(fontSize: 15.0, color: const Color(0xFF000000));
row.add(new RenderDecoratedBox( row.add(new RenderDecoratedBox(
...@@ -32,7 +32,7 @@ void main() { ...@@ -32,7 +32,7 @@ void main() {
decoration: new BoxDecoration(backgroundColor: const Color(0x7FCCFFCC)), decoration: new BoxDecoration(backgroundColor: const Color(0x7FCCFFCC)),
child: new RenderParagraph(new InlineStyle(style, [new InlineText('foo foo foo')])) child: new RenderParagraph(new InlineStyle(style, [new InlineText('foo foo foo')]))
)); ));
var subrow = new RenderFlex(alignItems: alignItems, baseline: TextBaseline.alphabetic); var subrow = new RenderFlex(alignItems: alignItems, textBaseline: TextBaseline.alphabetic);
style = new TextStyle(fontSize: 25.0, color: const Color(0xFF000000)); style = new TextStyle(fontSize: 25.0, color: const Color(0xFF000000));
subrow.add(new RenderDecoratedBox( subrow.add(new RenderDecoratedBox(
decoration: new BoxDecoration(backgroundColor: const Color(0x7FCCCCFF)), decoration: new BoxDecoration(backgroundColor: const Color(0x7FCCCCFF)),
......
...@@ -25,15 +25,15 @@ class Touch { ...@@ -25,15 +25,15 @@ class Touch {
class RenderImageGrow extends RenderImage { class RenderImageGrow extends RenderImage {
final Size _startingSize; final Size _startingSize;
RenderImageGrow(Image image, Size size) : _startingSize = size, super(image, size); RenderImageGrow(Image image, Size size)
: _startingSize = size, super(image: image, width: size.width, height: size.height);
double _growth = 0.0; double _growth = 0.0;
double get growth => _growth; double get growth => _growth;
void set growth(double value) { void set growth(double value) {
_growth = value; _growth = value;
double newWidth = _startingSize.width == null ? null : _startingSize.width + growth; width = _startingSize.width == null ? null : _startingSize.width + growth;
double newHeight = _startingSize.height == null ? null : _startingSize.height + growth; height = _startingSize.height == null ? null : _startingSize.height + growth;
requestedSize = new Size(newWidth, newHeight);
} }
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
// found in the LICENSE file. // found in the LICENSE file.
import 'package:sky/editing/input.dart'; import 'package:sky/editing/input.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animated_value.dart';
import 'package:sky/widgets/animated_component.dart'; import 'package:sky/widgets/animated_component.dart';
import 'package:sky/widgets/animation_builder.dart'; import 'package:sky/widgets/animation_builder.dart';
import 'package:sky/theme/colors.dart' as colors; import 'package:sky/theme/colors.dart' as colors;
...@@ -69,7 +69,8 @@ class StockHome extends AnimatedComponent { ...@@ -69,7 +69,8 @@ class StockHome extends AnimatedComponent {
} }
void _handleSearchEnd() { void _handleSearchEnd() {
assert(navigator.currentRoute.key == this); assert(navigator.currentRoute is RouteState);
assert((navigator.currentRoute as RouteState).owner == this); // TODO(ianh): remove cast once analyzer is cleverer
navigator.pop(); navigator.pop();
setState(() { setState(() {
_isSearching = false; _isSearching = false;
...@@ -280,10 +281,10 @@ class StockHome extends AnimatedComponent { ...@@ -280,10 +281,10 @@ class StockHome extends AnimatedComponent {
void _handleStockPurchased() { void _handleStockPurchased() {
setState(() { setState(() {
_snackbarTransform = new AnimationBuilder() _snackbarTransform = new AnimationBuilder()
..position = new AnimatedType<Point>(const Point(0.0, 45.0), end: Point.origin); ..position = new AnimatedValue<Point>(const Point(0.0, 45.0), end: Point.origin);
var performance = _snackbarTransform.createPerformance( var performance = _snackbarTransform.createPerformance(
[_snackbarTransform.position], duration: _kSnackbarSlideDuration); [_snackbarTransform.position], duration: _kSnackbarSlideDuration);
watch(performance); watch(performance); // TODO(mpcomplete): need to unwatch
performance.play(); performance.play();
}); });
} }
......
...@@ -61,7 +61,7 @@ class StockSettings extends StatefulComponent { ...@@ -61,7 +61,7 @@ class StockSettings extends StatefulComponent {
break; break;
case StockMode.pessimistic: case StockMode.pessimistic:
showModeDialog = true; showModeDialog = true;
navigator.pushState("/settings/confirm", (_) { navigator.pushState(this, (_) {
showModeDialog = false; showModeDialog = false;
}); });
break; break;
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/animation/curves.dart'; import 'package:sky/animation/curves.dart';
import 'package:sky/base/lerp.dart'; import 'package:sky/base/lerp.dart';
...@@ -27,8 +28,6 @@ class CardModel { ...@@ -27,8 +28,6 @@ class CardModel {
AnimationPerformance performance; AnimationPerformance performance;
String get label => "Item $value"; String get label => "Item $value";
String get key => value.toString(); String get key => value.toString();
bool operator ==(other) => other is CardModel && other.value == value;
int get hashCode => 373 * 37 * value.hashCode;
} }
class ShrinkingCard extends AnimatedComponent { class ShrinkingCard extends AnimatedComponent {
...@@ -44,7 +43,7 @@ class ShrinkingCard extends AnimatedComponent { ...@@ -44,7 +43,7 @@ class ShrinkingCard extends AnimatedComponent {
Function onUpdated; Function onUpdated;
Function onCompleted; Function onCompleted;
double get currentHeight => card.performance.variable.value; double get currentHeight => (card.performance.variable as AnimatedValue).value;
void initState() { void initState() {
assert(card.performance != null); assert(card.performance != null);
...@@ -100,7 +99,7 @@ class CardCollectionApp extends App { ...@@ -100,7 +99,7 @@ class CardCollectionApp extends App {
assert(card.performance == null); assert(card.performance == null);
card.performance = new AnimationPerformance() card.performance = new AnimationPerformance()
..duration = const Duration(milliseconds: 300) ..duration = const Duration(milliseconds: 300)
..variable = new AnimatedType<double>( ..variable = new AnimatedValue<double>(
card.height + kCardMargins.top + kCardMargins.bottom, card.height + kCardMargins.top + kCardMargins.bottom,
end: 0.0, end: 0.0,
curve: ease, curve: ease,
......
...@@ -16,7 +16,8 @@ class ContainerApp extends App { ...@@ -16,7 +16,8 @@ class ContainerApp extends App {
decoration: new BoxDecoration(backgroundColor: const Color(0xFFCCCCCC)), decoration: new BoxDecoration(backgroundColor: const Color(0xFFCCCCCC)),
child: new NetworkImage( child: new NetworkImage(
src: "https://www.dartlang.org/logos/dart-logo.png", src: "https://www.dartlang.org/logos/dart-logo.png",
size: new Size(300.0, 300.0) width: 300.0,
height: 300.0
) )
), ),
new Container( new Container(
......
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import "dart:sky";
import 'package:sky/animation/curves.dart';
import 'package:sky/base/lerp.dart';
abstract class AnimatedVariable {
void setProgress(double t);
String toString();
}
class Interval {
final double start;
final double end;
double adjustTime(double t) {
return ((t - start) / (end - start)).clamp(0.0, 1.0);
}
Interval(this.start, this.end) {
assert(start >= 0.0);
assert(start <= 1.0);
assert(end >= 0.0);
assert(end <= 1.0);
}
}
class AnimatedValue<T extends dynamic> extends AnimatedVariable {
AnimatedValue(this.begin, { this.end, this.interval, this.curve: linear }) {
value = begin;
}
T value;
T begin;
T end;
Interval interval;
Curve curve;
void setProgress(double t) {
if (end != null) {
double adjustedTime = interval == null ? t : interval.adjustTime(t);
if (adjustedTime == 1.0) {
value = end;
} else {
// TODO(mpcomplete): Reverse the timeline and curve.
value = begin + (end - begin) * curve.transform(adjustedTime);
}
}
}
String toString() => 'AnimatedValue(begin=$begin, end=$end, value=$value)';
}
class AnimatedList extends AnimatedVariable {
List<AnimatedVariable> variables;
Interval interval;
AnimatedList(this.variables, { this.interval });
void setProgress(double t) {
double adjustedTime = interval == null ? t : interval.adjustTime(t);
for (AnimatedVariable variable in variables)
variable.setProgress(adjustedTime);
}
String toString() => 'AnimatedList([$variables])';
}
class AnimatedColor extends AnimatedValue<Color> {
AnimatedColor(Color begin, { Color end, Curve curve: linear })
: super(begin, end: end, curve: curve);
void setProgress(double t) {
value = lerpColor(begin, end, t);
}
}
...@@ -4,71 +4,9 @@ ...@@ -4,71 +4,9 @@
import 'dart:async'; import 'dart:async';
import 'package:sky/animation/timeline.dart'; import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/curves.dart';
import 'package:sky/animation/forces.dart'; import 'package:sky/animation/forces.dart';
import 'package:sky/animation/timeline.dart';
abstract class AnimatedVariable {
void setFraction(double t);
String toString();
}
class Interval {
final double start;
final double end;
double adjustTime(double t) {
return ((t - start) / (end - start)).clamp(0.0, 1.0);
}
Interval(this.start, this.end) {
assert(start >= 0.0);
assert(start <= 1.0);
assert(end >= 0.0);
assert(end <= 1.0);
}
}
class AnimatedType<T extends dynamic> extends AnimatedVariable {
AnimatedType(this.begin, { this.end, this.interval, this.curve: linear }) {
value = begin;
}
T value;
T begin;
T end;
Interval interval;
Curve curve;
void setFraction(double t) {
if (end != null) {
double adjustedTime = interval == null ? t : interval.adjustTime(t);
if (adjustedTime == 1.0) {
value = end;
} else {
// TODO(mpcomplete): Reverse the timeline and curve.
value = begin + (end - begin) * curve.transform(adjustedTime);
}
}
}
String toString() => 'AnimatedType(begin=$begin, end=$end, value=$value)';
}
class AnimatedList extends AnimatedVariable {
List<AnimatedVariable> variables;
Interval interval;
AnimatedList(this.variables, { this.interval });
void setFraction(double t) {
double adjustedTime = interval == null ? t : interval.adjustTime(t);
for (AnimatedVariable variable in variables)
variable.setFraction(adjustedTime);
}
String toString() => 'AnimatedList([$variables])';
}
// This class manages a "performance" - a collection of values that change // This class manages a "performance" - a collection of values that change
// based on a timeline. For example, a performance may handle an animation // based on a timeline. For example, a performance may handle an animation
...@@ -82,7 +20,6 @@ class AnimationPerformance { ...@@ -82,7 +20,6 @@ class AnimationPerformance {
_timeline = new Timeline(_tick); _timeline = new Timeline(_tick);
} }
// TODO(mpcomplete): make this a list, or composable somehow.
AnimatedVariable variable; AnimatedVariable variable;
// TODO(mpcomplete): duration should be on a director. // TODO(mpcomplete): duration should be on a director.
Duration duration; Duration duration;
...@@ -142,7 +79,7 @@ class AnimationPerformance { ...@@ -142,7 +79,7 @@ class AnimationPerformance {
} }
void _tick(double t) { void _tick(double t) {
variable.setFraction(t); variable.setProgress(t);
_notifyListeners(); _notifyListeners();
} }
} }
...@@ -54,11 +54,12 @@ class Timeline { ...@@ -54,11 +54,12 @@ class Timeline {
double end: 1.0 double end: 1.0
}) { }) {
assert(!_animation.isAnimating); assert(!_animation.isAnimating);
assert(duration > Duration.ZERO);
return _animation.start(new TweenSimulation(duration, begin, end)); return _animation.start(new TweenSimulation(duration, begin, end));
} }
Future animateTo(double target, { Duration duration }) { Future animateTo(double target, { Duration duration }) {
assert(duration > Duration.ZERO);
return _start(duration: duration, begin: value, end: target); return _start(duration: duration, begin: value, end: target);
} }
......
...@@ -1249,9 +1249,10 @@ class RenderViewport extends RenderBox with RenderObjectWithChildMixin<RenderBox ...@@ -1249,9 +1249,10 @@ class RenderViewport extends RenderBox with RenderObjectWithChildMixin<RenderBox
class RenderImage extends RenderBox { class RenderImage extends RenderBox {
RenderImage(sky.Image image, Size requestedSize, { sky.ColorFilter colorFilter }) RenderImage({ sky.Image image, double width, double height, sky.ColorFilter colorFilter })
: _image = image, : _image = image,
_requestedSize = requestedSize, _width = width,
_height = height,
_colorFilter = colorFilter; _colorFilter = colorFilter;
sky.Image _image; sky.Image _image;
...@@ -1261,18 +1262,25 @@ class RenderImage extends RenderBox { ...@@ -1261,18 +1262,25 @@ class RenderImage extends RenderBox {
return; return;
_image = value; _image = value;
markNeedsPaint(); markNeedsPaint();
if (_requestedSize.width == null || _requestedSize.height == null) if (_width == null || _height == null)
markNeedsLayout(); markNeedsLayout();
} }
Size _requestedSize; double _width;
Size get requestedSize => _requestedSize; double get width => _width;
void set requestedSize (Size value) { void set width (double value) {
if (value == null) if (value == _width)
value = const Size(null, null);
if (value == _requestedSize)
return; return;
_requestedSize = value; _width = value;
markNeedsLayout();
}
double _height;
double get height => _height;
void set height (double value) {
if (value == _height)
return;
_height = value;
markNeedsLayout(); markNeedsLayout();
} }
...@@ -1299,8 +1307,8 @@ class RenderImage extends RenderBox { ...@@ -1299,8 +1307,8 @@ class RenderImage extends RenderBox {
Size _sizeForConstraints(BoxConstraints constraints) { Size _sizeForConstraints(BoxConstraints constraints) {
// If there's no image, we can't size ourselves automatically // If there's no image, we can't size ourselves automatically
if (_image == null) { if (_image == null) {
double width = requestedSize.width == null ? 0.0 : requestedSize.width; double width = _width == null ? 0.0 : _width;
double height = requestedSize.height == null ? 0.0 : requestedSize.height; double height = _height == null ? 0.0 : _height;
return constraints.constrain(new Size(width, height)); return constraints.constrain(new Size(width, height));
} }
...@@ -1310,8 +1318,8 @@ class RenderImage extends RenderBox { ...@@ -1310,8 +1318,8 @@ class RenderImage extends RenderBox {
// other dimension to maintain the aspect ratio. In both cases, // other dimension to maintain the aspect ratio. In both cases,
// constrain dimensions first, otherwise we end up losing the // constrain dimensions first, otherwise we end up losing the
// ratio after constraining. // ratio after constraining.
if (requestedSize.width == null) { if (_width == null) {
if (requestedSize.height == null) { if (_height == null) {
// autosize // autosize
double width = constraints.constrainWidth(_image.width.toDouble()); double width = constraints.constrainWidth(_image.width.toDouble());
double maxHeight = constraints.constrainHeight(_image.height.toDouble()); double maxHeight = constraints.constrainHeight(_image.height.toDouble());
...@@ -1323,21 +1331,21 @@ class RenderImage extends RenderBox { ...@@ -1323,21 +1331,21 @@ class RenderImage extends RenderBox {
} }
return constraints.constrain(new Size(width, height)); return constraints.constrain(new Size(width, height));
} }
// determine width from height // Determine width from height
double width = requestedSize.height * _image.width / _image.height; double width = _height * _image.width / _image.height;
return constraints.constrain(new Size(width, requestedSize.height)); return constraints.constrain(new Size(width, height));
} }
if (requestedSize.height == null) { if (_height == null) {
// determine height from width // Determine height from width
double height = requestedSize.width * _image.height / _image.width; double height = _width * _image.height / _image.width;
return constraints.constrain(new Size(requestedSize.width, height)); return constraints.constrain(new Size(width, height));
} }
} }
return constraints.constrain(requestedSize); return constraints.constrain(new Size(width, height));
} }
double getMinIntrinsicWidth(BoxConstraints constraints) { double getMinIntrinsicWidth(BoxConstraints constraints) {
if (requestedSize.width == null && requestedSize.height == null) if (_width == null && _height == null)
return constraints.constrainWidth(0.0); return constraints.constrainWidth(0.0);
return _sizeForConstraints(constraints).width; return _sizeForConstraints(constraints).width;
} }
...@@ -1347,7 +1355,7 @@ class RenderImage extends RenderBox { ...@@ -1347,7 +1355,7 @@ class RenderImage extends RenderBox {
} }
double getMinIntrinsicHeight(BoxConstraints constraints) { double getMinIntrinsicHeight(BoxConstraints constraints) {
if (requestedSize.width == null && requestedSize.height == null) if (_width == null && _height == null)
return constraints.constrainHeight(0.0); return constraints.constrainHeight(0.0);
return _sizeForConstraints(constraints).height; return _sizeForConstraints(constraints).height;
} }
...@@ -1377,7 +1385,7 @@ class RenderImage extends RenderBox { ...@@ -1377,7 +1385,7 @@ class RenderImage extends RenderBox {
canvas.restore(); canvas.restore();
} }
String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}dimensions: ${requestedSize}\n'; String debugDescribeSettings(String prefix) => '${super.debugDescribeSettings(prefix)}${prefix}width: ${width}\n${prefix}height: ${height}\n';
} }
class RenderDecoratedBox extends RenderProxyBox { class RenderDecoratedBox extends RenderProxyBox {
......
...@@ -83,6 +83,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl ...@@ -83,6 +83,7 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
} }
} }
// Set during layout if overflow occurred on the main axis
TextBaseline _textBaseline; TextBaseline _textBaseline;
TextBaseline get textBaseline => _textBaseline; TextBaseline get textBaseline => _textBaseline;
void set textBaseline (TextBaseline value) { void set textBaseline (TextBaseline value) {
...@@ -92,7 +93,6 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl ...@@ -92,7 +93,6 @@ class RenderFlex extends RenderBox with ContainerRenderObjectMixin<RenderBox, Fl
} }
} }
// Set during layout if overflow occurred on the main axis
double _overflow; double _overflow;
void setupParentData(RenderBox child) { void setupParentData(RenderBox child) {
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'package:vector_math/vector_math.dart'; import 'package:vector_math/vector_math.dart';
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/animation/curves.dart'; import 'package:sky/animation/curves.dart';
import 'package:sky/base/lerp.dart'; import 'package:sky/base/lerp.dart';
...@@ -11,21 +12,21 @@ import 'package:sky/painting/box_painter.dart'; ...@@ -11,21 +12,21 @@ import 'package:sky/painting/box_painter.dart';
import 'package:sky/widgets/basic.dart'; import 'package:sky/widgets/basic.dart';
import 'package:sky/widgets/animated_component.dart'; import 'package:sky/widgets/animated_component.dart';
class AnimatedBoxConstraintsValue extends AnimatedType<BoxConstraints> { class AnimatedBoxConstraintsValue extends AnimatedValue<BoxConstraints> {
AnimatedBoxConstraintsValue(BoxConstraints begin, { BoxConstraints end, Curve curve: linear }) AnimatedBoxConstraintsValue(BoxConstraints begin, { BoxConstraints end, Curve curve: linear })
: super(begin, end: end, curve: curve); : super(begin, end: end, curve: curve);
void setFraction(double t) { void setProgress(double t) {
// TODO(abarth): We should lerp the BoxConstraints. // TODO(abarth): We should lerp the BoxConstraints.
value = end; value = end;
} }
} }
class AnimatedBoxDecorationValue extends AnimatedType<BoxDecoration> { class AnimatedBoxDecorationValue extends AnimatedValue<BoxDecoration> {
AnimatedBoxDecorationValue(BoxDecoration begin, { BoxDecoration end, Curve curve: linear }) AnimatedBoxDecorationValue(BoxDecoration begin, { BoxDecoration end, Curve curve: linear })
: super(begin, end: end, curve: curve); : super(begin, end: end, curve: curve);
void setFraction(double t) { void setProgress(double t) {
if (t == 1.0) { if (t == 1.0) {
value = end; value = end;
return; return;
...@@ -34,11 +35,11 @@ class AnimatedBoxDecorationValue extends AnimatedType<BoxDecoration> { ...@@ -34,11 +35,11 @@ class AnimatedBoxDecorationValue extends AnimatedType<BoxDecoration> {
} }
} }
class AnimatedEdgeDimsValue extends AnimatedType<EdgeDims> { class AnimatedEdgeDimsValue extends AnimatedValue<EdgeDims> {
AnimatedEdgeDimsValue(EdgeDims begin, { EdgeDims end, Curve curve: linear }) AnimatedEdgeDimsValue(EdgeDims begin, { EdgeDims end, Curve curve: linear })
: super(begin, end: end, curve: curve); : super(begin, end: end, curve: curve);
void setFraction(double t) { void setProgress(double t) {
if (t == 1.0) { if (t == 1.0) {
value = end; value = end;
return; return;
...@@ -54,7 +55,7 @@ class AnimatedEdgeDimsValue extends AnimatedType<EdgeDims> { ...@@ -54,7 +55,7 @@ class AnimatedEdgeDimsValue extends AnimatedType<EdgeDims> {
class ImplicitlyAnimatedValue<T> { class ImplicitlyAnimatedValue<T> {
final AnimationPerformance performance = new AnimationPerformance(); final AnimationPerformance performance = new AnimationPerformance();
final AnimatedType<T> _variable; final AnimatedValue<T> _variable;
ImplicitlyAnimatedValue(this._variable, Duration duration) { ImplicitlyAnimatedValue(this._variable, Duration duration) {
performance performance
...@@ -168,21 +169,21 @@ class AnimatedContainer extends AnimatedComponent { ...@@ -168,21 +169,21 @@ class AnimatedContainer extends AnimatedComponent {
void _updateTransform() { void _updateTransform() {
_updateField(transform, _transform, () { _updateField(transform, _transform, () {
_transform = new ImplicitlyAnimatedValue<Matrix4>(new AnimatedType<Matrix4>(transform), duration); _transform = new ImplicitlyAnimatedValue<Matrix4>(new AnimatedValue<Matrix4>(transform), duration);
watch(_transform.performance); watch(_transform.performance);
}); });
} }
void _updateWidth() { void _updateWidth() {
_updateField(width, _width, () { _updateField(width, _width, () {
_width = new ImplicitlyAnimatedValue<double>(new AnimatedType<double>(width), duration); _width = new ImplicitlyAnimatedValue<double>(new AnimatedValue<double>(width), duration);
watch(_width.performance); watch(_width.performance);
}); });
} }
void _updateHeight() { void _updateHeight() {
_updateField(height, _height, () { _updateField(height, _height, () {
_height = new ImplicitlyAnimatedValue<double>( new AnimatedType<double>(height), duration); _height = new ImplicitlyAnimatedValue<double>( new AnimatedValue<double>(height), duration);
watch(_height.performance); watch(_height.performance);
}); });
} }
......
...@@ -4,9 +4,8 @@ ...@@ -4,9 +4,8 @@
import 'package:vector_math/vector_math.dart'; import 'package:vector_math/vector_math.dart';
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/animation/curves.dart';
import 'package:sky/base/lerp.dart';
import 'package:sky/painting/box_painter.dart'; import 'package:sky/painting/box_painter.dart';
import 'package:sky/theme/shadows.dart'; import 'package:sky/theme/shadows.dart';
import 'package:sky/widgets/basic.dart'; import 'package:sky/widgets/basic.dart';
...@@ -18,9 +17,9 @@ class AnimationBuilder { ...@@ -18,9 +17,9 @@ class AnimationBuilder {
AnimationBuilder(); AnimationBuilder();
AnimatedType<double> opacity; AnimatedValue<double> opacity;
AnimatedType<Point> position; AnimatedValue<Point> position;
AnimatedType<double> shadow; AnimatedValue<double> shadow;
AnimatedColor backgroundColor; AnimatedColor backgroundColor;
// These don't animate, but are used to build the AnimationBuilder anyway. // These don't animate, but are used to build the AnimationBuilder anyway.
...@@ -30,7 +29,7 @@ class AnimationBuilder { ...@@ -30,7 +29,7 @@ class AnimationBuilder {
Map<AnimatedVariable, AnimationPerformance> _variableToPerformance = Map<AnimatedVariable, AnimationPerformance> _variableToPerformance =
new Map<AnimatedVariable, AnimationPerformance>(); new Map<AnimatedVariable, AnimationPerformance>();
AnimationPerformance createPerformance(List<AnimatedType> variables, AnimationPerformance createPerformance(List<AnimatedValue> variables,
{ Duration duration }) { { Duration duration }) {
AnimationPerformance performance = new AnimationPerformance() AnimationPerformance performance = new AnimationPerformance()
..duration = duration ..duration = duration
...@@ -67,7 +66,7 @@ class AnimationBuilder { ...@@ -67,7 +66,7 @@ class AnimationBuilder {
} }
void updateFields({ void updateFields({
AnimatedType<double> shadow, AnimatedValue<double> shadow,
AnimatedColor backgroundColor, AnimatedColor backgroundColor,
double borderRadius, double borderRadius,
Shape shape Shape shape
...@@ -78,7 +77,7 @@ class AnimationBuilder { ...@@ -78,7 +77,7 @@ class AnimationBuilder {
this.shape = shape; this.shape = shape;
} }
void _updateField(AnimatedType variable, AnimatedType sourceVariable) { void _updateField(AnimatedValue variable, AnimatedValue sourceVariable) {
if (variable == null) if (variable == null)
return; // TODO(mpcomplete): Should we handle transition from null? return; // TODO(mpcomplete): Should we handle transition from null?
...@@ -101,15 +100,6 @@ class AnimationBuilder { ...@@ -101,15 +100,6 @@ class AnimationBuilder {
} }
} }
class AnimatedColor extends AnimatedType<Color> {
AnimatedColor(Color begin, { Color end, Curve curve: linear })
: super(begin, end: end, curve: curve);
void setFraction(double t) {
value = lerpColor(begin, end, t);
}
}
List<BoxShadow> _computeShadow(double level) { List<BoxShadow> _computeShadow(double level) {
if (level < 1.0) // shadows[1] is the first shadow if (level < 1.0) // shadows[1] is the first shadow
return null; return null;
......
...@@ -488,31 +488,34 @@ class Text extends Component { ...@@ -488,31 +488,34 @@ class Text extends Component {
} }
class Image extends LeafRenderObjectWrapper { class Image extends LeafRenderObjectWrapper {
Image({ sky.Image image, this.size, this.colorFilter }) Image({ sky.Image image, this.width, this.height, this.colorFilter })
: image = image, : image = image,
super(key: image.hashCode.toString()); // TODO(ianh): Find a way to uniquely identify the sky.Image rather than using hashCode, which could collide super(key: image.hashCode.toString()); // TODO(ianh): Find a way to uniquely identify the sky.Image rather than using hashCode, which could collide
final sky.Image image; final sky.Image image;
final Size size; final double width;
final double height;
final sky.ColorFilter colorFilter; final sky.ColorFilter colorFilter;
RenderImage createNode() => new RenderImage(image, size, colorFilter: colorFilter); RenderImage createNode() => new RenderImage(image: image, width: width, height: height, colorFilter: colorFilter);
RenderImage get root => super.root; RenderImage get root => super.root;
void syncRenderObject(Widget old) { void syncRenderObject(Widget old) {
super.syncRenderObject(old); super.syncRenderObject(old);
root.image = image; root.image = image;
root.requestedSize = size; root.width = width;
root.height = height;
root.colorFilter = colorFilter; root.colorFilter = colorFilter;
} }
} }
class FutureImage extends StatefulComponent { class FutureImage extends StatefulComponent {
FutureImage({ String key, this.image, this.size, this.colorFilter }) FutureImage({ String key, this.image, this.width, this.height, this.colorFilter })
: super(key: key); : super(key: key);
Future<sky.Image> image; Future<sky.Image> image;
Size size; double width;
double height;
sky.ColorFilter colorFilter; sky.ColorFilter colorFilter;
sky.Image _resolvedImage; sky.Image _resolvedImage;
...@@ -535,48 +538,57 @@ class FutureImage extends StatefulComponent { ...@@ -535,48 +538,57 @@ class FutureImage extends StatefulComponent {
void syncFields(FutureImage source) { void syncFields(FutureImage source) {
bool needToResolveImage = (image != source.image); bool needToResolveImage = (image != source.image);
image = source.image; image = source.image;
size = source.size; width = source.width;
height = source.height;
if (needToResolveImage) if (needToResolveImage)
_resolveImage(); _resolveImage();
} }
Widget build() { Widget build() {
return new Image(image: _resolvedImage, size: size, colorFilter: colorFilter); return new Image(
image: _resolvedImage,
width: width,
height: height,
colorFilter: colorFilter
);
} }
} }
class NetworkImage extends Component { class NetworkImage extends Component {
NetworkImage({ String src, this.size, this.colorFilter }) NetworkImage({ String src, this.width, this.height, this.colorFilter })
: src = src, : src = src, super(key: src);
super(key: src);
final String src; final String src;
final Size size; final double width;
final double height;
final sky.ColorFilter colorFilter; final sky.ColorFilter colorFilter;
Widget build() { Widget build() {
return new FutureImage( return new FutureImage(
image: image_cache.load(src), image: image_cache.load(src),
size: size, width: width,
height: height,
colorFilter: colorFilter colorFilter: colorFilter
); );
} }
} }
class AssetImage extends Component { class AssetImage extends Component {
AssetImage({ String name, this.bundle, this.size, this.colorFilter }) AssetImage({ String name, this.bundle, this.width, this.height, this.colorFilter })
: name = name, : name = name,
super(key: name); super(key: name);
final String name; final String name;
final AssetBundle bundle; final AssetBundle bundle;
final Size size; final double width;
final double height;
final sky.ColorFilter colorFilter; final sky.ColorFilter colorFilter;
Widget build() { Widget build() {
return new FutureImage( return new FutureImage(
image: bundle.loadImage(name), image: bundle.loadImage(name),
size: size, width: width,
height: height,
colorFilter: colorFilter colorFilter: colorFilter
); );
} }
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:sky' as sky; import 'dart:sky' as sky;
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/widgets/animated_component.dart'; import 'package:sky/widgets/animated_component.dart';
import 'package:sky/widgets/basic.dart'; import 'package:sky/widgets/basic.dart';
...@@ -13,7 +14,7 @@ import 'package:vector_math/vector_math.dart'; ...@@ -13,7 +14,7 @@ import 'package:vector_math/vector_math.dart';
const Duration _kCardDismissFadeout = const Duration(milliseconds: 200); const Duration _kCardDismissFadeout = const Duration(milliseconds: 200);
const double _kMinFlingVelocity = 700.0; const double _kMinFlingVelocity = 700.0;
const double _kMinFlingVelocityDelta = 400.0; const double _kMinFlingVelocityDelta = 400.0;
const double _kFlingVelocityScale = 1.0/300.0; const double _kFlingVelocityScale = 1.0 / 300.0;
const double _kDismissCardThreshold = 0.6; const double _kDismissCardThreshold = 0.6;
typedef void DismissedCallback(); typedef void DismissedCallback();
...@@ -30,8 +31,8 @@ class Dismissable extends AnimatedComponent { ...@@ -30,8 +31,8 @@ class Dismissable extends AnimatedComponent {
Widget child; Widget child;
DismissedCallback onDismissed; DismissedCallback onDismissed;
AnimatedType<Point> _position; AnimatedValue<Point> _position;
AnimatedType<double> _opacity; AnimatedValue<double> _opacity;
AnimationPerformance _performance; AnimationPerformance _performance;
double _width; double _width;
...@@ -39,8 +40,8 @@ class Dismissable extends AnimatedComponent { ...@@ -39,8 +40,8 @@ class Dismissable extends AnimatedComponent {
bool _dragUnderway = false; bool _dragUnderway = false;
void initState() { void initState() {
_position = new AnimatedType<Point>(Point.origin); _position = new AnimatedValue<Point>(Point.origin);
_opacity = new AnimatedType<double>(1.0, end: 0.0); _opacity = new AnimatedValue<double>(1.0, end: 0.0);
_performance = new AnimationPerformance() _performance = new AnimationPerformance()
..duration = _kCardDismissFadeout ..duration = _kCardDismissFadeout
..variable = new AnimatedList([_position, _opacity]) ..variable = new AnimatedList([_position, _opacity])
......
...@@ -4,11 +4,11 @@ ...@@ -4,11 +4,11 @@
import 'dart:sky' as sky; import 'dart:sky' as sky;
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/theme/shadows.dart'; import 'package:sky/theme/shadows.dart';
import 'package:sky/theme/colors.dart' as colors; import 'package:sky/theme/colors.dart' as colors;
import 'package:sky/widgets/animated_component.dart'; import 'package:sky/widgets/animated_component.dart';
import 'package:sky/widgets/animation_builder.dart';
import 'package:sky/widgets/basic.dart'; import 'package:sky/widgets/basic.dart';
import 'package:sky/widgets/navigator.dart'; import 'package:sky/widgets/navigator.dart';
import 'package:sky/widgets/scrollable_viewport.dart'; import 'package:sky/widgets/scrollable_viewport.dart';
...@@ -30,7 +30,7 @@ import 'package:vector_math/vector_math.dart'; ...@@ -30,7 +30,7 @@ import 'package:vector_math/vector_math.dart';
const double _kWidth = 304.0; const double _kWidth = 304.0;
const double _kMinFlingVelocity = 365.0; const double _kMinFlingVelocity = 365.0;
const double _kFlingVelocityScale = 1.0/300.0; const double _kFlingVelocityScale = 1.0 / 300.0;
const Duration _kBaseSettleDuration = const Duration(milliseconds: 246); const Duration _kBaseSettleDuration = const Duration(milliseconds: 246);
const Point _kOpenPosition = Point.origin; const Point _kOpenPosition = Point.origin;
const Point _kClosedPosition = const Point(-_kWidth, 0.0); const Point _kClosedPosition = const Point(-_kWidth, 0.0);
...@@ -60,12 +60,12 @@ class Drawer extends AnimatedComponent { ...@@ -60,12 +60,12 @@ class Drawer extends AnimatedComponent {
DrawerStatusChangedCallback onStatusChanged; DrawerStatusChangedCallback onStatusChanged;
Navigator navigator; Navigator navigator;
AnimatedType<Point> _position; AnimatedValue<Point> _position;
AnimatedColor _maskColor; AnimatedColor _maskColor;
AnimationPerformance _performance; AnimationPerformance _performance;
void initState() { void initState() {
_position = new AnimatedType<Point>(_kClosedPosition, end: _kOpenPosition); _position = new AnimatedValue<Point>(_kClosedPosition, end: _kOpenPosition);
_maskColor = new AnimatedColor(colors.transparent, end: const Color(0x7F000000)); _maskColor = new AnimatedColor(colors.transparent, end: const Color(0x7F000000));
_performance = new AnimationPerformance() _performance = new AnimationPerformance()
..duration = _kBaseSettleDuration ..duration = _kBaseSettleDuration
...@@ -143,7 +143,8 @@ class Drawer extends AnimatedComponent { ...@@ -143,7 +143,8 @@ class Drawer extends AnimatedComponent {
if (_lastStatus != null && status != _lastStatus) { if (_lastStatus != null && status != _lastStatus) {
if (status == DrawerStatus.inactive && if (status == DrawerStatus.inactive &&
navigator != null && navigator != null &&
navigator.currentRoute.key == this) navigator.currentRoute is RouteState &&
(navigator.currentRoute as RouteState).owner == this) // TODO(ianh): remove cast once analyzer is cleverer
navigator.pop(); navigator.pop();
if (onStatusChanged != null) if (onStatusChanged != null)
onStatusChanged(status); onStatusChanged(status);
......
...@@ -93,7 +93,8 @@ class Icon extends Component { ...@@ -93,7 +93,8 @@ class Icon extends Component {
return new AssetImage( return new AssetImage(
bundle: _iconBundle, bundle: _iconBundle,
name: '${category}/${density}/ic_${subtype}_${colorSuffix}_${size}dp.png', name: '${category}/${density}/ic_${subtype}_${colorSuffix}_${size}dp.png',
size: new Size(size.toDouble(), size.toDouble()), width: size.toDouble(),
height: size.toDouble(),
colorFilter: colorFilter colorFilter: colorFilter
); );
} }
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:sky' as sky; import 'dart:sky' as sky;
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/animation/curves.dart'; import 'package:sky/animation/curves.dart';
import 'package:sky/rendering/box.dart'; import 'package:sky/rendering/box.dart';
...@@ -29,7 +30,7 @@ double _getSplashTargetSize(Size bounds, Point position) { ...@@ -29,7 +30,7 @@ double _getSplashTargetSize(Size bounds, Point position) {
class InkSplash { class InkSplash {
InkSplash(this.pointer, this.position, this.well) { InkSplash(this.pointer, this.position, this.well) {
_targetRadius = _getSplashTargetSize(well.size, position); _targetRadius = _getSplashTargetSize(well.size, position);
_radius = new AnimatedType<double>( _radius = new AnimatedValue<double>(
_kSplashInitialSize, end: _targetRadius, curve: easeOut); _kSplashInitialSize, end: _targetRadius, curve: easeOut);
_performance = new AnimationPerformance() _performance = new AnimationPerformance()
...@@ -45,7 +46,7 @@ class InkSplash { ...@@ -45,7 +46,7 @@ class InkSplash {
double _targetRadius; double _targetRadius;
double _pinnedRadius; double _pinnedRadius;
AnimatedType<double> _radius; AnimatedValue<double> _radius;
AnimationPerformance _performance; AnimationPerformance _performance;
void _updateVelocity(double velocity) { void _updateVelocity(double velocity) {
......
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/animation/curves.dart'; import 'package:sky/animation/curves.dart';
import 'package:sky/widgets/animated_component.dart'; import 'package:sky/widgets/animated_component.dart';
...@@ -11,25 +12,24 @@ import 'package:vector_math/vector_math.dart'; ...@@ -11,25 +12,24 @@ import 'package:vector_math/vector_math.dart';
typedef Widget Builder(Navigator navigator, RouteBase route); typedef Widget Builder(Navigator navigator, RouteBase route);
abstract class RouteBase { abstract class RouteBase {
RouteBase({ this.key });
final Object key;
Widget build(Navigator navigator, RouteBase route); Widget build(Navigator navigator, RouteBase route);
void popState() { } void popState() { }
} }
class Route extends RouteBase { class Route extends RouteBase {
Route({ String name, this.builder }) : super(key: name); Route({ this.name, this.builder });
String get name => key; final String name;
final Builder builder; final Builder builder;
Widget build(Navigator navigator, RouteBase route) => builder(navigator, route); Widget build(Navigator navigator, RouteBase route) => builder(navigator, route);
} }
class RouteState extends RouteBase { class RouteState extends RouteBase {
RouteState({ this.callback, this.route, Object key }) : super(key: key); RouteState({ this.callback, this.route, this.owner });
RouteBase route;
Function callback; Function callback;
RouteBase route;
StatefulComponent owner;
Widget build(Navigator navigator, RouteBase route) => null; Widget build(Navigator navigator, RouteBase route) => null;
...@@ -59,17 +59,17 @@ class Transition extends AnimatedComponent { ...@@ -59,17 +59,17 @@ class Transition extends AnimatedComponent {
Function onDismissed; Function onDismissed;
Function onCompleted; Function onCompleted;
AnimatedType<Point> _position; AnimatedValue<Point> _position;
AnimatedType<double> _opacity; AnimatedValue<double> _opacity;
AnimationPerformance _performance; AnimationPerformance _performance;
void initState() { void initState() {
_position = new AnimatedType<Point>( _position = new AnimatedValue<Point>(
_kTransitionStartPoint, _kTransitionStartPoint,
end: Point.origin, end: Point.origin,
curve: easeOut curve: easeOut
); );
_opacity = new AnimatedType<double>(0.0, end: 1.0) _opacity = new AnimatedValue<double>(0.0, end: 1.0)
..curve = easeOut; ..curve = easeOut;
_performance = new AnimationPerformance() _performance = new AnimationPerformance()
..duration = _kTransitionDuration ..duration = _kTransitionDuration
...@@ -143,9 +143,8 @@ class Transition extends AnimatedComponent { ...@@ -143,9 +143,8 @@ class Transition extends AnimatedComponent {
} }
class HistoryEntry { class HistoryEntry {
HistoryEntry({ this.route, this.key }); HistoryEntry({ this.route });
final RouteBase route; final RouteBase route;
final int key;
bool transitionFinished = false; bool transitionFinished = false;
// TODO(jackson): Keep track of the requested transition // TODO(jackson): Keep track of the requested transition
} }
...@@ -157,12 +156,11 @@ class NavigationState { ...@@ -157,12 +156,11 @@ class NavigationState {
if (route.name != null) if (route.name != null)
namedRoutes[route.name] = route; namedRoutes[route.name] = route;
} }
history.add(new HistoryEntry(route: routes[0], key: _lastKey++)); history.add(new HistoryEntry(route: routes[0]));
} }
List<HistoryEntry> history = new List<HistoryEntry>(); List<HistoryEntry> history = new List<HistoryEntry>();
int historyIndex = 0; int historyIndex = 0;
int _lastKey = 0;
Map<String, RouteBase> namedRoutes = new Map<String, RouteBase>(); Map<String, RouteBase> namedRoutes = new Map<String, RouteBase>();
RouteBase get currentRoute => history[historyIndex].route; RouteBase get currentRoute => history[historyIndex].route;
...@@ -175,7 +173,7 @@ class NavigationState { ...@@ -175,7 +173,7 @@ class NavigationState {
} }
void push(RouteBase route) { void push(RouteBase route) {
HistoryEntry historyEntry = new HistoryEntry(route: route, key: _lastKey++); HistoryEntry historyEntry = new HistoryEntry(route: route);
history.insert(historyIndex + 1, historyEntry); history.insert(historyIndex + 1, historyEntry);
historyIndex++; historyIndex++;
} }
...@@ -202,9 +200,9 @@ class Navigator extends StatefulComponent { ...@@ -202,9 +200,9 @@ class Navigator extends StatefulComponent {
RouteBase get currentRoute => state.currentRoute; RouteBase get currentRoute => state.currentRoute;
void pushState(Object key, Function callback) { void pushState(StatefulComponent owner, Function callback) {
RouteBase route = new RouteState( RouteBase route = new RouteState(
key: key, owner: owner,
callback: callback, callback: callback,
route: state.currentRoute route: state.currentRoute
); );
...@@ -244,7 +242,7 @@ class Navigator extends StatefulComponent { ...@@ -244,7 +242,7 @@ class Navigator extends StatefulComponent {
if (content == null) if (content == null)
continue; continue;
Transition transition = new Transition( Transition transition = new Transition(
key: historyEntry.key.toString(), key: historyEntry.hashCode.toString(), // TODO(ianh): make it not collide
content: content, content: content,
direction: (i <= state.historyIndex) ? TransitionDirection.forward : TransitionDirection.reverse, direction: (i <= state.historyIndex) ? TransitionDirection.forward : TransitionDirection.reverse,
interactive: (i == state.historyIndex), interactive: (i == state.historyIndex),
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'dart:sky' as sky; import 'dart:sky' as sky;
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/painting/box_painter.dart'; import 'package:sky/painting/box_painter.dart';
import 'package:sky/theme/colors.dart'; import 'package:sky/theme/colors.dart';
...@@ -48,10 +49,10 @@ class PopupMenu extends AnimatedComponent { ...@@ -48,10 +49,10 @@ class PopupMenu extends AnimatedComponent {
int level; int level;
Navigator navigator; Navigator navigator;
AnimatedType<double> _opacity; AnimatedValue<double> _opacity;
AnimatedType<double> _width; AnimatedValue<double> _width;
AnimatedType<double> _height; AnimatedValue<double> _height;
List<AnimatedType<double>> _itemOpacities; List<AnimatedValue<double>> _itemOpacities;
AnimatedList _animationList; AnimatedList _animationList;
AnimationPerformance _performance; AnimationPerformance _performance;
...@@ -88,14 +89,14 @@ class PopupMenu extends AnimatedComponent { ...@@ -88,14 +89,14 @@ class PopupMenu extends AnimatedComponent {
void _updateAnimationVariables() { void _updateAnimationVariables() {
double unit = 1.0 / (items.length + 1.5); // 1.0 for the width and 0.5 for the last item's fade. double unit = 1.0 / (items.length + 1.5); // 1.0 for the width and 0.5 for the last item's fade.
_opacity = new AnimatedType<double>(0.0, end: 1.0); _opacity = new AnimatedValue<double>(0.0, end: 1.0);
_width = new AnimatedType<double>(0.0, end: 1.0, interval: new Interval(0.0, unit)); _width = new AnimatedValue<double>(0.0, end: 1.0, interval: new Interval(0.0, unit));
_height = new AnimatedType<double>(0.0, end: 1.0, interval: new Interval(0.0, unit * items.length)); _height = new AnimatedValue<double>(0.0, end: 1.0, interval: new Interval(0.0, unit * items.length));
_itemOpacities = new List<AnimatedType<double>>(); _itemOpacities = new List<AnimatedValue<double>>();
for (int i = 0; i < items.length; ++i) { for (int i = 0; i < items.length; ++i) {
double start = (i + 1) * unit; double start = (i + 1) * unit;
double end = (start + 1.5 * unit).clamp(0.0, 1.0); double end = (start + 1.5 * unit).clamp(0.0, 1.0);
_itemOpacities.add(new AnimatedType<double>( _itemOpacities.add(new AnimatedValue<double>(
0.0, end: 1.0, interval: new Interval(start, end))); 0.0, end: 1.0, interval: new Interval(start, end)));
} }
List<AnimatedVariable> variables = new List<AnimatedVariable>() List<AnimatedVariable> variables = new List<AnimatedVariable>()
...@@ -122,7 +123,8 @@ class PopupMenu extends AnimatedComponent { ...@@ -122,7 +123,8 @@ class PopupMenu extends AnimatedComponent {
if (_lastStatus != null && status != _lastStatus) { if (_lastStatus != null && status != _lastStatus) {
if (status == PopupMenuStatus.inactive && if (status == PopupMenuStatus.inactive &&
navigator != null && navigator != null &&
navigator.currentRoute.key == this) navigator.currentRoute is RouteState &&
(navigator.currentRoute as RouteState).owner == this) // TODO(ianh): remove cast once analyzer is cleverer
navigator.pop(); navigator.pop();
if (onStatusChanged != null) if (onStatusChanged != null)
onStatusChanged(status); onStatusChanged(status);
......
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
import 'dart:sky' as sky; import 'dart:sky' as sky;
import 'package:sky/animation/animated_value.dart';
import 'package:sky/animation/animation_performance.dart'; import 'package:sky/animation/animation_performance.dart';
import 'package:sky/animation/curves.dart'; import 'package:sky/animation/curves.dart';
import 'package:sky/widgets/animated_component.dart'; import 'package:sky/widgets/animated_component.dart';
...@@ -24,14 +25,14 @@ abstract class Toggleable extends AnimatedComponent { ...@@ -24,14 +25,14 @@ abstract class Toggleable extends AnimatedComponent {
bool value; bool value;
ValueChanged onChanged; ValueChanged onChanged;
AnimatedType<double> _position; AnimatedValue<double> _position;
AnimatedType<double> get position => _position; AnimatedValue<double> get position => _position;
AnimationPerformance _performance; AnimationPerformance _performance;
AnimationPerformance get performance => _performance; AnimationPerformance get performance => _performance;
void initState() { void initState() {
_position = new AnimatedType<double>(0.0, end: 1.0); _position = new AnimatedValue<double>(0.0, end: 1.0);
_performance = new AnimationPerformance() _performance = new AnimationPerformance()
..variable = position ..variable = position
..duration = _kCheckDuration ..duration = _kCheckDuration
......
...@@ -8,6 +8,8 @@ import 'package:sky/widgets/block_viewport.dart'; ...@@ -8,6 +8,8 @@ import 'package:sky/widgets/block_viewport.dart';
import 'package:sky/widgets/scrollable.dart'; import 'package:sky/widgets/scrollable.dart';
import 'package:sky/widgets/widget.dart'; import 'package:sky/widgets/widget.dart';
export 'package:sky/widgets/block_viewport.dart' show BlockViewportLayoutState;
class VariableHeightScrollable extends Scrollable { class VariableHeightScrollable extends Scrollable {
VariableHeightScrollable({ VariableHeightScrollable({
String key, String key,
......
...@@ -6,7 +6,6 @@ import 'dart:async'; ...@@ -6,7 +6,6 @@ import 'dart:async';
import 'dart:collection'; import 'dart:collection';
import 'dart:sky' as sky; import 'dart:sky' as sky;
import 'package:sky/base/debug.dart';
import 'package:sky/base/hit_test.dart'; import 'package:sky/base/hit_test.dart';
import 'package:sky/mojo/activity.dart' as activity; import 'package:sky/mojo/activity.dart' as activity;
import 'package:sky/rendering/box.dart'; import 'package:sky/rendering/box.dart';
...@@ -600,17 +599,20 @@ int _inLayoutCallbackBuilder = 0; ...@@ -600,17 +599,20 @@ int _inLayoutCallbackBuilder = 0;
class LayoutCallbackBuilderHandle { bool _active = true; } class LayoutCallbackBuilderHandle { bool _active = true; }
LayoutCallbackBuilderHandle enterLayoutCallbackBuilder() { LayoutCallbackBuilderHandle enterLayoutCallbackBuilder() {
if (!inDebugBuild) assert(() {
return null; _inLayoutCallbackBuilder += 1;
_inLayoutCallbackBuilder += 1; return true;
});
return new LayoutCallbackBuilderHandle(); return new LayoutCallbackBuilderHandle();
} }
void exitLayoutCallbackBuilder(LayoutCallbackBuilderHandle handle) { void exitLayoutCallbackBuilder(LayoutCallbackBuilderHandle handle) {
if (!inDebugBuild) assert(() {
return; assert(handle._active);
assert(handle._active); handle._active = false;
handle._active = false; _inLayoutCallbackBuilder -= 1;
_inLayoutCallbackBuilder -= 1; return true;
});
Widget._notifyMountStatusChanged();
} }
List<int> _debugFrameTimes = <int>[]; List<int> _debugFrameTimes = <int>[];
......
...@@ -11,4 +11,4 @@ environment: ...@@ -11,4 +11,4 @@ environment:
sdk: '>=1.8.0 <2.0.0' sdk: '>=1.8.0 <2.0.0'
homepage: https://github.com/domokit/mojo/tree/master/sky homepage: https://github.com/domokit/mojo/tree/master/sky
name: sky name: sky
version: 0.0.19 version: 0.0.20
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment