Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions package/src/RNCSliderNativeComponent.web.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import React, {RefObject, useCallback} from 'react';
import {
Animated,
View,
StyleSheet,
ColorValue,
ViewStyle,
GestureResponderEvent,
Expand Down Expand Up @@ -118,18 +117,22 @@ const RCTSliderWebComponent = React.forwardRef(

const onSlidingStart = useCallback(
(value: number) => {
isUserInteracting.current = true;
onRNCSliderSlidingStart && onRNCSliderSlidingStart(valueToEvent(value));
},
[onRNCSliderSlidingStart],
);

const onSlidingComplete = useCallback(
(value: number) => {
isUserInteracting.current = false;
onRNCSliderSlidingComplete &&
onRNCSliderSlidingComplete(valueToEvent(value));
},
[onRNCSliderSlidingComplete],
);
// Add a ref to track user interaction
const isUserInteracting = React.useRef(false);
const updateValue = useCallback(
(newValue: number) => {
// Ensure that the value is correctly rounded
Expand All @@ -145,7 +148,9 @@ const RCTSliderWebComponent = React.forwardRef(
);
if (value !== withinBounds) {
setValue(withinBounds);
onValueChange(withinBounds);
if (isUserInteracting.current) {
onValueChange(withinBounds);
}
return withinBounds;
}
return hardRounded;
Expand Down Expand Up @@ -197,7 +202,7 @@ const RCTSliderWebComponent = React.forwardRef(
};
}, [containerRef]);

const containerStyle = StyleSheet.compose(
const containerStyle = [
{
flexGrow: 1,
flexShrink: 1,
Expand All @@ -206,7 +211,7 @@ const RCTSliderWebComponent = React.forwardRef(
alignItems: 'center',
},
style,
);
] as ViewStyle[];

const trackStyle = {
height: trackHeight,
Expand All @@ -226,7 +231,7 @@ const RCTSliderWebComponent = React.forwardRef(
flexGrow: maxPercent,
};

const thumbViewStyle = StyleSheet.compose(
const thumbViewStyle = [
{
width: thumbSize,
height: thumbSize,
Expand All @@ -236,7 +241,7 @@ const RCTSliderWebComponent = React.forwardRef(
overflow: 'hidden',
},
thumbStyle,
);
] as ViewStyle[];

const decimalPrecision = React.useRef(
calculatePrecision(minimumValue, maximumValue, step),
Expand Down
2 changes: 1 addition & 1 deletion package/src/Slider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ const SliderComponent = (
props: Props,
forwardedRef?: Ref<typeof RCTSliderNativeComponent>,
) => {
const style = StyleSheet.compose(props.style, styles.slider);
const style = props.style ? [props.style, styles.slider] : styles.slider;

const {
onValueChange,
Expand Down