diff --git a/android/src/newarch/java/com/reactnativecommunity/slider/ReactSliderManager.java b/android/src/newarch/java/com/reactnativecommunity/slider/ReactSliderManager.java index a5bb95eec3337b93a2338a2869a2bda176c91cae..87817688eb280c2f702c26dc35558c6a0a4db1ea 100644 --- a/android/src/newarch/java/com/reactnativecommunity/slider/ReactSliderManager.java +++ b/android/src/newarch/java/com/reactnativecommunity/slider/ReactSliderManager.java @@ -42,12 +42,20 @@ public class ReactSliderManager extends SimpleViewManager implement public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) { ReactSlider slider = (ReactSlider)seekbar; - if(progress < slider.getLowerLimit()) { - progress = slider.getLowerLimit(); - seekbar.setProgress(progress); - } else if (progress > slider.getUpperLimit()) { - progress = slider.getUpperLimit(); - seekbar.setProgress(progress); + // During initialization, lowerLimit can be greater than upperLimit. + // + // If a change event is received during this, we need a check to prevent + // infinite recursion. + // + // Issue: https://github.com/callstack/react-native-slider/issues/571 + if (slider.getLowerLimit() <= slider.getUpperLimit()) { + if(progress < slider.getLowerLimit()) { + progress = slider.getLowerLimit(); + seekbar.setProgress(progress); + } else if (progress > slider.getUpperLimit()) { + progress = slider.getUpperLimit(); + seekbar.setProgress(progress); + } } ReactContext reactContext = (ReactContext) seekbar.getContext(); diff --git a/android/src/oldarch/java/com/reactnativecommunity/slider/ReactSliderManager.java b/android/src/oldarch/java/com/reactnativecommunity/slider/ReactSliderManager.java index 3ff5930f85a3cd92c2549925f41058abb188a57e..ab3681fdfe0b736c97020e1434e450c8183e6f18 100644 --- a/android/src/oldarch/java/com/reactnativecommunity/slider/ReactSliderManager.java +++ b/android/src/oldarch/java/com/reactnativecommunity/slider/ReactSliderManager.java @@ -30,12 +30,20 @@ public class ReactSliderManager extends SimpleViewManager { public void onProgressChanged(SeekBar seekbar, int progress, boolean fromUser) { ReactSlider slider = (ReactSlider)seekbar; - if(progress < slider.getLowerLimit()) { - progress = slider.getLowerLimit(); - seekbar.setProgress(progress); - } else if(progress > slider.getUpperLimit()) { - progress = slider.getUpperLimit(); - seekbar.setProgress(progress); + // During initialization, lowerLimit can be greater than upperLimit. + // + // If a change event is received during this, we need a check to prevent + // infinite recursion. + // + // Issue: https://github.com/callstack/react-native-slider/issues/571 + if (slider.getLowerLimit() <= slider.getUpperLimit()) { + if(progress < slider.getLowerLimit()) { + progress = slider.getLowerLimit(); + seekbar.setProgress(progress); + } else if (progress > slider.getUpperLimit()) { + progress = slider.getUpperLimit(); + seekbar.setProgress(progress); + } } ReactContext reactContext = (ReactContext) seekbar.getContext();