mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
Hhristov/fix tab view selected index (#3893)
* fix button ios color property when textDecoration is applied * Button ios color set on titleLabel * Coerce tabView selectedIndex after native items are set
This commit is contained in:
10
apps/.vscode/launch.json
vendored
10
apps/.vscode/launch.json
vendored
@@ -8,7 +8,10 @@
|
||||
"platform": "ios",
|
||||
"appRoot": "${workspaceRoot}",
|
||||
"sourceMaps": true,
|
||||
"watch": true
|
||||
"watch": true,
|
||||
"tnsArgs": [
|
||||
"--sync-all-files"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Attach on iOS",
|
||||
@@ -26,7 +29,10 @@
|
||||
"platform": "android",
|
||||
"appRoot": "${workspaceRoot}",
|
||||
"sourceMaps": true,
|
||||
"watch": true
|
||||
"watch": true,
|
||||
"tnsArgs": [
|
||||
"--sync-all-files"
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "Attach on Android",
|
||||
|
||||
@@ -196,7 +196,6 @@ selectedIndexProperty.register(TabViewBase);
|
||||
export const itemsProperty = new Property<TabViewBase, TabViewItemDefinition[]>({
|
||||
name: "items", valueChanged: (target, oldValue, newValue) => {
|
||||
target.onItemsChanged(oldValue, newValue);
|
||||
selectedIndexProperty.coerce(target);
|
||||
}
|
||||
});
|
||||
itemsProperty.register(TabViewBase);
|
||||
|
||||
@@ -327,25 +327,21 @@ export class TabView extends TabViewBase {
|
||||
}
|
||||
|
||||
public disposeNativeView() {
|
||||
// this._tabLayout.setItems(null, null);
|
||||
this._pagerAdapter.notifyDataSetChanged();
|
||||
(<any>this._pagerAdapter).owner = null;
|
||||
this._pagerAdapter = null;
|
||||
|
||||
// this._viewPager.setAdapter(null);
|
||||
this._tabLayout = null;
|
||||
(<any>this._viewPager).listener.owner = null;
|
||||
this._viewPager = null;
|
||||
super.disposeNativeView();
|
||||
}
|
||||
|
||||
private setAdapter(items: Array<TabViewItem>) {
|
||||
private setAdapterItems(items: Array<TabViewItem>) {
|
||||
(<any>this._pagerAdapter).items = items;
|
||||
|
||||
const length = items ? items.length : 0;
|
||||
if (length === 0) {
|
||||
// this._viewPager.setAdapter(null);
|
||||
// this._pagerAdapter = null;
|
||||
this._tabLayout.setItems(null, null);
|
||||
return;
|
||||
}
|
||||
@@ -393,7 +389,8 @@ export class TabView extends TabViewBase {
|
||||
return null;
|
||||
}
|
||||
[itemsProperty.setNative](value: TabViewItem[]) {
|
||||
this.setAdapter(value);
|
||||
this.setAdapterItems(value);
|
||||
selectedIndexProperty.coerce(this);
|
||||
}
|
||||
|
||||
[tabBackgroundColorProperty.getDefault](): android.graphics.drawable.Drawable.ConstantState {
|
||||
|
||||
@@ -386,6 +386,7 @@ export class TabView extends TabViewBase {
|
||||
}
|
||||
[itemsProperty.setNative](value: TabViewItem[]) {
|
||||
this.setViewControllers(value);
|
||||
selectedIndexProperty.coerce(this);
|
||||
}
|
||||
|
||||
[tabTextColorProperty.getDefault](): UIColor {
|
||||
|
||||
@@ -42,13 +42,12 @@ export class TextBase extends TextBaseCommon {
|
||||
}
|
||||
[colorProperty.setNative](value: Color | UIColor) {
|
||||
const color = value instanceof Color ? value.ios : value;
|
||||
if (!this.formattedText) {
|
||||
let nativeView = this.nativeView;
|
||||
if (nativeView instanceof UIButton) {
|
||||
nativeView.setTitleColorForState(color, UIControlState.Normal);
|
||||
} else {
|
||||
nativeView.textColor = color;
|
||||
}
|
||||
const nativeView = this.nativeView;
|
||||
if (nativeView instanceof UIButton) {
|
||||
nativeView.setTitleColorForState(color, UIControlState.Normal);
|
||||
nativeView.titleLabel.textColor = color;
|
||||
} else {
|
||||
nativeView.textColor = color;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,10 +57,10 @@ export class TextBase extends TextBaseCommon {
|
||||
return nativeView.font;
|
||||
}
|
||||
[fontInternalProperty.setNative](value: Font | UIFont) {
|
||||
if (!this.formattedText) {
|
||||
if (!(value instanceof Font) || !this.formattedText) {
|
||||
let nativeView = this.nativeView;
|
||||
nativeView = nativeView instanceof UIButton ? nativeView.titleLabel : nativeView;
|
||||
let font = value instanceof Font ? value.getUIFont(nativeView.font) : value;
|
||||
const font = value instanceof Font ? value.getUIFont(nativeView.font) : value;
|
||||
nativeView.font = font;
|
||||
}
|
||||
}
|
||||
@@ -170,14 +169,14 @@ export class TextBase extends TextBaseCommon {
|
||||
dict.set(NSKernAttributeName, style.letterSpacing * this.nativeView.font.pointSize);
|
||||
}
|
||||
|
||||
if (style.color) {
|
||||
const isTextView = this.nativeView instanceof UITextView;
|
||||
if (style.color && (dict.size > 0 || isTextView)) {
|
||||
dict.set(NSForegroundColorAttributeName, style.color.ios);
|
||||
}
|
||||
|
||||
const text = this.text;
|
||||
const string = (text === undefined || text === null) ? '' : text.toString();
|
||||
const source = getTransformedText(string, this.textTransform);
|
||||
const isTextView = this.nativeView instanceof UITextView;
|
||||
if (dict.size > 0 || isTextView) {
|
||||
if (isTextView) {
|
||||
// UITextView's font seems to change inside.
|
||||
|
||||
Reference in New Issue
Block a user