Skip to content

Commit

Permalink
Fix measure of ReactSlider for Android API < 21
Browse files Browse the repository at this point in the history
Summary:
This diff avoids calling to the method setStateListAnimator for users running in Android API < 21 (This method did not exist in Android API < 21)

changelog: [Android][Fix] Fix crash while measuring ReactSlider in Android API < 21

Reviewed By: lunaleaps

Differential Revision: D22164574

fbshipit-source-id: 8163f99eeb78302fc75e2c4938330c699ca8d363
  • Loading branch information
mdvacca authored and facebook-github-bot committed Jun 22, 2020
1 parent c3d4d2a commit 75e6f79
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public ReactSlider(Context context, @Nullable AttributeSet attrs, int style) {
disableStateListAnimatorIfNeeded();
}

private void disableStateListAnimatorIfNeeded() {
/* package */ void disableStateListAnimatorIfNeeded() {
// We disable the state list animator for Android 6 and 7; this is a hack to prevent T37452851
// and https://github.com/facebook/react-native/issues/9979
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,11 @@ public long measure(
float height,
YogaMeasureMode heightMode) {
if (!mMeasured) {
SeekBar reactSlider = new ReactSlider(getThemedContext(), null, STYLE);
ReactSlider reactSlider = new ReactSlider(getThemedContext(), null, STYLE);
// reactSlider is used for measurements purposes, it is not necessary to set a
// StateListAnimator.
// It is not safe to access StateListAnimator from a background thread.
reactSlider.setStateListAnimator(null);
reactSlider.disableStateListAnimatorIfNeeded();
final int spec =
View.MeasureSpec.makeMeasureSpec(
ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.UNSPECIFIED);
Expand Down

0 comments on commit 75e6f79

Please sign in to comment.