Skip to content

Commit

Permalink
fix(android): list picker getTextColor api level issue (#8755)
Browse files Browse the repository at this point in the history
closes #7860
  • Loading branch information
NathanWalker committed Aug 12, 2020
1 parent 23fbc64 commit 5c076de
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 12 deletions.
2 changes: 1 addition & 1 deletion nativescript-core/package.json
Expand Up @@ -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",
Expand Down
28 changes: 20 additions & 8 deletions nativescript-core/ui/list-picker/list-picker.android.ts
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion tns-core-modules-package/package.json
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion tns-platform-declarations/package.json
@@ -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": {
Expand Down

0 comments on commit 5c076de

Please sign in to comment.