mirror of
https://github.com/NativeScript/NativeScript.git
synced 2025-11-05 13:26:48 +08:00
fix(android): list picker getTextColor api level issue (#8755)
closes https://github.com/NativeScript/NativeScript/issues/7860
This commit is contained in:
@@ -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",
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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": {
|
||||
|
||||
Reference in New Issue
Block a user