Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 36 additions & 20 deletions tns-core-modules/ui/list-picker/list-picker.android.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { ListPickerBase, selectedIndexProperty, itemsProperty, colorProperty, Color } from "./list-picker-common";
import { ItemsSource } from ".";
import { device } from "../../platform";
import lazy from "../../utils/lazy";

export * from "./list-picker-common";

const sdkVersion = lazy(() => parseInt(device.sdkVersion));

interface Formatter {
new (owner: ListPicker): android.widget.NumberPicker.Formatter;
}
Expand Down Expand Up @@ -90,7 +94,14 @@ export class ListPicker extends ListPickerBase {
super.initNativeView();
initializeNativeClasses();
const nativeView = this.nativeViewProtected;
this._selectorWheelPaint = getSelectorWheelPaint(nativeView);

// 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);
}

const formatter = new Formatter(this);
nativeView.setFormatter(formatter);
(<any>nativeView).formatter = formatter;
Expand Down Expand Up @@ -153,28 +164,33 @@ export class ListPicker extends ListPickerBase {
selectedIndexProperty.coerce(this);
}

[colorProperty.getDefault](): { wheelColor: number, textColor: number } {
const editText = (<any>this.nativeViewProtected).editText;
[colorProperty.getDefault](): number {
// 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 (this._selectorWheelPaint) {
return this._selectorWheelPaint.getColor();
}

return {
wheelColor: this._selectorWheelPaint.getColor(),
textColor: editText ? editText.getTextColors().getDefaultColor() : -1
};
return this.nativeView.getTextColor();
}
[colorProperty.setNative](value: { wheelColor: number, textColor: number } | Color) {
let color: number;
let wheelColor: number;
if (value instanceof Color) {
color = wheelColor = value.android;
[colorProperty.setNative](value: number | Color) {
const color = value instanceof Color ? value.android : value;

// 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 (this._selectorWheelPaint) {
this._selectorWheelPaint.setColor(color);

const editText = (<any>this.nativeViewProtected).editText;
if (editText) {
editText.setTextColor(color);
}
} else {
color = value.textColor;
wheelColor = value.wheelColor;
}

this._selectorWheelPaint.setColor(wheelColor);
const editText = (<any>this.nativeViewProtected).editText;
if (editText) {
editText.setTextColor(color);
// api29 and higher native implementation sets
// both wheel color and input text color with single call
this.nativeView.setTextColor(color);
}
}
}