Open sudhanshu-15 opened 7 years ago
@sudhanshu-15 thank you for reporting this issue! I can confirm that indeed with some icon fonts the titles are not centered vertically on iOS (works fine on Android).
Steps to reproduce:
Result: when using some icon fonts (in the app MaterialIcons or Nasalizaiton) the tab title are not centered vertically on iOS
Is there any way to work around this issue until there is fix
I have found a workaround for now. Use the loaded
event on the TabView
and iterate over all childs setting the proper vertical alignment.
onTabViewLoaded: ({ object: tabView }) => {
tabView.eachChild((child) => {
child._iosViewController.tabBarItem.titlePositionAdjustment = {
horizontal: 0,
vertical: -8
};
});
},
The issue comes from the hardcoded vertical alignment in the TabView
module sources: https://github.com/NativeScript/NativeScript/blob/014e7a8e0ffaeefd5e0c29f0bfa64459f7547681/tns-core-modules/ui/tab-view/tab-view.ios.ts#L115
This solution doesn't appear to work. When accessing child
, _iosViewController
is undefined.
This is not only issue with TabView. I am seeing same effect on Labels and Buttons as well. TNS 4.x
@razorsyntax In new versions the _iosViewController
property is __controller
:
tabView.eachChild((child) => {
child.__controller.tabBarItem.titlePositionAdjustment = {
horizontal: 0,
vertical: -8
};
});
This piece of code is not working for me... I get these errors in console:
Argument of type '(child: ViewBase) => void' is not assignable to parameter of type '(child: ViewBase) => boolean'.
Type 'void' is not assignable to type 'boolean'.
Property '__controller' does not exist on type 'ViewBase'.
I am using Nativescript 4.2 and Angular 6.
Any suggestion?
@relez you cannot use this code with type validation, one way to use it is to cast tabView to any: (<any>tabView).eachChild(...
@ventsislav-georgiev
I changed the line in tns-core-modules/ui/tab-view/tab-view.ios.ts
to .setTitlePositionAdjustment({ horizontal: 0, vertical: -0 });
and it works, but is this an acceptable way of doing it? Also, just out of interest, do you know why there might have been a hardcoded value of -20 in the first place ?
Best wishes, Nat 😸
NS-Vue Implementation (not sure if this is the most direct root, but working):
// Javascript version
onTabViewLoaded: (tabView) => {
tabView.object.__vue_element_ref__.childNodes.forEach((child) => {
child._nativeView.__controller.tabBarItem.titlePositionAdjustment = {
horizontal: 0,
vertical: -10
};
})
},
Hi, Ive I changed the line in tns-core-modules/ui/tab-view/tab-view.ios.ts to .setTitlePositionAdjustment({ horizontal: 0, vertical: -15 }) which works well for the app. Is it possible to update this property in the .ts file while working in Nativescript angular ? Thanks.
Here a Fix:
onLoadTabView(event) {
if (event.object.ios) {
const items = event.object.ios.tabBar.items;
for (let i = 0; i < parseInt(items.count); i++) {
items.objectAtIndex(i).titlePositionAdjustment = { horizontal: 0, vertical: -8 };
}
}
},
Have Fun ;)
Please, provide the details below:
Did you verify this is a real problem by searching [Stack Overflow]
Yes, I had previously created an issue where icon fonts were not working on iOS TabView titles. https://github.com/NativeScript/NativeScript/issues/4302 It got resolved with 3.2.0 but here is a minute issue with it.
Tell us about the problem
The TabView icons using icon fonts on iOS are not vertically centered, on Android it is vertically centered and looks good, but on iOS it is aligned to the top.
Which platform(s) does your issue occur on?
iOS
Please provide the following version numbers that your issue occurs with:
Please tell us how to recreate the issue in as much detail as possible.
Create a tab view with title using Material Icons (Icon font) and you will be able to see the title icons are not vertically centered. On iOS
On Android
Is there code involved? If so, please share the minimal amount of code needed to recreate the problem.