Commit 54f2d4cb authored by Hans Muller's avatar Hans Muller

Merge pull request #878 from HansMuller/pageable_list_tabs

TabBarView is-a PageableList, doesn't need itemExtent

Base TabBarView on PageableList so that itemExtent and its SizeObserver aren't needed.

TabBarView scrolling is still TBD.
parents ffad464c c4f52177
...@@ -22,31 +22,19 @@ class TabsDemo extends StatefulComponent { ...@@ -22,31 +22,19 @@ class TabsDemo extends StatefulComponent {
} }
class _TabsDemoState extends State<TabsDemo> { class _TabsDemoState extends State<TabsDemo> {
double _viewWidth = 100.0;
void _handleSizeChanged(Size newSize) {
setState(() {
_viewWidth = newSize.width;
});
}
Widget build(_) { Widget build(_) {
return new SizeObserver( return new TabBarView<String>(
onSizeChanged: _handleSizeChanged, selection: _selection,
child: new TabBarView<String>( items: _iconNames,
selection: _selection, itemBuilder: (BuildContext context, String iconName, int index) {
items: _iconNames, return new Container(
itemExtent: _viewWidth, key: new ValueKey<String>(iconName),
itemBuilder: (BuildContext context, String iconName, int index) { padding: const EdgeDims.all(12.0),
return new Container( child: new Card(
key: new ValueKey<String>(iconName), child: new Center(child: new Icon(icon: "action/$iconName", size:IconSize.s48))
padding: const EdgeDims.all(12.0), )
child: new Card( );
child: new Center(child: new Icon(icon: "action/$iconName", size:IconSize.s48)) }
)
);
}
)
); );
} }
} }
......
...@@ -272,36 +272,25 @@ class StockHomeState extends State<StockHome> { ...@@ -272,36 +272,25 @@ class StockHomeState extends State<StockHome> {
); );
} }
double _viewWidth = 100.0;
void _handleSizeChanged(Size newSize) {
setState(() {
_viewWidth = newSize.width;
});
}
Widget build(BuildContext context) { Widget build(BuildContext context) {
return new Scaffold( return new Scaffold(
key: _scaffoldKey, key: _scaffoldKey,
toolBar: _isSearching ? buildSearchBar() : buildToolBar(), toolBar: _isSearching ? buildSearchBar() : buildToolBar(),
floatingActionButton: buildFloatingActionButton(), floatingActionButton: buildFloatingActionButton(),
drawer: _buildDrawer(context), drawer: _buildDrawer(context),
body: new SizeObserver( body: new TabBarView<StockHomeTab>(
onSizeChanged: _handleSizeChanged, selection: _tabBarSelection,
child: new TabBarView<StockHomeTab>( items: <StockHomeTab>[StockHomeTab.market, StockHomeTab.portfolio],
selection: _tabBarSelection, itemBuilder: (BuildContext context, StockHomeTab tab, _) {
items: <StockHomeTab>[StockHomeTab.market, StockHomeTab.portfolio], switch (tab) {
itemExtent: _viewWidth, case StockHomeTab.market:
itemBuilder: (BuildContext context, StockHomeTab tab, _) { return _buildStockTab(context, tab, config.symbols);
switch (tab) { case StockHomeTab.portfolio:
case StockHomeTab.market: return _buildStockTab(context, tab, portfolioSymbols);
return _buildStockTab(context, tab, config.symbols); default:
case StockHomeTab.portfolio: assert(false);
return _buildStockTab(context, tab, portfolioSymbols);
default:
assert(false);
}
} }
) }
) )
); );
} }
......
...@@ -28,7 +28,7 @@ const double _kMinTabWidth = 72.0; ...@@ -28,7 +28,7 @@ const double _kMinTabWidth = 72.0;
const double _kMaxTabWidth = 264.0; const double _kMaxTabWidth = 264.0;
const EdgeDims _kTabLabelPadding = const EdgeDims.symmetric(horizontal: 12.0); const EdgeDims _kTabLabelPadding = const EdgeDims.symmetric(horizontal: 12.0);
const double _kTabBarScrollDrag = 0.025; const double _kTabBarScrollDrag = 0.025;
const Duration _kTabBarScroll = const Duration(milliseconds: 200); const Duration _kTabBarScroll = const Duration(milliseconds: 300);
class _TabBarParentData extends ContainerBoxParentDataMixin<RenderBox> { } class _TabBarParentData extends ContainerBoxParentDataMixin<RenderBox> { }
...@@ -612,19 +612,17 @@ class _TabBarState extends ScrollableState<TabBar> { ...@@ -612,19 +612,17 @@ class _TabBarState extends ScrollableState<TabBar> {
} }
} }
class TabBarView<T> extends ScrollableList<T> { class TabBarView<T> extends PageableList<T> {
TabBarView({ TabBarView({
Key key, Key key,
this.selection, this.selection,
List<T> items, List<T> items,
ItemBuilder<T> itemBuilder, ItemBuilder<T> itemBuilder
double itemExtent
}) : super( }) : super(
key: key, key: key,
scrollDirection: ScrollDirection.horizontal, scrollDirection: ScrollDirection.horizontal,
items: items, items: items,
itemBuilder: itemBuilder, itemBuilder: itemBuilder,
itemExtent: itemExtent,
itemsWrap: false itemsWrap: false
) { ) {
assert(selection != null); assert(selection != null);
...@@ -640,9 +638,11 @@ class _NotScrollable extends BoundedBehavior { ...@@ -640,9 +638,11 @@ class _NotScrollable extends BoundedBehavior {
bool get isScrollable => false; bool get isScrollable => false;
} }
class _TabBarViewState<T> extends ScrollableListState<T, TabBarView<T>> { class _TabBarViewState<T> extends PageableListState<T, TabBarView<T>> {
ScrollBehavior createScrollBehavior() => new _NotScrollable(); final _NotScrollable _notScrollable = new _NotScrollable();
ScrollBehavior createScrollBehavior() => _notScrollable;
ExtentScrollBehavior get scrollBehavior => _notScrollable;
List<int> _itemIndices = [0, 1]; List<int> _itemIndices = [0, 1];
AnimationDirection _scrollDirection = AnimationDirection.forward; AnimationDirection _scrollDirection = AnimationDirection.forward;
...@@ -655,10 +655,10 @@ class _TabBarViewState<T> extends ScrollableListState<T, TabBarView<T>> { ...@@ -655,10 +655,10 @@ class _TabBarViewState<T> extends ScrollableListState<T, TabBarView<T>> {
scrollTo(0.0); scrollTo(0.0);
} else if (selectedIndex == config.items.length - 1) { } else if (selectedIndex == config.items.length - 1) {
_itemIndices = <int>[selectedIndex - 1, selectedIndex]; _itemIndices = <int>[selectedIndex - 1, selectedIndex];
scrollTo(config.itemExtent); scrollTo(1.0);
} else { } else {
_itemIndices = <int>[selectedIndex - 1, selectedIndex, selectedIndex + 1]; _itemIndices = <int>[selectedIndex - 1, selectedIndex, selectedIndex + 1];
scrollTo(config.itemExtent); scrollTo(1.0);
} }
} }
...@@ -680,12 +680,6 @@ class _TabBarViewState<T> extends ScrollableListState<T, TabBarView<T>> { ...@@ -680,12 +680,6 @@ class _TabBarViewState<T> extends ScrollableListState<T, TabBarView<T>> {
super.dispose(); super.dispose();
} }
void didUpdateConfig(TabBarView oldConfig) {
super.didUpdateConfig(oldConfig);
if (oldConfig.itemExtent != config.itemExtent && !_performance.isAnimating)
_initItemIndicesAndScrollPosition();
}
void _handleStatusChange(PerformanceStatus status) { void _handleStatusChange(PerformanceStatus status) {
final int selectedIndex = config.selection.index; final int selectedIndex = config.selection.index;
final int previousSelectedIndex = config.selection.previousIndex; final int previousSelectedIndex = config.selection.previousIndex;
...@@ -705,9 +699,9 @@ class _TabBarViewState<T> extends ScrollableListState<T, TabBarView<T>> { ...@@ -705,9 +699,9 @@ class _TabBarViewState<T> extends ScrollableListState<T, TabBarView<T>> {
void _handleProgressChange() { void _handleProgressChange() {
if (_scrollDirection == AnimationDirection.forward) if (_scrollDirection == AnimationDirection.forward)
scrollTo(config.itemExtent * _performance.progress); scrollTo(_performance.progress);
else else
scrollTo(config.itemExtent * (1.0 - _performance.progress)); scrollTo(1.0 - _performance.progress);
} }
int get itemCount => _itemIndices.length; int get itemCount => _itemIndices.length;
......
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