|
1 | 1 | import { ListPickerBase, selectedIndexProperty, itemsProperty, colorProperty, Color } from "./list-picker-common"; |
2 | 2 | import { ItemsSource } from "."; |
| 3 | +import { device } from "../../platform"; |
| 4 | +import lazy from "../../utils/lazy"; |
3 | 5 |
|
4 | 6 | export * from "./list-picker-common"; |
5 | 7 |
|
| 8 | +const sdkVersion = lazy(() => parseInt(device.sdkVersion)); |
| 9 | + |
6 | 10 | interface Formatter { |
7 | 11 | new (owner: ListPicker): android.widget.NumberPicker.Formatter; |
8 | 12 | } |
@@ -90,7 +94,14 @@ export class ListPicker extends ListPickerBase { |
90 | 94 | super.initNativeView(); |
91 | 95 | initializeNativeClasses(); |
92 | 96 | const nativeView = this.nativeViewProtected; |
93 | | - this._selectorWheelPaint = getSelectorWheelPaint(nativeView); |
| 97 | + |
| 98 | + // api28 and lower uses reflection to retrieve and manipulate |
| 99 | + // android.graphics.Paint object; this is no longer allowed on newer api levels but |
| 100 | + // equivalent public methods are exposed on api29+ directly on the native widget |
| 101 | + if (sdkVersion() < 29) { |
| 102 | + this._selectorWheelPaint = getSelectorWheelPaint(nativeView); |
| 103 | + } |
| 104 | + |
94 | 105 | const formatter = new Formatter(this); |
95 | 106 | nativeView.setFormatter(formatter); |
96 | 107 | (<any>nativeView).formatter = formatter; |
@@ -153,28 +164,33 @@ export class ListPicker extends ListPickerBase { |
153 | 164 | selectedIndexProperty.coerce(this); |
154 | 165 | } |
155 | 166 |
|
156 | | - [colorProperty.getDefault](): { wheelColor: number, textColor: number } { |
157 | | - const editText = (<any>this.nativeViewProtected).editText; |
| 167 | + [colorProperty.getDefault](): number { |
| 168 | + // api28 and lower uses reflection to retrieve and manipulate |
| 169 | + // android.graphics.Paint object; this is no longer allowed on newer api levels but |
| 170 | + // equivalent public methods are exposed on api29+ directly on the native widget |
| 171 | + if (this._selectorWheelPaint) { |
| 172 | + return this._selectorWheelPaint.getColor(); |
| 173 | + } |
158 | 174 |
|
159 | | - return { |
160 | | - wheelColor: this._selectorWheelPaint.getColor(), |
161 | | - textColor: editText ? editText.getTextColors().getDefaultColor() : -1 |
162 | | - }; |
| 175 | + return this.nativeView.getTextColor(); |
163 | 176 | } |
164 | | - [colorProperty.setNative](value: { wheelColor: number, textColor: number } | Color) { |
165 | | - let color: number; |
166 | | - let wheelColor: number; |
167 | | - if (value instanceof Color) { |
168 | | - color = wheelColor = value.android; |
| 177 | + [colorProperty.setNative](value: number | Color) { |
| 178 | + const color = value instanceof Color ? value.android : value; |
| 179 | + |
| 180 | + // api28 and lower uses reflection to retrieve and manipulate |
| 181 | + // android.graphics.Paint object; this is no longer allowed on newer api levels but |
| 182 | + // equivalent public methods are exposed on api29+ directly on the native widget |
| 183 | + if (this._selectorWheelPaint) { |
| 184 | + this._selectorWheelPaint.setColor(color); |
| 185 | + |
| 186 | + const editText = (<any>this.nativeViewProtected).editText; |
| 187 | + if (editText) { |
| 188 | + editText.setTextColor(color); |
| 189 | + } |
169 | 190 | } else { |
170 | | - color = value.textColor; |
171 | | - wheelColor = value.wheelColor; |
172 | | - } |
173 | | - |
174 | | - this._selectorWheelPaint.setColor(wheelColor); |
175 | | - const editText = (<any>this.nativeViewProtected).editText; |
176 | | - if (editText) { |
177 | | - editText.setTextColor(color); |
| 191 | + // api29 and higher native implementation sets |
| 192 | + // both wheel color and input text color with single call |
| 193 | + this.nativeView.setTextColor(color); |
178 | 194 | } |
179 | 195 | } |
180 | 196 | } |
0 commit comments