Skip to content

Commit a6cdad3

Browse files
authored
Merge branch 'main' into elliott/fix-thumb-touch
2 parents 0612786 + 613ef9e commit a6cdad3

File tree

1 file changed

+33
-26
lines changed

1 file changed

+33
-26
lines changed

src/index.tsx

+33-26
Original file line numberDiff line numberDiff line change
@@ -212,24 +212,39 @@ export class Slider extends PureComponent<SliderProps, SliderState> {
212212
}
213213
}
214214

215-
componentDidUpdate() {
216-
const newValues = normalizeValue(
217-
this.props,
218-
this.props.value instanceof Animated.Value
219-
? this.props.value.__getValue()
220-
: this.props.value,
221-
);
222-
newValues.forEach((value, i) => {
223-
if (!this.state.values[i]) {
224-
this._setCurrentValue(value, i);
225-
} else if (value !== this.state.values[i].__getValue()) {
226-
if (this.props.animateTransitions) {
227-
this._setCurrentValueAnimated(value, i);
228-
} else {
229-
this._setCurrentValue(value, i);
230-
}
231-
}
232-
});
215+
componentDidUpdate(prevProps) {
216+
// Check if the value prop has changed
217+
if (this.props.value !== prevProps.value) {
218+
const newValues = normalizeValue(this.props, this.props.value);
219+
220+
this.setState({
221+
values: updateValues({
222+
values: this.state.values,
223+
newValues: newValues,
224+
}),
225+
}, () => {
226+
newValues.forEach((value, i) => {
227+
const currentValue = this.state.values[i].__getValue();
228+
if (value !== currentValue && this.props.animateTransitions) {
229+
this._setCurrentValueAnimated(value, i);
230+
} else {
231+
this._setCurrentValue(value, i);
232+
}
233+
});
234+
});
235+
}
236+
237+
// Check for other prop changes that might require state updates, e.g., trackMarks
238+
if (this.props.trackMarks !== prevProps.trackMarks) {
239+
const newTrackMarksValues = normalizeValue(this.props, this.props.trackMarks);
240+
241+
this.setState({
242+
trackMarksValues: updateValues({
243+
values: this.state.trackMarksValues,
244+
newValues: newTrackMarksValues,
245+
}),
246+
});
247+
}
233248
}
234249

235250
_getRawValues(
@@ -685,14 +700,6 @@ export class Slider extends PureComponent<SliderProps, SliderState> {
685700
valueVisibleStyle.opacity = 0;
686701
}
687702

688-
const interpolatedRawValues = this._getRawValues(
689-
interpolatedTrackValues,
690-
);
691-
const minRawValue = Math.min(...interpolatedRawValues);
692-
const minThumbValue = new Animated.Value(minRawValue);
693-
const maxRawValue = Math.max(...interpolatedRawValues);
694-
const maxThumbValue = new Animated.Value(maxRawValue);
695-
696703
const _value = values[0].__getValue();
697704
const sliderWidthCoefficient =
698705
containerSize.width /

0 commit comments

Comments
 (0)