Commit c4545da2 authored by Adam Barth's avatar Adam Barth

Merge pull request #1172 from abarth/simplify_tabview

Simplify TabView API
parents f757211f dd08bf79
...@@ -85,9 +85,8 @@ class TabViewDemo extends StatelessComponent { ...@@ -85,9 +85,8 @@ class TabViewDemo extends StatelessComponent {
) )
), ),
new Flexible( new Flexible(
child: new TabBarView<String>( child: new TabBarView(
items: _iconNames, children: _iconNames.map(_buildTabView).toList()
itemBuilder: _buildTabView
) )
) )
]); ]);
......
...@@ -27,9 +27,8 @@ class TabsDemo extends StatefulComponent { ...@@ -27,9 +27,8 @@ class TabsDemo extends StatefulComponent {
class _TabsDemoState extends State<TabsDemo> { class _TabsDemoState extends State<TabsDemo> {
Widget build(_) { Widget build(_) {
return new TabBarView<String>( return new TabBarView(
items: _iconNames, children: _iconNames.map((String iconName) {
itemBuilder: (String iconName) {
return new Container( return new Container(
key: new ValueKey<String>(iconName), key: new ValueKey<String>(iconName),
padding: const EdgeDims.all(12.0), padding: const EdgeDims.all(12.0),
...@@ -37,7 +36,7 @@ class _TabsDemoState extends State<TabsDemo> { ...@@ -37,7 +36,7 @@ class _TabsDemoState extends State<TabsDemo> {
child: new Center(child: new Icon(icon: "action/$iconName", size:IconSize.s48)) child: new Center(child: new Icon(icon: "action/$iconName", size:IconSize.s48))
) )
); );
} }).toList()
); );
} }
} }
......
...@@ -267,18 +267,11 @@ class StockHomeState extends State<StockHome> { ...@@ -267,18 +267,11 @@ class StockHomeState extends State<StockHome> {
toolBar: _isSearching ? buildSearchBar() : buildToolBar(), toolBar: _isSearching ? buildSearchBar() : buildToolBar(),
floatingActionButton: buildFloatingActionButton(), floatingActionButton: buildFloatingActionButton(),
drawer: _buildDrawer(context), drawer: _buildDrawer(context),
body: new TabBarView<StockHomeTab>( body: new TabBarView(
items: <StockHomeTab>[StockHomeTab.market, StockHomeTab.portfolio], children: <Widget>[
itemBuilder: (StockHomeTab tab) { _buildStockTab(context, StockHomeTab.market, config.symbols),
switch (tab) { _buildStockTab(context, StockHomeTab.portfolio, portfolioSymbols),
case StockHomeTab.market: ]
return _buildStockTab(context, tab, config.symbols);
case StockHomeTab.portfolio:
return _buildStockTab(context, tab, portfolioSymbols);
default:
assert(false);
}
}
) )
) )
); );
......
...@@ -764,36 +764,29 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect ...@@ -764,36 +764,29 @@ class _TabBarState<T> extends ScrollableState<TabBar<T>> implements TabBarSelect
} }
} }
typedef Widget TabItemBuilder<T>(T item); class TabBarView extends PageableList {
class TabBarView<T> extends PageableList {
TabBarView({ TabBarView({
Key key, Key key,
List<T> items, List<Widget> children
TabItemBuilder<T> itemBuilder }) : super(
}) : items = items, itemBuilder = itemBuilder, super(
key: key, key: key,
scrollDirection: ScrollDirection.horizontal, scrollDirection: ScrollDirection.horizontal,
children: items.map((T item) => itemBuilder(item)).toList(), children: children
itemsWrap: false
) { ) {
assert(items != null); assert(children != null);
assert(items.length > 1); assert(children.length > 1);
} }
final List<T> items; _TabBarViewState createState() => new _TabBarViewState();
final TabItemBuilder<T> itemBuilder;
_TabBarViewState createState() => new _TabBarViewState<T>();
} }
class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements TabBarSelectionPerformanceListener { class _TabBarViewState extends PageableListState<TabBarView> implements TabBarSelectionPerformanceListener {
TabBarSelectionState _selection; TabBarSelectionState _selection;
List<Widget> _items; List<Widget> _items;
AnimationDirection _scrollDirection = AnimationDirection.forward; AnimationDirection _scrollDirection = AnimationDirection.forward;
int get _tabCount => config.items.length; int get _tabCount => config.children.length;
BoundedBehavior _boundedBehavior; BoundedBehavior _boundedBehavior;
...@@ -802,7 +795,7 @@ class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements Ta ...@@ -802,7 +795,7 @@ class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements Ta
return _boundedBehavior; return _boundedBehavior;
} }
void _initSelection(TabBarSelectionState<T> selection) { void _initSelection(TabBarSelectionState selection) {
_selection = selection; _selection = selection;
if (_selection != null) { if (_selection != null) {
_selection.registerPerformanceListener(this); _selection.registerPerformanceListener(this);
...@@ -919,7 +912,7 @@ class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements Ta ...@@ -919,7 +912,7 @@ class _TabBarViewState<T> extends PageableListState<TabBarView<T>> implements Ta
} }
Widget buildContent(BuildContext context) { Widget buildContent(BuildContext context) {
TabBarSelectionState<T> newSelection = TabBarSelection.of(context); TabBarSelectionState newSelection = TabBarSelection.of(context);
if (_selection != newSelection) if (_selection != newSelection)
_initSelection(newSelection); _initSelection(newSelection);
return new PageViewport( return new PageViewport(
......
...@@ -41,10 +41,10 @@ class ScrollableList extends Scrollable { ...@@ -41,10 +41,10 @@ class ScrollableList extends Scrollable {
final ScrollableListPainter scrollableListPainter; final ScrollableListPainter scrollableListPainter;
final Iterable<Widget> children; final Iterable<Widget> children;
ScrollableState createState() => new _ScrollableList2State(); ScrollableState createState() => new _ScrollableListState();
} }
class _ScrollableList2State extends ScrollableState<ScrollableList> { class _ScrollableListState extends ScrollableState<ScrollableList> {
ScrollBehavior createScrollBehavior() => new OverscrollBehavior(); ScrollBehavior createScrollBehavior() => new OverscrollBehavior();
ExtentScrollBehavior get scrollBehavior => super.scrollBehavior; ExtentScrollBehavior get scrollBehavior => super.scrollBehavior;
......
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