From c354abc7e0a7cb9c061e47a4669c013aaeedbf94 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Fri, 21 Aug 2015 14:13:03 -0700 Subject: [PATCH] Rename all the scrollable classes Block -> BlockBody ScrollableBlock -> Block FixedHeightScrollable -> ScrollableWidgetList VariableHeightScrollable -> ScrollableMixedWidgetList BlockViewport -> MixedViewport --- examples/address_book/lib/main.dart | 4 +- examples/fitness/lib/feed.dart | 2 +- examples/fitness/lib/meal.dart | 2 +- examples/fitness/lib/measurement.dart | 2 +- examples/fitness/lib/settings.dart | 2 +- examples/stocks/lib/stock_settings.dart | 2 +- examples/widgets/card_collection.dart | 4 +- examples/widgets/ensure_visible.dart | 4 +- examples/widgets/horizontal_scrolling.dart | 2 +- ...lock_viewport.dart => mixed_viewport.dart} | 8 ++-- examples/widgets/overlay_geometry.dart | 4 +- examples/widgets/pop_out_and_expand.dart | 2 +- sky/packages/sky/lib/widgets.dart | 2 +- sky/packages/sky/lib/widgets/basic.dart | 4 +- sky/packages/sky/lib/widgets/dialog.dart | 2 +- sky/packages/sky/lib/widgets/drawer.dart | 2 +- ...lock_viewport.dart => mixed_viewport.dart} | 14 +++---- sky/packages/sky/lib/widgets/popup_menu.dart | 2 +- sky/packages/sky/lib/widgets/scrollable.dart | 42 +++++++++---------- sky/packages/sky/lib/widgets/widgets.md | 8 ---- 20 files changed, 53 insertions(+), 61 deletions(-) rename examples/widgets/{block_viewport.dart => mixed_viewport.dart} (95%) rename sky/packages/sky/lib/widgets/{block_viewport.dart => mixed_viewport.dart} (97%) diff --git a/examples/address_book/lib/main.dart b/examples/address_book/lib/main.dart index 321d529c693..ebc84a9de0a 100644 --- a/examples/address_book/lib/main.dart +++ b/examples/address_book/lib/main.dart @@ -54,7 +54,7 @@ class AddressBookApp extends App { showDialog(navigator, (navigator) { return new Dialog( title: new Text("Describe your picture"), - content: new ScrollableBlock([ + content: new Block([ new Field(inputKey: fillKey, icon: "editor/format_color_fill", placeholder: "Color"), new Field(inputKey: emoticonKey, icon: "editor/insert_emoticon", placeholder: "Emotion"), ]), @@ -88,7 +88,7 @@ class AddressBookApp extends App { Widget buildBody(Navigator navigator) { return new Material( - child: new ScrollableBlock([ + child: new Block([ new AspectRatio( aspectRatio: 16.0 / 9.0, child: new Container( diff --git a/examples/fitness/lib/feed.dart b/examples/fitness/lib/feed.dart index d9ae7361836..06943f92454 100644 --- a/examples/fitness/lib/feed.dart +++ b/examples/fitness/lib/feed.dart @@ -324,7 +324,7 @@ class AddItemDialog extends StatefulComponent { } return new Dialog( title: new Text("What are you doing?"), - content: new ScrollableBlock(menuItems), + content: new Block(menuItems), onDismiss: navigator.pop, actions: [ new FlatButton( diff --git a/examples/fitness/lib/meal.dart b/examples/fitness/lib/meal.dart index deaccd09dc1..8969214632c 100644 --- a/examples/fitness/lib/meal.dart +++ b/examples/fitness/lib/meal.dart @@ -92,7 +92,7 @@ class MealFragment extends StatefulComponent { child: new ScrollableViewport( child: new Container( padding: const EdgeDims.all(20.0), - child: new Block([ + child: new BlockBody([ new Text(meal.displayDate), new Input( key: descriptionKey, diff --git a/examples/fitness/lib/measurement.dart b/examples/fitness/lib/measurement.dart index 19d9bef9123..ea8e4a9fa6f 100644 --- a/examples/fitness/lib/measurement.dart +++ b/examples/fitness/lib/measurement.dart @@ -114,7 +114,7 @@ class MeasurementFragment extends StatefulComponent { child: new ScrollableViewport( child: new Container( padding: const EdgeDims.all(20.0), - child: new Block([ + child: new BlockBody([ new Text(measurement.displayDate), new Input( key: weightKey, diff --git a/examples/fitness/lib/settings.dart b/examples/fitness/lib/settings.dart index b51ec049ba2..be25ce0666a 100644 --- a/examples/fitness/lib/settings.dart +++ b/examples/fitness/lib/settings.dart @@ -109,7 +109,7 @@ class SettingsFragment extends StatefulComponent { child: new ScrollableViewport( child: new Container( padding: const EdgeDims.symmetric(vertical: 20.0), - child: new Block([ + child: new BlockBody([ new DrawerItem( onPressed: () { _handleBackupChanged(!(userData.backupMode == BackupMode.enabled)); }, children: [ diff --git a/examples/stocks/lib/stock_settings.dart b/examples/stocks/lib/stock_settings.dart index d3a4977d7b8..a97fd16ca56 100644 --- a/examples/stocks/lib/stock_settings.dart +++ b/examples/stocks/lib/stock_settings.dart @@ -98,7 +98,7 @@ class StockSettings extends StatefulComponent { child: new ScrollableViewport( child: new Container( padding: const EdgeDims.symmetric(vertical: 20.0), - child: new Block([ + child: new BlockBody([ new DrawerItem( icon: 'action/thumb_up', onPressed: () => _confirmOptimismChange(), diff --git a/examples/widgets/card_collection.dart b/examples/widgets/card_collection.dart index e74371163e6..95cf8d49ffb 100644 --- a/examples/widgets/card_collection.dart +++ b/examples/widgets/card_collection.dart @@ -24,7 +24,7 @@ class CardCollectionApp extends App { final TextStyle backgroundTextStyle = typography.white.title.copyWith(textAlign: TextAlign.center); - BlockViewportLayoutState layoutState = new BlockViewportLayoutState(); + MixedViewportLayoutState layoutState = new MixedViewportLayoutState(); List cardModels; void initState() { @@ -102,7 +102,7 @@ class CardCollectionApp extends App { Widget cardCollection = new Container( padding: const EdgeDims.symmetric(vertical: 12.0, horizontal: 8.0), decoration: new BoxDecoration(backgroundColor: Theme.of(this).primarySwatch[50]), - child: new VariableHeightScrollable( + child: new ScrollableMixedWidgetList( builder: builder, token: cardModels.length, layoutState: layoutState diff --git a/examples/widgets/ensure_visible.dart b/examples/widgets/ensure_visible.dart index 8da1d3abed0..fb0e4171ad2 100644 --- a/examples/widgets/ensure_visible.dart +++ b/examples/widgets/ensure_visible.dart @@ -24,7 +24,7 @@ class EnsureVisibleApp extends App { const TextStyle(color: colors.white, fontSize: 24.0, fontWeight: bold); List cardModels; - BlockViewportLayoutState layoutState = new BlockViewportLayoutState(); + MixedViewportLayoutState layoutState = new MixedViewportLayoutState(); CardModel selectedCardModel; void initState() { @@ -74,7 +74,7 @@ class EnsureVisibleApp extends App { Widget cardCollection = new Container( padding: const EdgeDims.symmetric(vertical: 12.0, horizontal: 8.0), decoration: new BoxDecoration(backgroundColor: Theme.of(this).primarySwatch[50]), - child: new VariableHeightScrollable( + child: new ScrollableMixedWidgetList( builder: builder, token: cardModels.length, layoutState: layoutState diff --git a/examples/widgets/horizontal_scrolling.dart b/examples/widgets/horizontal_scrolling.dart index a19cc541a71..6ab4cf42a6a 100644 --- a/examples/widgets/horizontal_scrolling.dart +++ b/examples/widgets/horizontal_scrolling.dart @@ -42,7 +42,7 @@ class HorizontalScrollingApp extends App { child: new Container( height: 50.0, child: new Flex([ - new ScrollableBlock(circles, scrollDirection: ScrollDirection.horizontal) + new Block(circles, scrollDirection: ScrollDirection.horizontal) ], justifyContent: FlexJustifyContent.end) ) ); diff --git a/examples/widgets/block_viewport.dart b/examples/widgets/mixed_viewport.dart similarity index 95% rename from examples/widgets/block_viewport.dart rename to examples/widgets/mixed_viewport.dart index ee8b5fe450c..1420b206b76 100644 --- a/examples/widgets/block_viewport.dart +++ b/examples/widgets/mixed_viewport.dart @@ -6,9 +6,9 @@ import 'dart:math' as math; import 'package:sky/widgets.dart'; -class BlockViewportApp extends App { +class MixedViewportApp extends App { - BlockViewportLayoutState layoutState = new BlockViewportLayoutState(); + MixedViewportLayoutState layoutState = new MixedViewportLayoutState(); List lengths = []; double offset = 0.0; @@ -87,7 +87,7 @@ class BlockViewportApp extends App { border: new Border.all(color: new Color(0xFF000000)) ), padding: new EdgeDims.all(16.0), - child: new BlockViewport( + child: new MixedViewport( builder: builder, startOffset: offset, token: lengths.length, @@ -124,7 +124,7 @@ class BlockViewportApp extends App { } void main() { - runApp(new BlockViewportApp()); + runApp(new MixedViewportApp()); // scheduler.addPersistentFrameCallback((_) { // SkyBinding.instance.debugDumpRenderTree(); // }); diff --git a/examples/widgets/overlay_geometry.dart b/examples/widgets/overlay_geometry.dart index fdf89fc870a..e31311ece37 100644 --- a/examples/widgets/overlay_geometry.dart +++ b/examples/widgets/overlay_geometry.dart @@ -71,7 +71,7 @@ class OverlayGeometryApp extends App { const TextStyle(color: colors.white, fontSize: 18.0, fontWeight: bold); List cardModels; - BlockViewportLayoutState layoutState = new BlockViewportLayoutState(); + MixedViewportLayoutState layoutState = new MixedViewportLayoutState(); Map markers = new Map(); double markersScrollOffset; ScrollListener scrollListener; @@ -138,7 +138,7 @@ class OverlayGeometryApp extends App { } Widget build() { - Scrollable scrollable = new VariableHeightScrollable( + Scrollable scrollable = new ScrollableMixedWidgetList( builder: builder, token: cardModels.length, layoutState: layoutState diff --git a/examples/widgets/pop_out_and_expand.dart b/examples/widgets/pop_out_and_expand.dart index b01b60bed6d..1924e6846ef 100644 --- a/examples/widgets/pop_out_and_expand.dart +++ b/examples/widgets/pop_out_and_expand.dart @@ -91,7 +91,7 @@ class ExampleApp extends App { body: new MimicOverlay( overlay: _overlay, duration: const Duration(milliseconds: 500), - children: [ new ScrollableBlock(cards) ] + children: [ new Block(cards) ] ) ) ) diff --git a/sky/packages/sky/lib/widgets.dart b/sky/packages/sky/lib/widgets.dart index 16ddebaf912..9e95d5da906 100644 --- a/sky/packages/sky/lib/widgets.dart +++ b/sky/packages/sky/lib/widgets.dart @@ -7,7 +7,6 @@ export 'widgets/animated_component.dart'; export 'widgets/animated_container.dart'; export 'widgets/basic.dart'; -export 'widgets/block_viewport.dart'; export 'widgets/button_base.dart'; export 'widgets/card.dart'; export 'widgets/checkbox.dart'; @@ -30,6 +29,7 @@ export 'widgets/material.dart'; export 'widgets/material_button.dart'; export 'widgets/mimic.dart'; export 'widgets/mimic_overlay.dart'; +export 'widgets/mixed_viewport.dart'; export 'widgets/modal_overlay.dart'; export 'widgets/navigator.dart'; export 'widgets/popup_menu.dart'; diff --git a/sky/packages/sky/lib/widgets/basic.dart b/sky/packages/sky/lib/widgets/basic.dart index 024751dd1a9..6606d311849 100644 --- a/sky/packages/sky/lib/widgets/basic.dart +++ b/sky/packages/sky/lib/widgets/basic.dart @@ -407,8 +407,8 @@ class Container extends Component { // LAYOUT NODES -class Block extends MultiChildRenderObjectWrapper { - Block(List children, { +class BlockBody extends MultiChildRenderObjectWrapper { + BlockBody(List children, { Key key, this.direction: BlockDirection.vertical }) : super(key: key, children: children); diff --git a/sky/packages/sky/lib/widgets/dialog.dart b/sky/packages/sky/lib/widgets/dialog.dart index 98e8840517c..608f9f507b5 100644 --- a/sky/packages/sky/lib/widgets/dialog.dart +++ b/sky/packages/sky/lib/widgets/dialog.dart @@ -99,7 +99,7 @@ class Dialog extends Component { level: 4, color: _color, child: new ShrinkWrapWidth( - child: new ScrollableBlock(dialogBody) + child: new Block(dialogBody) ) ) ) diff --git a/sky/packages/sky/lib/widgets/drawer.dart b/sky/packages/sky/lib/widgets/drawer.dart index 8bb184da2d5..c80db53aca4 100644 --- a/sky/packages/sky/lib/widgets/drawer.dart +++ b/sky/packages/sky/lib/widgets/drawer.dart @@ -105,7 +105,7 @@ class Drawer extends StatefulComponent { backgroundColor: Theme.of(this).canvasColor, boxShadow: shadows[level]), width: _kWidth, - child: new ScrollableBlock(children) + child: new Block(children) ) ); diff --git a/sky/packages/sky/lib/widgets/block_viewport.dart b/sky/packages/sky/lib/widgets/mixed_viewport.dart similarity index 97% rename from sky/packages/sky/lib/widgets/block_viewport.dart rename to sky/packages/sky/lib/widgets/mixed_viewport.dart index 1ce2c3d95f1..3b8ce4f1f9b 100644 --- a/sky/packages/sky/lib/widgets/block_viewport.dart +++ b/sky/packages/sky/lib/widgets/mixed_viewport.dart @@ -24,8 +24,8 @@ class _Key { typedef void LayoutChangedCallback(); -class BlockViewportLayoutState { - BlockViewportLayoutState() +class MixedViewportLayoutState { + MixedViewportLayoutState() : _childOffsets = [0.0], _firstVisibleChildIndex = 0, _visibleChildCount = 0, @@ -77,8 +77,8 @@ class BlockViewportLayoutState { } } -class BlockViewport extends RenderObjectWrapper { - BlockViewport({ this.builder, this.startOffset, this.token, this.layoutState, Key key }) +class MixedViewport extends RenderObjectWrapper { + MixedViewport({ this.builder, this.startOffset, this.token, this.layoutState, Key key }) : super(key: key) { assert(this.layoutState != null); } @@ -86,7 +86,7 @@ class BlockViewport extends RenderObjectWrapper { IndexedBuilder builder; double startOffset; Object token; - BlockViewportLayoutState layoutState; + MixedViewportLayoutState layoutState; RenderBlockViewport get renderObject => super.renderObject; RenderBlockViewport createNode() => new RenderBlockViewport(); @@ -144,7 +144,7 @@ class BlockViewport extends RenderObjectWrapper { return right; } - bool retainStatefulNodeIfPossible(BlockViewport newNode) { + bool retainStatefulNodeIfPossible(MixedViewport newNode) { assert(layoutState == newNode.layoutState); retainStatefulRenderObjectWrapper(newNode); if (startOffset != newNode.startOffset) { @@ -162,7 +162,7 @@ class BlockViewport extends RenderObjectWrapper { return true; } - void syncRenderObject(BlockViewport old) { + void syncRenderObject(MixedViewport old) { super.syncRenderObject(old); if (layoutState._dirty || !layoutState.isValid) { renderObject.markNeedsLayout(); diff --git a/sky/packages/sky/lib/widgets/popup_menu.dart b/sky/packages/sky/lib/widgets/popup_menu.dart index 46ba861bed6..d678b96b3da 100644 --- a/sky/packages/sky/lib/widgets/popup_menu.dart +++ b/sky/packages/sky/lib/widgets/popup_menu.dart @@ -142,7 +142,7 @@ class PopupMenu extends StatefulComponent { horizontal: _kMenuHorizontalPadding, vertical: _kMenuVerticalPadding ), - child: new Block(children) + child: new BlockBody(children) ) ) ) diff --git a/sky/packages/sky/lib/widgets/scrollable.dart b/sky/packages/sky/lib/widgets/scrollable.dart index a24dbecaca4..515f2e519b4 100644 --- a/sky/packages/sky/lib/widgets/scrollable.dart +++ b/sky/packages/sky/lib/widgets/scrollable.dart @@ -16,11 +16,11 @@ import 'package:sky/rendering/box.dart'; import 'package:sky/rendering/viewport.dart'; import 'package:sky/theme/view_configuration.dart' as config; import 'package:sky/widgets/basic.dart'; -import 'package:sky/widgets/block_viewport.dart'; -import 'package:sky/widgets/scrollable.dart'; import 'package:sky/widgets/framework.dart'; +import 'package:sky/widgets/mixed_viewport.dart'; +import 'package:sky/widgets/scrollable.dart'; -export 'package:sky/widgets/block_viewport.dart' show BlockViewportLayoutState; +export 'package:sky/widgets/mixed_viewport.dart' show MixedViewportLayoutState; // The GestureEvent velocity properties are pixels/second, config min,max limits are pixels/ms @@ -314,11 +314,11 @@ class ScrollableViewport extends Scrollable { } } -/// A mashup of [ScrollableViewport] and [Block]. Useful when you have a small, +/// A mashup of [ScrollableViewport] and [BlockBody]. Useful when you have a small, /// fixed number of children that you wish to arrange in a block layout and that /// might exceed the height of its container (and therefore need to scroll). -class ScrollableBlock extends Component { - ScrollableBlock(this.children, { +class Block extends Component { + Block(this.children, { Key key, this.scrollDirection: ScrollDirection.vertical }) : super(key: key); @@ -335,7 +335,7 @@ class ScrollableBlock extends Component { Widget build() { return new ScrollableViewport( scrollDirection: scrollDirection, - child: new Block(children, direction: _direction) + child: new BlockBody(children, direction: _direction) ); } } @@ -345,9 +345,9 @@ class ScrollableBlock extends Component { /// ScrollDirection.vertical itemExtent is the height of each item. Use this /// widget when you have a large number of children or when you are concerned // about offscreen widgets consuming resources. -abstract class FixedHeightScrollable extends Scrollable { +abstract class ScrollableWidgetList extends Scrollable { - FixedHeightScrollable({ + ScrollableWidgetList({ Key key, ScrollDirection scrollDirection: ScrollDirection.vertical, this.itemExtent, @@ -360,12 +360,12 @@ abstract class FixedHeightScrollable extends Scrollable { double itemExtent; Size containerSize = Size.zero; - /// Subclasses must implement `get itemCount` to tell FixedHeightScrollable + /// Subclasses must implement `get itemCount` to tell ScrollableWidgetList /// how many items there are in the list. int get itemCount; int _previousItemCount; - void syncFields(FixedHeightScrollable source) { + void syncFields(ScrollableWidgetList source) { bool scrollBehaviorUpdateNeeded = padding != source.padding || itemExtent != source.itemExtent || @@ -478,7 +478,7 @@ abstract class FixedHeightScrollable extends Scrollable { : BlockDirection.horizontal; // TODO(ianh): Refactor this so that it does the building in the - // same frame as the size observing, similar to BlockViewport, but + // same frame as the size observing, similar to MixedViewport, but // keeping the fixed-height optimisations. return new SizeObserver( callback: _handleSizeChanged, @@ -487,7 +487,7 @@ abstract class FixedHeightScrollable extends Scrollable { scrollOffset: viewportOffset, child: new Container( padding: _crossAxisPadding, - child: new Block(items, direction: blockDirection) + child: new BlockBody(items, direction: blockDirection) ) ) ); @@ -499,10 +499,10 @@ abstract class FixedHeightScrollable extends Scrollable { typedef Widget ItemBuilder(T item); -/// A wrapper around [FixedHeightScrollable] that helps you translate a list of +/// A wrapper around [ScrollableWidgetList] that helps you translate a list of /// model objects into a scrollable list of widgets. Assumes all the widgets /// have the same height. -class ScrollableList extends FixedHeightScrollable { +class ScrollableList extends ScrollableWidgetList { ScrollableList({ Key key, ScrollDirection scrollDirection: ScrollDirection.vertical, @@ -588,11 +588,11 @@ class PageableList extends ScrollableList { } /// A general scrollable list for a large number of children that might not all -/// have the same height. Prefer [FixedHeightScrollable] when all the children +/// have the same height. Prefer [ScrollableWidgetList] when all the children /// have the same height because it can use that property to be more efficient. /// Prefer [ScrollableViewport] with a single child. -class VariableHeightScrollable extends Scrollable { - VariableHeightScrollable({ +class ScrollableMixedWidgetList extends Scrollable { + ScrollableMixedWidgetList({ Key key, this.builder, this.token, @@ -601,7 +601,7 @@ class VariableHeightScrollable extends Scrollable { IndexedBuilder builder; Object token; - BlockViewportLayoutState layoutState; + MixedViewportLayoutState layoutState; // When the token changes the scrollable's contents may have // changed. Remember as much so that after the new contents @@ -624,7 +624,7 @@ class VariableHeightScrollable extends Scrollable { super.didUnmount(); } - void syncFields(VariableHeightScrollable source) { + void syncFields(ScrollableMixedWidgetList source) { builder = source.builder; if (token != source.token) _contentsChanged = true; @@ -661,7 +661,7 @@ class VariableHeightScrollable extends Scrollable { Widget buildContent() { return new SizeObserver( callback: _handleSizeChanged, - child: new BlockViewport( + child: new MixedViewport( builder: builder, layoutState: layoutState, startOffset: scrollOffset, diff --git a/sky/packages/sky/lib/widgets/widgets.md b/sky/packages/sky/lib/widgets/widgets.md index 68dcc48a960..f32afa22150 100644 --- a/sky/packages/sky/lib/widgets/widgets.md +++ b/sky/packages/sky/lib/widgets/widgets.md @@ -59,14 +59,6 @@ Layout models `right` and `left` properties to non-null values will force the child to have a particular width. - - `Block` Layout a list of child widgets in a vertical line. Each child's width - is set to the widget of the block, and each child is positioned directly - below the previous child. The block's height is set to the total height of - all of its children. A block can be used only in locations that offer an - unbounded amount of vertical space (e.g., inside a `Viewport`). Rather than - using `Block` directly, most client should use `ScrollableBlock`, which - combines `Block` with `Viewport` and scrolling physics. - Positioning and sizing ----------------------