Skip to content

Commit ea16a3f

Browse files
committed
fix: reduce lag when overriding animator
1 parent 1dd5a91 commit ea16a3f

File tree

1 file changed

+8
-3
lines changed
  • lib/src/nativescript-ngx-shadow/common

1 file changed

+8
-3
lines changed

lib/src/nativescript-ngx-shadow/common/shadow.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ if (isAndroid) {
2121
PlainShadow = android.graphics.drawable.GradientDrawable.extend({});
2222
}
2323

24+
// https://github.com/NativeScript/android-runtime/issues/1330
25+
function getAndroidR(rtype: string, field: string): number {
26+
return +java.lang.Class.forName("android.R$" + rtype).getField(field).get(null);
27+
}
28+
2429
export class Shadow {
2530
static DEFAULT_SHAPE = ShapeEnum.RECTANGLE;
2631
static DEFAULT_BGCOLOR = '#FFFFFF';
@@ -138,7 +143,7 @@ export class Shadow {
138143

139144
const ObjectAnimator = android.animation.ObjectAnimator;
140145
const AnimatorSet = android.animation.AnimatorSet;
141-
const shortAnimTime = android.R.integer.config_shortAnimTime;
146+
const shortAnimTime = getAndroidR("integer", "config_shortAnimTime");
142147

143148
const buttonDuration =
144149
nativeView.getContext().getResources().getInteger(shortAnimTime) / 2;
@@ -169,10 +174,10 @@ export class Shadow {
169174
]));
170175

171176
sla.addState(
172-
[android.R.attr.state_pressed, android.R.attr.state_enabled],
177+
[getAndroidR("attr", "state_pressed"), getAndroidR("attr", "state_enabled")],
173178
pressedSet,
174179
);
175-
sla.addState([android.R.attr.state_enabled], notPressedSet);
180+
sla.addState([getAndroidR("attr", "state_enabled")], notPressedSet);
176181
sla.addState([], defaultSet);
177182
nativeView.setStateListAnimator(sla);
178183
}

0 commit comments

Comments
 (0)