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:
Hristo Hristov
2017-03-29 16:39:54 +03:00
committed by GitHub
parent 86b9be340a
commit 29e07dd027
5 changed files with 22 additions and 20 deletions

View File

@@ -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",

View File

@@ -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);

View File

@@ -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 {

View File

@@ -386,6 +386,7 @@ export class TabView extends TabViewBase {
}
[itemsProperty.setNative](value: TabViewItem[]) {
this.setViewControllers(value);
selectedIndexProperty.coerce(this);
}
[tabTextColorProperty.getDefault](): UIColor {

View File

@@ -42,15 +42,14 @@ 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;
const nativeView = this.nativeView;
if (nativeView instanceof UIButton) {
nativeView.setTitleColorForState(color, UIControlState.Normal);
nativeView.titleLabel.textColor = color;
} else {
nativeView.textColor = color;
}
}
}
[fontInternalProperty.getDefault](): UIFont {
let nativeView = this.nativeView;
@@ -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.