Skip to content

Commit

Permalink
fix(android): findStateDrawableIndex reflection method
Browse files Browse the repository at this point in the history
  • Loading branch information
m1ga committed Sep 25, 2023
1 parent 9cab86c commit 67b0f84
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1256,8 +1256,12 @@ public static String getBackgroundColorForState(TiBackgroundDrawable backgroundD
// Get the backgroundDrawable background as a StateListDrawable.
StateListDrawable stateListDrawable = (StateListDrawable) simpleDrawable;
// Get the reflection methods.
String methodName = "getStateDrawableIndex";
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
methodName = "findStateDrawableIndex";
}
Method getStateDrawableIndexMethod =
StateListDrawable.class.getMethod("getStateDrawableIndex", int[].class);
StateListDrawable.class.getMethod(methodName, int[].class);
Method getStateDrawableMethod = StateListDrawable.class.getMethod("getStateDrawable", int.class);
// Get the disabled state's (as defined in TiUIHelper) index.
int index = (int) getStateDrawableIndexMethod.invoke(stateListDrawable, state);
Expand Down

0 comments on commit 67b0f84

Please sign in to comment.