mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix: dont default to Font.default (#8401)
* fix: dont default to Font.default This would cause a font to be set for any label even when using default system font. This will also cause a typeface which is pretty long * lint: lint fixes * fix: added null font guards * fix: Used default bold for TabView Co-authored-by: Vasko <v.trifonov@gmail.com>
This commit is contained in:
@@ -176,6 +176,7 @@ export class ImageSource implements ImageSourceDefinition {
|
||||
}
|
||||
|
||||
static fromFontIconCodeSync(source: string, font: Font, color: Color): ImageSource {
|
||||
font = font || Font.default;
|
||||
const paint = new android.graphics.Paint();
|
||||
paint.setTypeface(font.getAndroidTypeface());
|
||||
paint.setAntiAlias(true);
|
||||
|
||||
@@ -165,6 +165,7 @@ export class ImageSource implements ImageSourceDefinition {
|
||||
}
|
||||
|
||||
static fromFontIconCodeSync(source: string, font: Font, color: Color): ImageSource {
|
||||
font = font || Font.default;
|
||||
let fontSize = layout.toDevicePixels(font.fontSize);
|
||||
if (!fontSize) {
|
||||
// TODO: Consider making 36 font size as default for optimal look on TabView and ActionBar
|
||||
|
||||
@@ -654,7 +654,7 @@ export class BottomNavigation extends TabNavigationBase {
|
||||
}
|
||||
|
||||
const target = tabStripItem.image;
|
||||
const font = target.style.fontInternal;
|
||||
const font = target.style.fontInternal || Font.default;
|
||||
if (!color) {
|
||||
color = target.style.color;
|
||||
}
|
||||
@@ -774,7 +774,7 @@ export class BottomNavigation extends TabNavigationBase {
|
||||
|
||||
const defaultTabItemFontSize = 10;
|
||||
const tabItemFontSize = view.style.fontSize || defaultTabItemFontSize;
|
||||
const font: UIFont = view.style.fontInternal.getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
|
||||
const font: UIFont = (view.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
|
||||
const tabItemTextColor = view.style.color;
|
||||
const textColor = tabItemTextColor instanceof Color ? tabItemTextColor.ios : null;
|
||||
let attributes: any = { [NSFontAttributeName]: font };
|
||||
|
||||
@@ -1154,12 +1154,12 @@ opacityProperty.register(Style);
|
||||
export const colorProperty = new InheritedCssProperty<Style, Color>({ name: "color", cssName: "color", equalityComparer: Color.equals, valueConverter: (v) => new Color(v) });
|
||||
colorProperty.register(Style);
|
||||
|
||||
export const fontInternalProperty = new CssProperty<Style, Font>({ name: "fontInternal", cssName: "_fontInternal", defaultValue: Font.default });
|
||||
export const fontInternalProperty = new CssProperty<Style, Font>({ name: "fontInternal", cssName: "_fontInternal" });
|
||||
fontInternalProperty.register(Style);
|
||||
|
||||
export const fontFamilyProperty = new InheritedCssProperty<Style, string>({
|
||||
name: "fontFamily", cssName: "font-family", affectsLayout: isIOS, valueChanged: (target, oldValue, newValue) => {
|
||||
let currentFont = target.fontInternal;
|
||||
let currentFont = target.fontInternal || Font.default;
|
||||
if (currentFont.fontFamily !== newValue) {
|
||||
const newFont = currentFont.withFontFamily(newValue);
|
||||
target.fontInternal = Font.equals(Font.default, newFont) ? unsetValue : newFont;
|
||||
@@ -1170,7 +1170,10 @@ fontFamilyProperty.register(Style);
|
||||
|
||||
export const fontSizeProperty = new InheritedCssProperty<Style, number>({
|
||||
name: "fontSize", cssName: "font-size", affectsLayout: isIOS, valueChanged: (target, oldValue, newValue) => {
|
||||
let currentFont = target.fontInternal;
|
||||
if (target.viewRef["handleFontSize"] === true) {
|
||||
return;
|
||||
}
|
||||
let currentFont = target.fontInternal || Font.default;
|
||||
if (currentFont.fontSize !== newValue) {
|
||||
const newFont = currentFont.withFontSize(newValue);
|
||||
target.fontInternal = Font.equals(Font.default, newFont) ? unsetValue : newFont;
|
||||
@@ -1182,7 +1185,7 @@ fontSizeProperty.register(Style);
|
||||
|
||||
export const fontStyleProperty = new InheritedCssProperty<Style, FontStyle>({
|
||||
name: "fontStyle", cssName: "font-style", affectsLayout: isIOS, defaultValue: FontStyle.NORMAL, valueConverter: FontStyle.parse, valueChanged: (target, oldValue, newValue) => {
|
||||
let currentFont = target.fontInternal;
|
||||
let currentFont = target.fontInternal || Font.default;
|
||||
if (currentFont.fontStyle !== newValue) {
|
||||
const newFont = currentFont.withFontStyle(newValue);
|
||||
target.fontInternal = Font.equals(Font.default, newFont) ? unsetValue : newFont;
|
||||
@@ -1193,7 +1196,7 @@ fontStyleProperty.register(Style);
|
||||
|
||||
export const fontWeightProperty = new InheritedCssProperty<Style, FontWeight>({
|
||||
name: "fontWeight", cssName: "font-weight", affectsLayout: isIOS, defaultValue: FontWeight.NORMAL, valueConverter: FontWeight.parse, valueChanged: (target, oldValue, newValue) => {
|
||||
let currentFont = target.fontInternal;
|
||||
let currentFont = target.fontInternal || Font.default;
|
||||
if (currentFont.fontWeight !== newValue) {
|
||||
const newFont = currentFont.withFontWeight(newValue);
|
||||
target.fontInternal = Font.equals(Font.default, newFont) ? unsetValue : newFont;
|
||||
|
||||
@@ -587,7 +587,7 @@ function getTitleAttributesForStates(tabView: TabView): TabStates {
|
||||
|
||||
const defaultTabItemFontSize = 10;
|
||||
const tabItemFontSize = tabView.style.tabTextFontSize || defaultTabItemFontSize;
|
||||
const font: UIFont = tabView.style.fontInternal.getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
|
||||
const font: UIFont = (tabView.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
|
||||
const tabItemTextColor = tabView.style.tabTextColor;
|
||||
const textColor = tabItemTextColor instanceof Color ? tabItemTextColor.ios : null;
|
||||
result.normalState = { [NSFontAttributeName]: font };
|
||||
|
||||
@@ -824,7 +824,7 @@ export class Tabs extends TabsBase {
|
||||
}
|
||||
|
||||
const target = tabStripItem.image;
|
||||
const font = target.style.fontInternal;
|
||||
const font = target.style.fontInternal || Font.default;
|
||||
if (!color) {
|
||||
color = target.style.color;
|
||||
}
|
||||
@@ -997,7 +997,7 @@ export class Tabs extends TabsBase {
|
||||
public setTabBarFontInternal(value: Font): void {
|
||||
const defaultTabItemFontSize = 10;
|
||||
const tabItemFontSize = this.tabStrip.style.fontSize || defaultTabItemFontSize;
|
||||
const font: UIFont = this.tabStrip.style.fontInternal.getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
|
||||
const font: UIFont = (this.tabStrip.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
|
||||
|
||||
this._ios.tabBar.unselectedItemTitleFont = font;
|
||||
this._ios.tabBar.selectedItemTitleFont = font;
|
||||
@@ -1194,7 +1194,7 @@ export class Tabs extends TabsBase {
|
||||
|
||||
const defaultTabItemFontSize = 10;
|
||||
const tabItemFontSize = view.style.fontSize || defaultTabItemFontSize;
|
||||
const font: UIFont = view.style.fontInternal.getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
|
||||
const font: UIFont = (view.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(tabItemFontSize));
|
||||
|
||||
this.viewController.tabBar.unselectedItemTitleFont = font;
|
||||
this.viewController.tabBar.selectedItemTitleFont = font;
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import tabViewModule = require("@nativescript/core/ui/tab-view");
|
||||
import { Font } from "@nativescript/core/ui/styling/font";
|
||||
|
||||
export function getNativeTabCount(tabView: tabViewModule.TabView): number {
|
||||
if (!tabView.ios.viewControllers) {
|
||||
@@ -30,5 +31,5 @@ export function getNativeFont(tabView: tabViewModule.TabView): UIFont {
|
||||
}
|
||||
|
||||
export function getOriginalFont(tabView: tabViewModule.TabView): UIFont {
|
||||
return tabView.style.fontInternal.getUIFont(UIFont.systemFontOfSize(10));
|
||||
return (tabView.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(10));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import tabViewModule = require("@nativescript/core/ui/tab-view");
|
||||
import { Font } from "@nativescript/core/ui/styling/font";
|
||||
|
||||
export function getNativeTabCount(tabView: tabViewModule.TabView): number {
|
||||
if (!tabView.ios.viewControllers) {
|
||||
@@ -30,5 +31,5 @@ export function getNativeFont(tabView: tabViewModule.TabView): UIFont {
|
||||
}
|
||||
|
||||
export function getOriginalFont(tabView: tabViewModule.TabView): UIFont {
|
||||
return tabView.style.fontInternal.getUIFont(UIFont.systemFontOfSize(10));
|
||||
return (tabView.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(10));
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Tabs } from "@nativescript/core/ui/tabs";
|
||||
import { Font } from "@nativescript/core/ui/styling/font";
|
||||
|
||||
// TODO: Should we add getCount to UIPageViewController???
|
||||
export function getNativeTabCount(tabView: Tabs): number {
|
||||
@@ -39,5 +40,5 @@ export function getNativeFont(tabView: Tabs): UIFont {
|
||||
}
|
||||
|
||||
export function getOriginalFont(tabView: Tabs): UIFont {
|
||||
return tabView.style.fontInternal.getUIFont(UIFont.systemFontOfSize(10));
|
||||
return (tabView.style.fontInternal || Font.default).getUIFont(UIFont.systemFontOfSize(10));
|
||||
}
|
||||
|
||||
@@ -178,7 +178,6 @@ public class BottomNavigationBar extends LinearLayout {
|
||||
titleTextView.setGravity(Gravity.CENTER);
|
||||
titleTextView.setMaxWidth((int) (ITEM_TEXT_MAX_WIDTH * density));
|
||||
titleTextView.setTextSize(TypedValue.COMPLEX_UNIT_SP, ITEM_TEXT_SIZE_SP);
|
||||
titleTextView.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
titleTextView.setEllipsize(TextUtils.TruncateAt.END);
|
||||
titleTextView.setMaxLines(1);
|
||||
titleTextView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
@@ -160,7 +160,7 @@ public class TabLayout extends HorizontalScrollView {
|
||||
* {@link TabLayout} you are required to set any
|
||||
* {@link ViewPager.OnPageChangeListener} through this method. This is so
|
||||
* that the layout can update it's scroll position correctly.
|
||||
*
|
||||
*
|
||||
* @see ViewPager#setOnPageChangeListener(ViewPager.OnPageChangeListener)
|
||||
*/
|
||||
public void setOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
|
||||
@@ -196,25 +196,25 @@ public class TabLayout extends HorizontalScrollView {
|
||||
TextView textView = (TextView)ll.getChildAt(1);
|
||||
this.setupItem(ll, textView, imgView, tabItem);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the TextView for tab item at index
|
||||
*/
|
||||
public TextView getTextViewForItemAt(int index){
|
||||
LinearLayout ll = this.getViewForItemAt(index);
|
||||
return (ll != null) ? (TextView)ll.getChildAt(1) : null;
|
||||
return (ll != null) ? (TextView)ll.getChildAt(1) : null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the LinearLayout container for tab item at index
|
||||
*/
|
||||
public LinearLayout getViewForItemAt(int index){
|
||||
LinearLayout result = null;
|
||||
|
||||
|
||||
if(this.mTabStrip.getChildCount() > index){
|
||||
result = (LinearLayout)this.mTabStrip.getChildAt(index);
|
||||
}
|
||||
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -263,10 +263,10 @@ public class TabLayout extends HorizontalScrollView {
|
||||
ll.addView(textView);
|
||||
return ll;
|
||||
}
|
||||
|
||||
|
||||
private void setupItem(LinearLayout ll, TextView textView,ImageView imgView, TabItemSpec tabItem){
|
||||
float density = getResources().getDisplayMetrics().density;
|
||||
|
||||
|
||||
if (tabItem.iconId != 0) {
|
||||
imgView.setImageResource(tabItem.iconId);
|
||||
imgView.setVisibility(VISIBLE);
|
||||
@@ -293,7 +293,7 @@ public class TabLayout extends HorizontalScrollView {
|
||||
} else {
|
||||
ll.setMinimumHeight((int) (SMALL_MIN_HEIGHT * density));
|
||||
}
|
||||
|
||||
|
||||
if (mDistributeEvenly) {
|
||||
LinearLayout.LayoutParams lp = (LinearLayout.LayoutParams) ll.getLayoutParams();
|
||||
lp.width = 0;
|
||||
@@ -438,4 +438,4 @@ public class TabLayout extends HorizontalScrollView {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -250,7 +250,6 @@ public class TabsBar extends HorizontalScrollView {
|
||||
textView.setGravity(Gravity.CENTER);
|
||||
textView.setMaxWidth((int) (TEXT_MAX_WIDTH * density));
|
||||
textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, TAB_VIEW_TEXT_SIZE_SP);
|
||||
textView.setTypeface(Typeface.DEFAULT_BOLD);
|
||||
textView.setEllipsize(TextUtils.TruncateAt.END);
|
||||
textView.setMaxLines(2);
|
||||
textView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
Reference in New Issue
Block a user