diff --git a/examples/stocks-fn/lib/stock_app.dart b/examples/stocks-fn/lib/stock_app.dart index f79c26ad182..87f5e6dca77 100644 --- a/examples/stocks-fn/lib/stock_app.dart +++ b/examples/stocks-fn/lib/stock_app.dart @@ -40,6 +40,10 @@ class StocksApp extends App { ${typography.white.title};''' ); + static Style _stocklistHeight = new Style(''' + flex: 1;''' + ); + List _sortedStocks; bool _isSearching = false; bool _isShowingMenu = false; @@ -137,7 +141,9 @@ class StocksApp extends App { ] ); - var list = new Stocklist(stocks: _sortedStocks, query: _searchQuery); + var list = new StyleNode( + new Stocklist(stocks: _sortedStocks, query: _searchQuery), + _stocklistHeight); var fab = new FloatingActionButton(content: new Icon( type: 'content/add_white', size: 24), level: 3); diff --git a/framework/components/fixed_height_scrollable.dart b/framework/components/fixed_height_scrollable.dart index 500af2e27f6..4b5f86d1dac 100644 --- a/framework/components/fixed_height_scrollable.dart +++ b/framework/components/fixed_height_scrollable.dart @@ -9,13 +9,9 @@ import 'dart:sky' as sky; import 'scrollable.dart'; abstract class FixedHeightScrollable extends Scrollable { - // 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 final Style _style = new Style(''' overflow: hidden; position: relative; - flex: 1; will-change: transform;''' ); diff --git a/framework/fn.dart b/framework/fn.dart index 7aa23d59e68..0f16769849d 100644 --- a/framework/fn.dart +++ b/framework/fn.dart @@ -52,6 +52,29 @@ class Style { Style._internal(this._className); } +abstract class ContentNode extends Node { + Node content; + + ContentNode(Node content) : this.content = content, super(key: content._key); + + void _sync(Node old, sky.ParentNode host, sky.Node insertBefore) { + Node oldContent = old == null ? null : (old as ContentNode).content; + content = _syncChild(content, oldContent, host, insertBefore); + _root = content._root; + } + + void _remove() { + _removeChild(content); + super._remove(); + } +} + +class StyleNode extends ContentNode { + final Style style; + + StyleNode(Node content, this.style): super(content); +} + void _parentInsertBefore(sky.ParentNode parent, sky.Node node, sky.Node ref) { @@ -133,8 +156,7 @@ abstract class Node { // new component was built that could re-use some of it. Consider // syncing the new VDOM against the old one. if (oldNode != null && node._key != oldNode._key) { - _trace('_sync(remove) ${node._key}'); - oldNode._remove(); + _removeChild(oldNode); } if (node._willSync(oldNode)) { @@ -207,8 +229,7 @@ typedef GestureEventListener(sky.GestureEvent e); typedef PointerEventListener(sky.PointerEvent e); typedef EventListener(sky.Event e); -class EventTarget extends Node { - Node content; +class EventTarget extends ContentNode { final Map listeners; static final Set _registeredEvents = new HashSet(); @@ -270,8 +291,7 @@ class EventTarget extends Node { PointerEventListener onPointerMove, PointerEventListener onPointerUp, Map custom - }) : this.content = content, - listeners = _createListeners( + }) : listeners = _createListeners( onWheel: onWheel, onGestureFlingCancel: onGestureFlingCancel, onGestureFlingStart: onGestureFlingStart, @@ -285,7 +305,7 @@ class EventTarget extends Node { onPointerUp: onPointerUp, custom: custom ), - super(key: content._key); + super(content); void _handleEvent(sky.Event e) { sky.EventListener listener = listeners[e.type]; @@ -318,14 +338,7 @@ class EventTarget extends Node { _ensureDocumentListener(type); } - Node oldContent = old == null ? null : (old as EventTarget).content; - content = _syncChild(content, oldContent , host, insertBefore); - _root = content._root; - } - - void _remove() { - _removeChild(content); - super._remove(); + super._sync(old, host, insertBefore); } } @@ -362,18 +375,18 @@ abstract class Element extends RenderNode { sky.Node _createNode() => sky.document.createElement(_tagName); + final List children; + final Style style; final String inlineStyle; - final List _children; - final String _class; + String _class; Element({ Object key, List children, - Style style, + this.style, this.inlineStyle - }) : _class = style == null ? '' : style._className, - _children = children == null ? _emptyList : children, + }) : this.children = children == null ? _emptyList : children, super(key:key) { if (_isInCheckedMode) { @@ -383,8 +396,8 @@ abstract class Element extends RenderNode { void _remove() { super._remove(); - if (_children != null) { - for (var child in _children) { + if (children != null) { + for (var child in children) { _removeChild(child); } } @@ -392,7 +405,7 @@ abstract class Element extends RenderNode { void _debugReportDuplicateIds() { var idSet = new HashSet(); - for (var child in _children) { + for (var child in children) { if (child is Text) { continue; // Text nodes all have the same key and are never reordered. } @@ -404,10 +417,30 @@ abstract class Element extends RenderNode { } } + void _ensureClass() { + if (_class == null) { + List