From deaaf3c9e526057606bc12f4262d7d60d06ad38b Mon Sep 17 00:00:00 2001 From: "maciej.lodygowski" Date: Wed, 18 Sep 2024 14:48:56 +0200 Subject: [PATCH 1/3] fix: floating number problem on android --- .../com/reactnativecommunity/slider/ReactSlider.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/package/android/src/main/java/com/reactnativecommunity/slider/ReactSlider.java b/package/android/src/main/java/com/reactnativecommunity/slider/ReactSlider.java index b4eeed3c..42608b6c 100644 --- a/package/android/src/main/java/com/reactnativecommunity/slider/ReactSlider.java +++ b/package/android/src/main/java/com/reactnativecommunity/slider/ReactSlider.java @@ -15,6 +15,9 @@ import android.view.accessibility.AccessibilityEvent; import android.view.accessibility.AccessibilityManager; import androidx.appcompat.widget.AppCompatSeekBar; + +import java.math.BigDecimal; +import java.math.RoundingMode; import java.net.URL; import java.util.List; import java.util.Timer; @@ -239,12 +242,16 @@ private void updateValue() { setProgress((int) Math.round((mValue - mMinValue) / (mMaxValue - mMinValue) * getTotalSteps())); } + private double roundToSafeValue(double value) { + return new BigDecimal(value).setScale(2, RoundingMode.HALF_UP).doubleValue(); + } + private int getTotalSteps() { - return (int) Math.ceil((mMaxValue - mMinValue) / getStepValue()); + return (int) Math.ceil((roundToSafeValue(mMaxValue) - roundToSafeValue(mMinValue)) / getStepValue()); } private double getStepValue() { - return mStep > 0 ? mStep : mStepCalculated; + return roundToSafeValue(mStep > 0 ? mStep : mStepCalculated); } private BitmapDrawable getBitmapDrawable(final String uri) { From 767ffab54af4ac59688b3d46a868ed4eb955ff17 Mon Sep 17 00:00:00 2001 From: "maciej.lodygowski" Date: Fri, 20 Sep 2024 18:18:41 +0200 Subject: [PATCH 2/3] fix: change number type from float to double --- .../java/com/reactnativecommunity/slider/ReactSlider.java | 8 ++------ .../slider/ReactSliderManagerImpl.java | 6 +++--- .../reactnativecommunity/slider/ReactSliderManager.java | 6 +++--- .../reactnativecommunity/slider/ReactSliderManager.java | 6 +++--- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/package/android/src/main/java/com/reactnativecommunity/slider/ReactSlider.java b/package/android/src/main/java/com/reactnativecommunity/slider/ReactSlider.java index 42608b6c..5a67e8c3 100644 --- a/package/android/src/main/java/com/reactnativecommunity/slider/ReactSlider.java +++ b/package/android/src/main/java/com/reactnativecommunity/slider/ReactSlider.java @@ -242,16 +242,12 @@ private void updateValue() { setProgress((int) Math.round((mValue - mMinValue) / (mMaxValue - mMinValue) * getTotalSteps())); } - private double roundToSafeValue(double value) { - return new BigDecimal(value).setScale(2, RoundingMode.HALF_UP).doubleValue(); - } - private int getTotalSteps() { - return (int) Math.ceil((roundToSafeValue(mMaxValue) - roundToSafeValue(mMinValue)) / getStepValue()); + return (int) Math.ceil((mMaxValue - mMinValue) / getStepValue()); } private double getStepValue() { - return roundToSafeValue(mStep > 0 ? mStep : mStepCalculated); + return mStep > 0 ? mStep : mStepCalculated; } private BitmapDrawable getBitmapDrawable(final String uri) { diff --git a/package/android/src/main/java/com/reactnativecommunity/slider/ReactSliderManagerImpl.java b/package/android/src/main/java/com/reactnativecommunity/slider/ReactSliderManagerImpl.java index 3c7f057a..dff1f9dd 100644 --- a/package/android/src/main/java/com/reactnativecommunity/slider/ReactSliderManagerImpl.java +++ b/package/android/src/main/java/com/reactnativecommunity/slider/ReactSliderManagerImpl.java @@ -44,11 +44,11 @@ public static void setValue(ReactSlider view, double value) { } } - public static void setMinimumValue(ReactSlider view, float value) { + public static void setMinimumValue(ReactSlider view, double value) { view.setMinValue(value); } - public static void setMaximumValue(ReactSlider view, float value) { + public static void setMaximumValue(ReactSlider view, double value) { view.setMaxValue(value); } @@ -60,7 +60,7 @@ public static void setUpperLimit(ReactSlider view, double value) { view.setUpperLimit(value); } - public static void setStep(ReactSlider view, float value) { + public static void setStep(ReactSlider view, double value) { view.setStep(value); } diff --git a/package/android/src/newarch/java/com/reactnativecommunity/slider/ReactSliderManager.java b/package/android/src/newarch/java/com/reactnativecommunity/slider/ReactSliderManager.java index c780b8a4..61f3a015 100644 --- a/package/android/src/newarch/java/com/reactnativecommunity/slider/ReactSliderManager.java +++ b/package/android/src/newarch/java/com/reactnativecommunity/slider/ReactSliderManager.java @@ -113,19 +113,19 @@ public void setValue(ReactSlider view, float value) { @Override @ReactProp(name = "minimumValue", defaultFloat = 0f) - public void setMinimumValue(ReactSlider view, float value) { + public void setMinimumValue(ReactSlider view, double value) { ReactSliderManagerImpl.setMinimumValue(view, value); } @Override @ReactProp(name = "maximumValue", defaultFloat = 0f) - public void setMaximumValue(ReactSlider view, float value) { + public void setMaximumValue(ReactSlider view, double value) { ReactSliderManagerImpl.setMaximumValue(view, value); } @Override @ReactProp(name = "step", defaultFloat = 0f) - public void setStep(ReactSlider view, float value) { + public void setStep(ReactSlider view, double value) { ReactSliderManagerImpl.setStep(view, value); } diff --git a/package/android/src/oldarch/java/com/reactnativecommunity/slider/ReactSliderManager.java b/package/android/src/oldarch/java/com/reactnativecommunity/slider/ReactSliderManager.java index 05482018..f2b0379d 100644 --- a/package/android/src/oldarch/java/com/reactnativecommunity/slider/ReactSliderManager.java +++ b/package/android/src/oldarch/java/com/reactnativecommunity/slider/ReactSliderManager.java @@ -131,17 +131,17 @@ public void setValue(ReactSlider view, float value) { } @ReactProp(name = "minimumValue", defaultFloat = 0f) - public void setMinimumValue(ReactSlider view, float value) { + public void setMinimumValue(ReactSlider view, double value) { ReactSliderManagerImpl.setMinimumValue(view, value); } @ReactProp(name = "maximumValue", defaultFloat = 1f) - public void setMaximumValue(ReactSlider view, float value) { + public void setMaximumValue(ReactSlider view, double value) { ReactSliderManagerImpl.setMaximumValue(view, value); } @ReactProp(name = "lowerLimit") - public void setLowerLimit(ReactSlider view, float value) { + public void setLowerLimit(ReactSlider view, double value) { ReactSliderManagerImpl.setLowerLimit(view, value); } From baa959a4c9545d30df3c4aadf6a820de430d092b Mon Sep 17 00:00:00 2001 From: "maciej.lodygowski" Date: Fri, 20 Sep 2024 18:19:32 +0200 Subject: [PATCH 3/3] fix: remove unused imports --- .../main/java/com/reactnativecommunity/slider/ReactSlider.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/package/android/src/main/java/com/reactnativecommunity/slider/ReactSlider.java b/package/android/src/main/java/com/reactnativecommunity/slider/ReactSlider.java index 5a67e8c3..13819a82 100644 --- a/package/android/src/main/java/com/reactnativecommunity/slider/ReactSlider.java +++ b/package/android/src/main/java/com/reactnativecommunity/slider/ReactSlider.java @@ -16,8 +16,6 @@ import android.view.accessibility.AccessibilityManager; import androidx.appcompat.widget.AppCompatSeekBar; -import java.math.BigDecimal; -import java.math.RoundingMode; import java.net.URL; import java.util.List; import java.util.Timer;