Skip to content

Incubator Slider - fix step interpolation #2988

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

Merged
merged 3 commits into from
Mar 27, 2024

Conversation

Inbal-Tish
Copy link
Collaborator

@Inbal-Tish Inbal-Tish commented Mar 19, 2024

Description

Incubator Slider - fix step interpolation

to reproduce:
<Incubator.Slider value={sliderValue} onValueChange={setSliderValue} step={1} minimumValue={12} maximumValue={50} />
Slider or press track to see the slider jumps.

Changelog

Incubator Slider - fix step interpolation

Additional info

ticket 4070

@Inbal-Tish Inbal-Tish requested a review from ethanshar March 19, 2024 13:21
@Inbal-Tish Inbal-Tish added the hotfix Requires a hotfix release label Mar 19, 2024
@@ -58,7 +58,6 @@ export function validateValues(props: SliderProps) {
export function getStepInterpolated(trackWidth: number, minimumValue: number, maximumValue: number, stepXValue: SharedValue<number>) {
'worklet';
const outputRange = [0, trackWidth];
const inputRange = minimumValue < 0 ?
[Math.abs(maximumValue), Math.abs(minimumValue)] : [minimumValue, maximumValue];
const inputRange = minimumValue < 0 ? [0, Math.abs(minimumValue)] : [0, maximumValue];
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see that it works, but Im not sure I understand the bug.
Can you explain what happens here that caused this?

Copy link
Collaborator Author

@Inbal-Tish Inbal-Tish Mar 21, 2024

Choose a reason for hiding this comment

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

Ok, I added refinement to explain: The interpolation finds a value from one range at a different range. In this case, the value is the stepXValue, the x point equal to the step. This value is used to calculate the new location from the current location - where to jump to. Since this is an x value it doesn't care if the initial value is 12, it needs to start from 0 to give a value of x, so instead of defining the range 12 to 50, I'll define it as 0 to 38.

Copy link
Collaborator

Choose a reason for hiding this comment

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

👍

@Inbal-Tish Inbal-Tish added the Important for Next Release PR that must be included in the release version label Mar 25, 2024
@ethanshar ethanshar merged commit 5049b12 into master Mar 27, 2024
@ethanshar ethanshar deleted the fix/IncubatorSlider_step_interpolation branch March 27, 2024 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotfix Requires a hotfix release Important for Next Release PR that must be included in the release version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants