Skip to content

[Material] selected/unselected label styles + icon themes on BottomNavigationBar#31018

Merged
johnsonmh merged 14 commits intoflutter:masterfrom
johnsonmh:feature-bottomNavLabelStyles
May 2, 2019
Merged

[Material] selected/unselected label styles + icon themes on BottomNavigationBar#31018
johnsonmh merged 14 commits intoflutter:masterfrom
johnsonmh:feature-bottomNavLabelStyles

Conversation

@johnsonmh
Copy link
Contributor

@johnsonmh johnsonmh commented Apr 13, 2019

Description

This PR adds selectedTextStyle and unselectedTextStyle parameters to the BottomNavigationBar class. These parameters provide two main benefits to users of BottomNavigationBar:

  1. Further customization of the fonts in a BottomNavigationBar.

Having a generic TextStyle allows for more than just fontSize to animate.
For example, TextStyle.fontWeight or TextStyle.fontStyle can animate.
giphy-1

Also, selectedTextStyle and unselectedTextStyle provide a convenient way to customize the fontFamily of the text in a bottom nav. Previously, this was only possible by supplying a textStyle directly to all of the individual Text widgets passed to BottomNavigationBarItem.
giphy-2

  1. selectedTextStyle and unselectedTextStyle parameters will allow for the TextStyles to be customized in BottomNavigationBarTheme, when it is created.

This PR also adds selectedIconTheme and unselectedIconTheme.

These params now make bottom navigation bars much more customizable:

giphy-7

giphy-3

giphy-5

Related Issues

N/A

Tests

I added the following tests:

  • selectedTextStyle and unselectedTextStyle are honored in the BottomNavigationBar.
  • The selectedTextStyle.fontSize and unselectedTextStyle.fontSize take precedence over selectedFontSize and unselectedFontSize.
  • The selectedTextStyle.color and unselectedTextStyle.color take precedence over selectedItemColor and unselectedItemColor.
  • The selectedIconTheme.color and unselectedIconTheme.color take precedence over selectedItemColor and unselectedItemColor.
  • The selectedIconTheme.size and unselectedIconTheme.size take precedence over iconSize.
  • Tests for making sure that the padding on the nav bar items is calculated correctly when all labels are shown, just selected labels are shown, and when no labels are shown.

Alternatives Considered

Since selectedFontSize and unselectedFontSize already exist as parameters, it brings up the question of what to do when both selectedTextStyle.fontSize and selectedFontSize are provided.

There are three options I considered:

  1. Keep both parameters, but prefer selectedTextStyle.fontSize if it is provided, since providing the entire TextStyle is more specific.
  2. Keep both parameters, but throw an assert saying that font size should not be provided on both selectedTextStyle and selectedFontSize.
  3. Deprecate and remove selectedFontSize, since it is now achievable through selectedFontStyle.fontSize.

I opted for option 1, because it is non-breaking and is inline with some existing components. For example, in TabBars, you could provide both indicatorColor and an indicator with it's own color, and the custom indicators color will be used.

If we think that having both will serve as unnecessary complication, or that it will be unclear to users which to use, I can deprecate/remove selectedFontSize and unselectedFontSize in the future. It would require a breaking change, but it may be worth it.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Does your PR require Flutter developers to manually update their apps to accommodate your change?

  • Yes, this is a breaking change (Please read Handling breaking changes). Replace this with a link to the e-mail where you asked for input on this proposed change.
  • No, this is not a breaking change.

@goderbauer goderbauer added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Apr 15, 2019
Copy link
Contributor

@rami-a rami-a left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just some minor comments

@johnsonmh johnsonmh changed the title [WIP][Material] selected and unselected label styles on Bottom Navigation Bar [WIP][Material] selected and unselected label styles + icon themes on BottomNavigationBar Apr 22, 2019
Copy link
Contributor Author

@johnsonmh johnsonmh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks Will!

@johnsonmh johnsonmh changed the title [WIP][Material] selected and unselected label styles + icon themes on BottomNavigationBar [Material] selected/unselected label styles + icon themes on BottomNavigationBar Apr 23, 2019
@johnsonmh johnsonmh requested a review from HansMuller April 24, 2019 03:04
Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could be simplified a little by not doing default value computations in the constructor (at least for the new properties); better to adding "effectiveFoo" getters to _BottomNavigvationBarState

Copy link
Contributor

@HansMuller HansMuller left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@johnsonmh johnsonmh merged commit a40e5c9 into flutter:master May 2, 2019
@johnsonmh johnsonmh deleted the feature-bottomNavLabelStyles branch May 2, 2019 22:20
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants