Skip to content

Tabs styling improvements#8366

Merged
vtrifonov merged 23 commits into
masterfrom
trifonov/tabs-styling
Mar 9, 2020
Merged

Tabs styling improvements#8366
vtrifonov merged 23 commits into
masterfrom
trifonov/tabs-styling

Conversation

@vtrifonov

@vtrifonov vtrifonov commented Feb 21, 2020

Copy link
Copy Markdown
Contributor

PR Checklist

What is the current behavior?

  • The tabs in iOS are left-aligned and this cannot be modified
  • The styling of the Tabs TabStrip component is not being applied in ios.
  • The default value of the TextTransform for the tab strips labels in android is "none" which differs from the Material design guidelines

What is the new behavior?

  • Now we allow leading, justified, center and centerSelected types of alignment of the Tabs TabStrip items in iOS. To change the behavior set the iOSTabBarItemsAlignment property to the Tabs component to one of the following:
    • leading - tab items are aligned to the left
    • justified - tab strip is split equally to all the tab items
    • center - tabs items are aligned in the center
    • centerSelected - tab items move to make the selected tab in the center
  • With this PR we have allowed styling of Tabs TabStrip in iOS. You can now change the font, background-color, color, and TextTransform. There are some limitations though:
    • The iOS MDCTabBar supports only two styles of the tab strip items - normal and selected, which means that you cannot have different styles for two items with the same normal state
    • The supported TextTransform values for the Tabs TabStrip are "none", "initial" and "uppercase"
    • If the iOSTabBarItemsAlignment is set to something different than justify and you want to set the background of the selected item, you can achieve it by setting :active style to the TabStrip item, but the selection highlight indicator will not be shown in that case

Fixes #8369, #8345, #8340.

BREAKING CHANGES:

The default value of the TextTransform for android is now uppercase.

Migration steps:

If you don't want to use uppercased items, you need to change the TextTransform property/style either on TabStrip, TabStripItem or Label element.

@cla-bot cla-bot Bot added the cla: yes label Feb 21, 2020
Comment thread nativescript-core/ui/tabs/tabs.ios.ts Outdated
Comment thread nativescript-core/ui/tabs/tabs.ios.ts Outdated

if (!tabStripItem.iconSource) {
if (isIconAboveTitle) {
tabBarItem.titlePositionAdjustment = { horizontal: 0, vertical: -20 };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Where do these magic numbers come from?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I'm not sure. The same numbers are set in tabs-view and bottom-navigation as well. I haven't change it though.

return "initial";
case MDCTabBarTextTransform.Uppercase:
default:
return "uppercase";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Wouldn't it be better to throw an exception in the default branch? I think it would be easier to find out if for some reason there is a new property in the enumeration.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The thing is that this is something that is set through CSS and it works of Android for all the cases, but iOS doesn't support all, so I would prefer not to crash the app with a CSS change. On the other hand, if you cannot achieve what you want with a single style you can always use platform-specific ones.

@vtrifonov vtrifonov changed the title Trifonov/tabs styling Tabs styling in iOS Feb 24, 2020
@vtrifonov vtrifonov changed the title Tabs styling in iOS Tabs styling improvements Feb 24, 2020
@vtrifonov vtrifonov marked this pull request as ready for review February 24, 2020 14:27
@vtrifonov vtrifonov requested a review from vmutafov March 5, 2020 17:24
private getItemLabelTextTransform(tabStripItem: TabStripItem): TextTransform {
const nestedLabel = tabStripItem.label;
let textTransform: TextTransform = null;
if (nestedLabel && nestedLabel.style.textTransform && nestedLabel.style.textTransform !== "initial") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't the check be if (nestedLabel && nestedLabel.style && nestedLabel.style.textTransform !== "initial")?
The same goes a couple of lines below.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Shouldn't it be if (nestedLabel && nestedLabel.style.textTransform !== "initial") then?

}

get textTransform(): TextTransform {
return this.style.textTransform;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it possible we don't have a style?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comment thread nativescript-core/ui/tabs/tabs.android.ts
private getItemLabelTextTransform(tabStripItem: TabStripItem): TextTransform {
const nestedLabel = tabStripItem.label;
let textTransform: TextTransform = null;
if (nestedLabel && nestedLabel.style.textTransform && nestedLabel.style.textTransform !== "initial") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is the if check correct? Please check one of my previous comments. Also, isn't this duplicate code? Could we move it to a utility class for the TabStripItem?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It is duplicate, I've planned to create a base Tabs/Bottom Navigation component as there's a lot of duplicate code between the two controls.

dtopuzov added a commit to NativeScript/functional-tests-images that referenced this pull request Mar 9, 2020
Update images after changes caused by NativeScript/NativeScript#8366
@vtrifonov vtrifonov merged commit 4589431 into master Mar 9, 2020
@vtrifonov vtrifonov deleted the trifonov/tabs-styling branch March 9, 2020 13:24
NathanWalker pushed a commit that referenced this pull request Aug 7, 2020
* fix(tabs): delay loadView when animation runs

* chore: update api.md

* chore: remove unnecessary casting

* test: Added disabled test for changing tabs

* tabs(ios): added tabs styling in ios

* tabs: added iosAlignment property

* tabs: textTransform support

* tabs: iosAlignment moved to tabstrip

* test: add frame-in-tabs test

* chore: addressing PR comments

* chore: addressing PR comments

* chore: call method on the instance instead of call

* chore: move IOSAlignment property

* chore: update comments

* fix: texttransform to tabstrip in bottomnavigation

* chore: add new item to native-api-usage

* chore: remove unneeded setNativeView call

* chore: removed unneeded check

Co-authored-by: Dimitar Topuzov <dtopuzov@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tabs missalign with two tabStripItem

3 participants