Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(202)

Side by Side Diff: sky/sdk/lib/widgets/tabs.dart

Issue 1235443002: Support for icon theming (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: fix tests Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 import 'dart:math' as math; 5 import 'dart:math' as math;
6 6
7 import 'package:sky/animation/generators.dart'; 7 import 'package:sky/animation/generators.dart';
8 import 'package:sky/animation/mechanics.dart'; 8 import 'package:sky/animation/mechanics.dart';
9 import 'package:sky/animation/scroll_behavior.dart'; 9 import 'package:sky/animation/scroll_behavior.dart';
10 import 'package:sky/painting/text_style.dart'; 10 import 'package:sky/painting/text_style.dart';
11 import 'package:sky/rendering/box.dart'; 11 import 'package:sky/rendering/box.dart';
12 import 'package:sky/rendering/object.dart'; 12 import 'package:sky/rendering/object.dart';
13 import 'package:vector_math/vector_math.dart'; 13 import 'package:vector_math/vector_math.dart';
14 import 'package:sky/theme/colors.dart' as colors; 14 import 'package:sky/theme/colors.dart' as colors;
15 import 'package:sky/theme/typography.dart' as typography;
15 import 'package:sky/widgets/basic.dart'; 16 import 'package:sky/widgets/basic.dart';
17 import 'package:sky/widgets/default_text_style.dart';
16 import 'package:sky/widgets/icon.dart'; 18 import 'package:sky/widgets/icon.dart';
19 import 'package:sky/widgets/icon_theme.dart';
17 import 'package:sky/widgets/ink_well.dart'; 20 import 'package:sky/widgets/ink_well.dart';
18 import 'package:sky/widgets/scrollable.dart'; 21 import 'package:sky/widgets/scrollable.dart';
19 import 'package:sky/widgets/theme.dart'; 22 import 'package:sky/widgets/theme.dart';
20 import 'package:sky/widgets/widget.dart'; 23 import 'package:sky/widgets/widget.dart';
21 24
22 typedef void SelectedIndexChanged(int selectedIndex); 25 typedef void SelectedIndexChanged(int selectedIndex);
23 typedef void LayoutChanged(Size size, List<double> widths); 26 typedef void LayoutChanged(Size size, List<double> widths);
24 27
25 // See https://www.google.com/design/spec/components/tabs.html#tabs-specs 28 // See https://www.google.com/design/spec/components/tabs.html#tabs-specs
26 const double _kTabHeight = 46.0; 29 const double _kTabHeight = 46.0;
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
294 this.selected: false 297 this.selected: false
295 }) : super(key: key) { 298 }) : super(key: key) {
296 assert(label.text != null || label.icon != null); 299 assert(label.text != null || label.icon != null);
297 } 300 }
298 301
299 final TabLabel label; 302 final TabLabel label;
300 final bool selected; 303 final bool selected;
301 304
302 Widget _buildLabelText() { 305 Widget _buildLabelText() {
303 assert(label.text != null); 306 assert(label.text != null);
304 TextStyle textStyle = Theme.of(this).toolbarText.button.merge(_kTabTextStyle ); 307 TextStyle textStyle = DefaultTextStyle.of(this).merge(_kTabTextStyle);
305 return new Text(label.text, style: textStyle); 308 return new Text(label.text, style: textStyle);
306 } 309 }
307 310
308 Widget _buildLabelIcon() { 311 Widget _buildLabelIcon() {
309 assert(label.icon != null); 312 assert(label.icon != null);
310 return new Icon(type: label.icon, size: _kTabIconSize); 313 return new Icon(type: label.icon, size: _kTabIconSize);
311 } 314 }
312 315
313 Widget build() { 316 Widget build() {
314 Widget labelContents; 317 Widget labelContents;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 assert(labels != null && labels.isNotEmpty); 430 assert(labels != null && labels.isNotEmpty);
428 List<Widget> tabs = <Widget>[]; 431 List<Widget> tabs = <Widget>[];
429 bool textAndIcons = false; 432 bool textAndIcons = false;
430 int tabIndex = 0; 433 int tabIndex = 0;
431 for (TabLabel label in labels) { 434 for (TabLabel label in labels) {
432 tabs.add(_toTab(label, tabIndex++)); 435 tabs.add(_toTab(label, tabIndex++));
433 if (label.text != null && label.icon != null) 436 if (label.text != null && label.icon != null)
434 textAndIcons = true; 437 textAndIcons = true;
435 } 438 }
436 439
437 Color backgroundColor = Theme.of(this).primaryColor; 440 ThemeData themeData = Theme.of(this);
438 Color indicatorColor = Theme.of(this).accentColor; 441 Color backgroundColor = themeData.primaryColor;
442 Color indicatorColor = themeData.accentColor;
439 if (indicatorColor == backgroundColor) { 443 if (indicatorColor == backgroundColor) {
440 indicatorColor = colors.White; 444 indicatorColor = colors.White;
441 } 445 }
442 446
443 TabBarWrapper tabBarWrapper = new TabBarWrapper( 447 TextStyle textStyle;
444 children: tabs, 448 IconThemeColor iconThemeColor;
445 selectedIndex: selectedIndex, 449 switch (themeData.primaryColorBrightness) {
446 backgroundColor: backgroundColor, 450 case ThemeBrightness.light:
447 indicatorColor: indicatorColor, 451 textStyle = typography.black.button;
448 textAndIcons: textAndIcons, 452 iconThemeColor = IconThemeColor.black;
449 scrollable: scrollable, 453 break;
450 onLayoutChanged: scrollable ? _layoutChanged : null 454 case ThemeBrightness.dark:
451 ); 455 textStyle = typography.white.button;
456 iconThemeColor = IconThemeColor.white;
457 break;
458 }
452 459
453 Matrix4 transform = new Matrix4.identity(); 460 Matrix4 transform = new Matrix4.identity();
454 transform.translate(-scrollOffset, 0.0); 461 transform.translate(-scrollOffset, 0.0);
455 return new Transform(child: tabBarWrapper, transform: transform); 462 return new Transform(
463 transform: transform,
464 child: new IconTheme(
465 data: new IconThemeData(color: iconThemeColor),
466 child: new DefaultTextStyle(
467 style: textStyle,
468 child: new TabBarWrapper(
469 children: tabs,
470 selectedIndex: selectedIndex,
471 backgroundColor: backgroundColor,
472 indicatorColor: indicatorColor,
473 textAndIcons: textAndIcons,
474 scrollable: scrollable,
475 onLayoutChanged: scrollable ? _layoutChanged : null
476 )
477 )
478 )
479 );
456 } 480 }
457 } 481 }
458 482
459 class TabNavigatorView { 483 class TabNavigatorView {
460 TabNavigatorView({ this.label, this.builder }); 484 TabNavigatorView({ this.label, this.builder });
461 485
462 final TabLabel label; 486 final TabLabel label;
463 final Builder builder; 487 final Builder builder;
464 488
465 Widget buildContent() { 489 Widget buildContent() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
499 selectedIndex: selectedIndex, 523 selectedIndex: selectedIndex,
500 scrollable: scrollable 524 scrollable: scrollable
501 ); 525 );
502 526
503 Widget content = views[selectedIndex].buildContent(); 527 Widget content = views[selectedIndex].buildContent();
504 return new Flex([tabBar, new Flexible(child: content)], 528 return new Flex([tabBar, new Flexible(child: content)],
505 direction: FlexDirection.vertical 529 direction: FlexDirection.vertical
506 ); 530 );
507 } 531 }
508 } 532 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698