Skip to content

Commit 36f5803

Browse files
committed
fix(slider): faster android slider
1 parent b6f689c commit 36f5803

File tree

2 files changed

+9
-23
lines changed

2 files changed

+9
-23
lines changed

src/core/android/utils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,14 +165,14 @@ export function getFullColorStateList(activeColor: number, inactiveColor = 16273
165165
}
166166
return NUtils.getFullColorStateList(activeColor, inactiveColor, disabledColor);
167167
}
168-
export function getEnabledColorStateList(color: number, variant: string) {
168+
export function getEnabledColorStateList(color: number, disabledColor: number) {
169169
if (!color) {
170170
return null;
171171
}
172172
if (!NUtils) {
173173
NUtils = (com as any).nativescript.material.core.Utils;
174174
}
175-
return NUtils.getEnabledColorStateList(color, variant);
175+
return NUtils.getEnabledColorStateList(color, disabledColor);
176176
}
177177

178178
let NUtils;

src/slider/slider.android.ts

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,14 @@
11
import { cssProperty, rippleColorProperty, themer } from '@nativescript-community/ui-material-core';
2-
import { state } from '@nativescript-community/ui-material-core/android/utils';
2+
import { getEnabledColorStateList, state } from '@nativescript-community/ui-material-core/android/utils';
33
import { CoercibleProperty, Color, Property, View, backgroundColorProperty, backgroundInternalProperty, colorProperty } from '@nativescript/core';
44
import { thumbColorProperty, trackBackgroundColorProperty, trackFillColorProperty } from './cssproperties';
55

66
let ASlider: typeof com.google.android.material.slider.Slider;
7-
export function getEnabledColorStateList(color: Color, alpha = 255) {
7+
export function sliderGetEnabledColorStateList(color: Color, alpha = 255) {
88
if (!color) {
99
return null;
1010
}
11-
const states = Array.create('[I', 2);
12-
// const SELECTED_PRESSED_STATE_SET = Array.create("int",1);
13-
// SELECTED_PRESSED_STATE_SET[0] = state.enabled;
14-
states[0] = Array.create('int', 1);
15-
states[0][0] = -state.enabled;
16-
states[1] = android.util.StateSet.NOTHING;
17-
// states[1][0] = new java.lang.Integer(-state.enabled);
18-
// const states = [
19-
// getSELECTED_PRESSED_STATE_SET(),
20-
// []]
21-
// ;
22-
const colors = Array.create('int', 2);
23-
colors[0] = new Color(alpha, 158, 158, 158).android;
24-
colors[1] = color.android;
25-
return new android.content.res.ColorStateList(states, colors);
11+
return getEnabledColorStateList(color.android, new Color(alpha, 158, 158, 158).android);
2612
}
2713
export const valueProperty = new CoercibleProperty<Slider, number>({
2814
name: 'value',
@@ -127,7 +113,7 @@ export class Slider extends View {
127113

128114
[colorProperty.setNative](color: Color) {
129115
if (color) {
130-
this.nativeViewProtected.setTrackTintList(getEnabledColorStateList(color));
116+
this.nativeViewProtected.setTrackTintList(sliderGetEnabledColorStateList(color));
131117
if (!this.trackBackgroundColor) {
132118
this.trackBackgroundColor = new Color(61.2, color.r, color.g, color.b);
133119
}
@@ -180,7 +166,7 @@ export class Slider extends View {
180166
this.nativeViewProtected.setHaloTintList(color ? android.content.res.ColorStateList.valueOf(color.android) : null);
181167
}
182168
[thumbColorProperty.setNative](color: Color) {
183-
this.nativeViewProtected.setThumbTintList(getEnabledColorStateList(color));
169+
this.nativeViewProtected.setThumbTintList(sliderGetEnabledColorStateList(color));
184170
if (!this.rippleColor) {
185171
this.rippleColor = color;
186172
} else {
@@ -189,10 +175,10 @@ export class Slider extends View {
189175
}
190176
}
191177
[trackBackgroundColorProperty.setNative](color: Color) {
192-
this.nativeViewProtected.setTrackInactiveTintList(getEnabledColorStateList(color, 61.2));
178+
this.nativeViewProtected.setTrackInactiveTintList(sliderGetEnabledColorStateList(color, 61.2));
193179
}
194180
[trackFillColorProperty.setNative](color: Color) {
195-
this.nativeViewProtected.setTrackActiveTintList(getEnabledColorStateList(color));
181+
this.nativeViewProtected.setTrackActiveTintList(sliderGetEnabledColorStateList(color));
196182
}
197183

198184
// [elevationProperty.setNative](value: number) {

0 commit comments

Comments
 (0)