-
Notifications
You must be signed in to change notification settings - Fork 267
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: check for invalid configuration in limit settings #638
base: main
Are you sure you want to change the base?
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -11,6 +11,7 @@ | |||||||||||||||||||
import android.graphics.BitmapFactory; | ||||||||||||||||||||
import android.graphics.drawable.BitmapDrawable; | ||||||||||||||||||||
import android.os.Build; | ||||||||||||||||||||
import android.util.Log; | ||||||||||||||||||||
import android.util.AttributeSet; | ||||||||||||||||||||
import android.view.accessibility.AccessibilityEvent; | ||||||||||||||||||||
import android.view.accessibility.AccessibilityManager; | ||||||||||||||||||||
|
@@ -104,6 +105,15 @@ private void disableStateListAnimatorIfNeeded() { | |||||||||||||||||||
updateAll(); | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
/*package*/ int getValidProgressValue(int progress) { | ||||||||||||||||||||
if (progress < getLowerLimit()) { | ||||||||||||||||||||
progress = getLowerLimit(); | ||||||||||||||||||||
} else if (progress > getUpperLimit()) { | ||||||||||||||||||||
progress = getUpperLimit(); | ||||||||||||||||||||
} | ||||||||||||||||||||
return progress; | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
/* package */ void setValue(double value) { | ||||||||||||||||||||
mValue = value; | ||||||||||||||||||||
updateValue(); | ||||||||||||||||||||
|
@@ -222,16 +232,28 @@ private void updateAll() { | |||||||||||||||||||
updateValue(); | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
/** Update limit based on props limit, max and min */ | ||||||||||||||||||||
/** Update limit based on props limit, max and min | ||||||||||||||||||||
* Fallback to upper limit if invalid configuration provided | ||||||||||||||||||||
*/ | ||||||||||||||||||||
private void updateLowerLimit() { | ||||||||||||||||||||
double limit = Math.max(mRealLowerLimit, mMinValue); | ||||||||||||||||||||
mLowerLimit = (int) Math.round((limit - mMinValue) / (mMaxValue - mMinValue) * getTotalSteps()); | ||||||||||||||||||||
int lowerLimit = (int) Math.round((limit - mMinValue) / (mMaxValue - mMinValue) * getTotalSteps()); | ||||||||||||||||||||
if(lowerLimit > mUpperLimit) { | ||||||||||||||||||||
Log.w("Invalid configuration", "reverting lower limit to upper limit"); | ||||||||||||||||||||
} | ||||||||||||||||||||
mLowerLimit = Math.min(lowerLimit, mUpperLimit); | ||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
/** Update limit based on props limit, max and min */ | ||||||||||||||||||||
/** Update limit based on props limit, max and min | ||||||||||||||||||||
* Fallback to lower limit if invalid configuration provided | ||||||||||||||||||||
*/ | ||||||||||||||||||||
private void updateUpperLimit() { | ||||||||||||||||||||
double limit = Math.min(mRealUpperLimit, mMaxValue); | ||||||||||||||||||||
mUpperLimit = (int) Math.round((limit - mMinValue) / (mMaxValue - mMinValue) * getTotalSteps()); | ||||||||||||||||||||
int upperLimit = (int) Math.round((limit - mMinValue) / (mMaxValue - mMinValue) * getTotalSteps()); | ||||||||||||||||||||
if(mLowerLimit > upperLimit) { | ||||||||||||||||||||
Log.w("Invalid configuration", "reverting upper limit to equal to lower limit"); | ||||||||||||||||||||
} | ||||||||||||||||||||
mUpperLimit = Math.max(upperLimit, mLowerLimit); | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||
} | ||||||||||||||||||||
|
||||||||||||||||||||
/** Update value only (optimization in case only value is set). */ | ||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -158,8 +158,26 @@ - (void)sliderTouchEnd:(RNCSlider *)sender | |||||||||||||||||||||||
RCT_EXPORT_VIEW_PROPERTY(maximumTrackImage, UIImage); | ||||||||||||||||||||||||
RCT_EXPORT_VIEW_PROPERTY(minimumValue, float); | ||||||||||||||||||||||||
RCT_EXPORT_VIEW_PROPERTY(maximumValue, float); | ||||||||||||||||||||||||
RCT_EXPORT_VIEW_PROPERTY(lowerLimit, float); | ||||||||||||||||||||||||
RCT_EXPORT_VIEW_PROPERTY(upperLimit, float); | ||||||||||||||||||||||||
RCT_CUSTOM_VIEW_PROPERTY(lowerLimit, float, RNCSlider) { | ||||||||||||||||||||||||
float lowerLimit = [RCTConvert float:json]; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if (lowerLimit > view.upperLimit) { | ||||||||||||||||||||||||
lowerLimit = view.upperLimit; | ||||||||||||||||||||||||
NSLog(@"Invalid configuration: reverting upper limit to equal to lower limit") | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
view.lowerLimit = lowerLimit; | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
} | ||||||||||||||||||||||||
RCT_CUSTOM_VIEW_PROPERTY(upperLimit, float, RNCSlider) { | ||||||||||||||||||||||||
float upperLimit = [RCTConvert float:json]; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if (upperLimit < view.lowerLimit) { | ||||||||||||||||||||||||
upperLimit = view.lowerLimit; | ||||||||||||||||||||||||
NSLog(@"Invalid configuration: reverting lower limit to equal to upper limit") | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
view.upperLimit = upperLimit; | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
} | ||||||||||||||||||||||||
RCT_EXPORT_VIEW_PROPERTY(minimumTrackTintColor, UIColor); | ||||||||||||||||||||||||
RCT_EXPORT_VIEW_PROPERTY(maximumTrackTintColor, UIColor); | ||||||||||||||||||||||||
RCT_EXPORT_VIEW_PROPERTY(onRNCSliderValueChange, RCTBubblingEventBlock); | ||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React, {useState} from 'react'; | ||
import React, {useCallback, useEffect, useState} from 'react'; | ||
import { | ||
Image, | ||
Platform, | ||
|
@@ -281,6 +281,18 @@ const SliderComponent = ( | |
default: constants.LIMIT_MAX_VALUE, | ||
}); | ||
|
||
const limitCheck = useCallback(() => { | ||
if (lowerLimit >= upperLimit) { | ||
console.warn( | ||
'Invalid configuration: lower limit is supposed to me smaller than upper limit', | ||
); | ||
} | ||
}, [lowerLimit, upperLimit]); | ||
|
||
useEffect(() => { | ||
limitCheck(); | ||
}, [limitCheck, localProps]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We don't need to create separate callback for |
||
|
||
return ( | ||
<View | ||
onLayout={(event) => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We shouldn't display logs in very different format for the same type of error.
Let's unify all of them to the one proposed in the suggestions for iOS platform (of course considering whether it's for
upperLimit
orlowerLimit
).