Index: sky/sdk/lib/widgets/tabs.dart |
diff --git a/sky/sdk/lib/widgets/tabs.dart b/sky/sdk/lib/widgets/tabs.dart |
index 09d03be9df8a2b0fa35f882b0701c291a97318b1..c1372cc4645f198ba9eed03f67510378997928ef 100644 |
--- a/sky/sdk/lib/widgets/tabs.dart |
+++ b/sky/sdk/lib/widgets/tabs.dart |
@@ -299,3 +299,58 @@ class TabBar extends Component { |
); |
} |
} |
+ |
+class TabNavigatorView { |
+ TabNavigatorView({ this.label, this.content }); |
+ |
+ final TabLabel label; |
+ final Function content; |
Hixie
2015/06/27 00:12:38
Function doesn't have a return type. Make a typede
hansmuller
2015/06/29 16:49:42
Thanks, that's better than the names I had in mind
|
+ |
+ Widget buildContent() { |
+ return content != null ? content() : null; |
abarth-chromium
2015/06/27 00:27:36
Should we just build unconditionally? What does i
hansmuller
2015/06/29 16:49:42
I suppose it could mean that there's no view for t
|
+ } |
+} |
+ |
+class TabNavigator extends Component { |
+ TabNavigator({ |
+ String key, |
+ this.views, |
+ this.selectedIndex: 0, |
+ this.onChanged |
+ }) : super(key: key, stateful: true); |
+ |
+ List<TabNavigatorView> views; |
+ int selectedIndex; |
+ SelectedIndexChanged onChanged; |
+ |
+ void syncFields(TabNavigator source) { |
+ views = source.views; |
+ selectedIndex = source.selectedIndex; |
+ onChanged = source.onChanged; |
+ } |
+ |
+ void _selectedTabIndexChanged(int tabIndex) { |
+ setState(() { |
+ selectedIndex = tabIndex; |
+ }); |
+ if (onChanged != null) |
+ onChanged(selectedIndex); |
abarth-chromium
2015/06/27 00:27:36
I'm not sure it makes sense to do both of these.
|
+ } |
+ |
+ Widget build() { |
+ assert(views != null && views.isNotEmpty); |
+ assert(selectedIndex >= 0 && selectedIndex < views.length); |
+ |
+ TabBar tabBar = new TabBar( |
+ labels: views.map((view) => view.label).toList(), |
Hixie
2015/06/27 00:12:38
Why toList()?
hansmuller
2015/06/29 16:49:42
I've changed the type of TabBar.labels to Iterable
|
+ onChanged: _selectedTabIndexChanged, |
abarth-chromium
2015/06/27 00:27:36
If you make that change, you can just pass onChang
|
+ selectedIndex: selectedIndex |
+ ); |
+ |
+ Widget content = views[selectedIndex].buildContent(); |
+ return new Flex( |
+ <Widget>[tabBar, new Flexible(child: content)], |
Hixie
2015/06/27 00:12:38
We don't usually bother type-annotating the childr
hansmuller
2015/06/29 16:49:41
OK. As you know, without the annotation code like
|
+ direction: FlexDirection.vertical |
+ ); |
+ } |
+} |