Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

draggie
Copy link
Contributor

@draggie draggie commented Sep 10, 2024

Summary:

fixes: #571
Apply additional check and move the progress calculation to Slider class

Test Plan:

Have ran the application examples on new/old arch witch success - the crash is not happening anymore.

@draggie draggie self-assigned this Sep 10, 2024
Copy link
Member

@BartoszKlonowski BartoszKlonowski left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If lowerLimit > upperLimit we shouldn't fallback to upperLimit. If we do that, then we will end up with having lowerLimit === upperLimit, which will prevent Slider from moving at all. This is not the best experience.
If a dev/user makes a simple mistake, typo, of having lowerLimit greater than the upper one, then we should just avoid setting that incorrect limit. In that worst case, the limit that is incorrect will just not work, not the whole Slider.

Comment on lines 174 to 179
if (upperLimit < view.lowerLimit) {
upperLimit = view.lowerLimit;
NSLog(@"Invalid configuration: reverting lower limit to equal to upper limit")
}

view.upperLimit = upperLimit;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (upperLimit < view.lowerLimit) {
upperLimit = view.lowerLimit;
NSLog(@"Invalid configuration: reverting lower limit to equal to upper limit")
}
view.upperLimit = upperLimit;
if (upperLimit < view.lowerLimit) {
NSLog(@"Invalid configuration: upperLimit < lowerLimit; upperLimit not set")
} else {
view.upperLimit = upperLimit;
}

Comment on lines 164 to 169
if (lowerLimit > view.upperLimit) {
lowerLimit = view.upperLimit;
NSLog(@"Invalid configuration: reverting upper limit to equal to lower limit")
}

view.lowerLimit = lowerLimit;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (lowerLimit > view.upperLimit) {
lowerLimit = view.upperLimit;
NSLog(@"Invalid configuration: reverting upper limit to equal to lower limit")
}
view.lowerLimit = lowerLimit;
if (upperLimit < view.lowerLimit) {
NSLog(@"Invalid configuration: upperLimit < lowerLimit; lowerLimit not set")
} else {
view.lowerLimit = lowerLimit;
}

}, [lowerLimit, upperLimit]);

useEffect(() => {
limitCheck();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need to create separate callback for limitCheck and use it only in the effect.
Let's have that single if check and console.warn directly in this effect.
Also, if the callback uses lowerLimit, upperLimit for dependencies then I don't see a reason for using anything different in the dependencies of this effect.

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");
Copy link
Member

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 or lowerLimit).

Comment on lines 253 to 256
if(mLowerLimit > upperLimit) {
Log.w("Invalid configuration", "reverting upper limit to equal to lower limit");
}
mUpperLimit = Math.max(upperLimit, mLowerLimit);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if(mLowerLimit > upperLimit) {
Log.w("Invalid configuration", "reverting upper limit to equal to lower limit");
}
mUpperLimit = Math.max(upperLimit, mLowerLimit);
if (mLowerLimit > upperLimit) {
Log.w("Invalid configuration", "upperLimit < lowerLimit; upperLimit not set");
} else {
mUpperLimit = upperLimit;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants