fix(android): list picker getTextColor api level issue (#8755)

closes https://github.com/NativeScript/NativeScript/issues/7860
This commit is contained in:
Nathan Walker
2020-08-11 22:29:11 -07:00
committed by GitHub
parent 23fbc64639
commit 5c076de856
5 changed files with 24 additions and 12 deletions

View File

@@ -3,7 +3,7 @@
"main": "index",
"types": "index.d.ts",
"description": "NativeScript Core Modules",
"version": "6.5.13",
"version": "6.5.15",
"homepage": "https://www.nativescript.org",
"repository": {
"type": "git",

View File

@@ -68,11 +68,21 @@ function getEditText(picker: android.widget.NumberPicker): android.widget.EditTe
let selectorWheelPaintField: java.lang.reflect.Field;
function getSelectorWheelPaint(picker: android.widget.NumberPicker): android.graphics.Paint {
if (!selectorWheelPaintField) {
selectorWheelPaintField = picker.getClass().getDeclaredField("mSelectorWheelPaint");
selectorWheelPaintField.setAccessible(true);
try {
selectorWheelPaintField = picker.getClass().getDeclaredField("mSelectorWheelPaint");
if (selectorWheelPaintField) {
selectorWheelPaintField.setAccessible(true);
}
} catch (err) {
// mSelectorWheelPaint is not supported on api level
}
}
return selectorWheelPaintField.get(picker);
if (selectorWheelPaintField) {
return selectorWheelPaintField.get(picker);
}
return null;
}
export class ListPicker extends ListPickerBase {
@@ -98,9 +108,7 @@ export class ListPicker extends ListPickerBase {
// api28 and lower uses reflection to retrieve and manipulate
// android.graphics.Paint object; this is no longer allowed on newer api levels but
// equivalent public methods are exposed on api29+ directly on the native widget
if (sdkVersion() < 29) {
this._selectorWheelPaint = getSelectorWheelPaint(nativeView);
}
this._selectorWheelPaint = getSelectorWheelPaint(nativeView);
const formatter = new Formatter(this);
nativeView.setFormatter(formatter);
@@ -172,7 +180,11 @@ export class ListPicker extends ListPickerBase {
return this._selectorWheelPaint.getColor();
}
return this.nativeView.getTextColor();
if (this.nativeView && this.nativeView.getTextColor) {
return this.nativeView.getTextColor();
} else {
return 0;
}
}
[colorProperty.setNative](value: number | Color) {
const color = value instanceof Color ? value.android : value;
@@ -187,7 +199,7 @@ export class ListPicker extends ListPickerBase {
if (editText) {
editText.setTextColor(color);
}
} else {
} else if (this.nativeView && this.nativeView.setTextColor) {
// api29 and higher native implementation sets
// both wheel color and input text color with single call
this.nativeView.setTextColor(color);

View File

@@ -2,7 +2,7 @@
"name": "NativeScript",
"description": "NativeScript Core Modules",
"homepage": "https://www.nativescript.org",
"version": "6.5.13",
"version": "6.5.15",
"repository": {
"type": "git",
"url": "https://github.com/NativeScript/NativeScript"

View File

@@ -3,7 +3,7 @@
"main": "index",
"types": "index.d.ts",
"description": "NativeScript Core Modules",
"version": "6.5.13",
"version": "6.5.15",
"homepage": "https://www.nativescript.org",
"repository": {
"type": "git",

View File

@@ -1,6 +1,6 @@
{
"name": "tns-platform-declarations",
"version": "6.5.13",
"version": "6.5.15",
"description": "Platform-specific TypeScript declarations for NativeScript for accessing native objects",
"main": "",
"scripts": {