Commit b7d9e475 authored by Rafael Weinstein's avatar Rafael Weinstein

Ensure that sky Nodes are in the document when didMount() is fired. Refactor...

Ensure that sky Nodes are in the document when didMount() is fired. Refactor FixedHeightScrollable to inspect heights rather than having the passed in

BUG=
R=abarth@chromium.org

Review URL: https://codereview.chromium.org/994553003
parent 440185f8
...@@ -2,9 +2,13 @@ part of widgets; ...@@ -2,9 +2,13 @@ part of widgets;
abstract class FixedHeightScrollable extends Component { abstract class FixedHeightScrollable extends Component {
// TODO(rafaelw): This component really shouldn't have an opinion
// about how it is sized. The owning component should decide whether
// it's explicitly sized or flexible or whatever...
static Style _style = new Style(''' static Style _style = new Style('''
overflow: hidden; overflow: hidden;
position: relative; position: relative;
flex: 1;
will-change: transform;''' will-change: transform;'''
); );
...@@ -13,40 +17,55 @@ abstract class FixedHeightScrollable extends Component { ...@@ -13,40 +17,55 @@ abstract class FixedHeightScrollable extends Component {
will-change: transform;''' will-change: transform;'''
); );
double itemHeight;
double height;
double minOffset; double minOffset;
double maxOffset; double maxOffset;
double _scrollOffset = 0.0; double _scrollOffset = 0.0;
FlingCurve _flingCurve; FlingCurve _flingCurve;
int _flingAnimationId; int _flingAnimationId;
double _height = 0.0;
double _itemHeight;
FixedHeightScrollable({ FixedHeightScrollable({
Object key, Object key,
this.itemHeight,
this.height,
this.minOffset, this.minOffset,
this.maxOffset this.maxOffset
}) : super(key: key) {} }) : super(key: key) {}
List<Node> renderItems(int start, int count); List<Node> renderItems(int start, int count);
void didMount() {
var root = getRoot();
var item = root.firstChild.firstChild;
sky.ClientRect scrollRect = root.getBoundingClientRect();
sky.ClientRect itemRect = item.getBoundingClientRect();
assert(scrollRect.height > 0);
assert(itemRect.height > 0);
setState(() {
_height = scrollRect.height;
_itemHeight = itemRect.height;
});
}
Node render() { Node render() {
int drawCount = (height / itemHeight).round() + 1; var itemNumber = 0;
double alignmentDelta = -_scrollOffset % itemHeight; var drawCount = 1;
var transformStyle = '';
if (_height > 0.0) {
drawCount = (_height / _itemHeight).round() + 1;
double alignmentDelta = -_scrollOffset % _itemHeight;
if (alignmentDelta != 0.0) { if (alignmentDelta != 0.0) {
alignmentDelta -= itemHeight; alignmentDelta -= _itemHeight;
} }
double drawStart = _scrollOffset + alignmentDelta; double drawStart = _scrollOffset + alignmentDelta;
int itemNumber = (drawStart / itemHeight).floor(); itemNumber = (drawStart / _itemHeight).floor();
var transformStyle = transformStyle =
'transform: translateY(${(alignmentDelta).toStringAsFixed(2)}px)'; 'transform: translateY(${(alignmentDelta).toStringAsFixed(2)}px)';
}
var items = renderItems(itemNumber, drawCount);
return new Container( return new Container(
style: _style, style: _style,
...@@ -54,7 +73,7 @@ abstract class FixedHeightScrollable extends Component { ...@@ -54,7 +73,7 @@ abstract class FixedHeightScrollable extends Component {
new Container( new Container(
style: _scrollAreaStyle, style: _scrollAreaStyle,
inlineStyle: transformStyle, inlineStyle: transformStyle,
children: items children: renderItems(itemNumber, drawCount)
) )
] ]
) )
......
...@@ -7,7 +7,7 @@ class Stocklist extends FixedHeightScrollable { ...@@ -7,7 +7,7 @@ class Stocklist extends FixedHeightScrollable {
Stocklist({ Stocklist({
Object key, Object key,
this.stocks this.stocks
}) : super(key: key, itemHeight: 80.0, height: 800.0, minOffset: 0.0); }) : super(key: key, minOffset: 0.0);
List<Node> renderItems(int start, int count) { List<Node> renderItems(int start, int count) {
var items = []; var items = [];
......
...@@ -6,7 +6,6 @@ class StockRow extends MaterialComponent { ...@@ -6,7 +6,6 @@ class StockRow extends MaterialComponent {
static Style _style = new Style(''' static Style _style = new Style('''
transform: translateX(0); transform: translateX(0);
max-height: 48px;
display: flex; display: flex;
align-items: center; align-items: center;
border-bottom: 1px solid #F4F4F4; border-bottom: 1px solid #F4F4F4;
......
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