From 4491168fcb301efdde8ea8bb3784494d9cd9c5e3 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Thu, 4 Jun 2015 10:52:12 -0700 Subject: [PATCH] Make FixedHeightScrollable mostly work in fn2 We still need to add a clip and a way to integrate with layout, but those changes are more invasive and I'll do them in separate CLs. R=eseidel@chromium.org, ianh@google.com Review URL: https://codereview.chromium.org/1166983003 --- .../components2/fixed_height_scrollable.dart | 65 +++++++------------ 1 file changed, 22 insertions(+), 43 deletions(-) diff --git a/sdk/lib/framework/components2/fixed_height_scrollable.dart b/sdk/lib/framework/components2/fixed_height_scrollable.dart index b73692ced2b..3a47f86bd04 100644 --- a/sdk/lib/framework/components2/fixed_height_scrollable.dart +++ b/sdk/lib/framework/components2/fixed_height_scrollable.dart @@ -3,27 +3,14 @@ // found in the LICENSE file. import '../animation/scroll_behavior.dart'; -import '../debug/tracing.dart'; import '../fn2.dart'; -import 'dart:math' as math; import 'dart:async'; +import 'dart:math' as math; +import 'package:vector_math/vector_math.dart'; import 'scrollable.dart'; abstract class FixedHeightScrollable extends Scrollable { - static final Style _style = new Style(''' - overflow: hidden; - position: relative; - will-change: transform;''' - ); - - static final Style _scrollAreaStyle = new Style(''' - position:relative; - will-change: transform;''' - ); - - FixedHeightScrollable({ - Object key - }) : super(key: key); + FixedHeightScrollable({ Object key }) : super(key: key); ScrollBehavior createScrollBehavior() => new OverscrollBehavior(); OverscrollBehavior get scrollBehavior => super.scrollBehavior as OverscrollBehavior; @@ -42,23 +29,16 @@ abstract class FixedHeightScrollable extends Scrollable { } void _measureHeights() { - trace('FixedHeightScrollable::_measureHeights', () { - if (_itemHeight != null) - return; - var root = getRoot(); - if (root == null) - return; - var item = root.firstChild.firstChild; - if (item == null) - return; - setState(() { - _height = root.height; - assert(_height > 0); - _itemHeight = item.height; - assert(_itemHeight > 0); - scrollBehavior.containerHeight = _height; - scrollBehavior.contentsHeight = _itemHeight * _itemCount; - }); + if (_itemHeight != null) + return; + setState(() { + // TODO(abarth): Actually measure these heights. + _height = 500.0; // root.height; + assert(_height > 0); + _itemHeight = 100.0; // item.height; + assert(_itemHeight > 0); + scrollBehavior.containerHeight = _height; + scrollBehavior.contentsHeight = _itemHeight * _itemCount; }); } @@ -70,12 +50,13 @@ abstract class FixedHeightScrollable extends Scrollable { if (_itemHeight == null) new Future.microtask(_measureHeights); + Matrix4 transform = new Matrix4.identity(); + if (_height > 0.0 && _itemHeight != null) { if (scrollOffset < 0.0) { double visibleHeight = _height + scrollOffset; drawCount = (visibleHeight / _itemHeight).round() + 1; - transformStyle = - 'transform: translateY(${(-scrollOffset).toStringAsFixed(2)}px)'; + transform.translate(0.0, -scrollOffset); } else { drawCount = (_height / _itemHeight).ceil() + 1; double alignmentDelta = -scrollOffset % _itemHeight; @@ -85,18 +66,16 @@ abstract class FixedHeightScrollable extends Scrollable { double drawStart = scrollOffset + alignmentDelta; itemNumber = math.max(0, (drawStart / _itemHeight).floor()); - transformStyle = - 'transform: translateY(${(alignmentDelta).toStringAsFixed(2)}px)'; + transform.translate(0.0, alignmentDelta); } } - return new Container( - style: _style, + // TODO(abarth): Add a clip. + return new BlockContainer( children: [ - new Container( - style: _scrollAreaStyle, - inlineStyle: transformStyle, - children: buildItems(itemNumber, drawCount) + new Transform( + transform: transform, + child: new BlockContainer(children: buildItems(itemNumber, drawCount)) ) ] );