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",
|
"platform": "ios",
|
||||||
"appRoot": "${workspaceRoot}",
|
"appRoot": "${workspaceRoot}",
|
||||||
"sourceMaps": true,
|
"sourceMaps": true,
|
||||||
"watch": true
|
"watch": true,
|
||||||
|
"tnsArgs": [
|
||||||
|
"--sync-all-files"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Attach on iOS",
|
"name": "Attach on iOS",
|
||||||
@@ -26,7 +29,10 @@
|
|||||||
"platform": "android",
|
"platform": "android",
|
||||||
"appRoot": "${workspaceRoot}",
|
"appRoot": "${workspaceRoot}",
|
||||||
"sourceMaps": true,
|
"sourceMaps": true,
|
||||||
"watch": true
|
"watch": true,
|
||||||
|
"tnsArgs": [
|
||||||
|
"--sync-all-files"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"name": "Attach on Android",
|
"name": "Attach on Android",
|
||||||
|
|||||||
@@ -196,7 +196,6 @@ selectedIndexProperty.register(TabViewBase);
|
|||||||
export const itemsProperty = new Property<TabViewBase, TabViewItemDefinition[]>({
|
export const itemsProperty = new Property<TabViewBase, TabViewItemDefinition[]>({
|
||||||
name: "items", valueChanged: (target, oldValue, newValue) => {
|
name: "items", valueChanged: (target, oldValue, newValue) => {
|
||||||
target.onItemsChanged(oldValue, newValue);
|
target.onItemsChanged(oldValue, newValue);
|
||||||
selectedIndexProperty.coerce(target);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
itemsProperty.register(TabViewBase);
|
itemsProperty.register(TabViewBase);
|
||||||
|
|||||||
@@ -327,25 +327,21 @@ export class TabView extends TabViewBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public disposeNativeView() {
|
public disposeNativeView() {
|
||||||
// this._tabLayout.setItems(null, null);
|
|
||||||
this._pagerAdapter.notifyDataSetChanged();
|
this._pagerAdapter.notifyDataSetChanged();
|
||||||
(<any>this._pagerAdapter).owner = null;
|
(<any>this._pagerAdapter).owner = null;
|
||||||
this._pagerAdapter = null;
|
this._pagerAdapter = null;
|
||||||
|
|
||||||
// this._viewPager.setAdapter(null);
|
|
||||||
this._tabLayout = null;
|
this._tabLayout = null;
|
||||||
(<any>this._viewPager).listener.owner = null;
|
(<any>this._viewPager).listener.owner = null;
|
||||||
this._viewPager = null;
|
this._viewPager = null;
|
||||||
super.disposeNativeView();
|
super.disposeNativeView();
|
||||||
}
|
}
|
||||||
|
|
||||||
private setAdapter(items: Array<TabViewItem>) {
|
private setAdapterItems(items: Array<TabViewItem>) {
|
||||||
(<any>this._pagerAdapter).items = items;
|
(<any>this._pagerAdapter).items = items;
|
||||||
|
|
||||||
const length = items ? items.length : 0;
|
const length = items ? items.length : 0;
|
||||||
if (length === 0) {
|
if (length === 0) {
|
||||||
// this._viewPager.setAdapter(null);
|
|
||||||
// this._pagerAdapter = null;
|
|
||||||
this._tabLayout.setItems(null, null);
|
this._tabLayout.setItems(null, null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -393,7 +389,8 @@ export class TabView extends TabViewBase {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
[itemsProperty.setNative](value: TabViewItem[]) {
|
[itemsProperty.setNative](value: TabViewItem[]) {
|
||||||
this.setAdapter(value);
|
this.setAdapterItems(value);
|
||||||
|
selectedIndexProperty.coerce(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
[tabBackgroundColorProperty.getDefault](): android.graphics.drawable.Drawable.ConstantState {
|
[tabBackgroundColorProperty.getDefault](): android.graphics.drawable.Drawable.ConstantState {
|
||||||
|
|||||||
@@ -386,6 +386,7 @@ export class TabView extends TabViewBase {
|
|||||||
}
|
}
|
||||||
[itemsProperty.setNative](value: TabViewItem[]) {
|
[itemsProperty.setNative](value: TabViewItem[]) {
|
||||||
this.setViewControllers(value);
|
this.setViewControllers(value);
|
||||||
|
selectedIndexProperty.coerce(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
[tabTextColorProperty.getDefault](): UIColor {
|
[tabTextColorProperty.getDefault](): UIColor {
|
||||||
|
|||||||
@@ -42,15 +42,14 @@ export class TextBase extends TextBaseCommon {
|
|||||||
}
|
}
|
||||||
[colorProperty.setNative](value: Color | UIColor) {
|
[colorProperty.setNative](value: Color | UIColor) {
|
||||||
const color = value instanceof Color ? value.ios : value;
|
const color = value instanceof Color ? value.ios : value;
|
||||||
if (!this.formattedText) {
|
const nativeView = this.nativeView;
|
||||||
let nativeView = this.nativeView;
|
|
||||||
if (nativeView instanceof UIButton) {
|
if (nativeView instanceof UIButton) {
|
||||||
nativeView.setTitleColorForState(color, UIControlState.Normal);
|
nativeView.setTitleColorForState(color, UIControlState.Normal);
|
||||||
|
nativeView.titleLabel.textColor = color;
|
||||||
} else {
|
} else {
|
||||||
nativeView.textColor = color;
|
nativeView.textColor = color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
[fontInternalProperty.getDefault](): UIFont {
|
[fontInternalProperty.getDefault](): UIFont {
|
||||||
let nativeView = this.nativeView;
|
let nativeView = this.nativeView;
|
||||||
@@ -58,10 +57,10 @@ export class TextBase extends TextBaseCommon {
|
|||||||
return nativeView.font;
|
return nativeView.font;
|
||||||
}
|
}
|
||||||
[fontInternalProperty.setNative](value: Font | UIFont) {
|
[fontInternalProperty.setNative](value: Font | UIFont) {
|
||||||
if (!this.formattedText) {
|
if (!(value instanceof Font) || !this.formattedText) {
|
||||||
let nativeView = this.nativeView;
|
let nativeView = this.nativeView;
|
||||||
nativeView = nativeView instanceof UIButton ? nativeView.titleLabel : 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;
|
nativeView.font = font;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,14 +169,14 @@ export class TextBase extends TextBaseCommon {
|
|||||||
dict.set(NSKernAttributeName, style.letterSpacing * this.nativeView.font.pointSize);
|
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);
|
dict.set(NSForegroundColorAttributeName, style.color.ios);
|
||||||
}
|
}
|
||||||
|
|
||||||
const text = this.text;
|
const text = this.text;
|
||||||
const string = (text === undefined || text === null) ? '' : text.toString();
|
const string = (text === undefined || text === null) ? '' : text.toString();
|
||||||
const source = getTransformedText(string, this.textTransform);
|
const source = getTransformedText(string, this.textTransform);
|
||||||
const isTextView = this.nativeView instanceof UITextView;
|
|
||||||
if (dict.size > 0 || isTextView) {
|
if (dict.size > 0 || isTextView) {
|
||||||
if (isTextView) {
|
if (isTextView) {
|
||||||
// UITextView's font seems to change inside.
|
// UITextView's font seems to change inside.
|
||||||
|
|||||||
Reference in New Issue
Block a user