Skip to content

Commit 0157466

Browse files
authored
Slider/add throttleTime prop (#3020)
* Slider/add disableTrottling prop * add throttleTime props (instead of disable) * add default 200
1 parent f2622cc commit 0157466

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

src/incubator/Slider/index.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,10 @@ export interface SliderProps extends AccessibilityProps {
139139
* Whether to use the new Slider implementation using Reanimated
140140
*/
141141
migrate?: boolean;
142+
/**
143+
* Control the throttle time of the onValueChange and onRangeChange callbacks
144+
*/
145+
throttleTime?: number;
142146
}
143147

144148
type Props = SliderProps & ForwardRefInjectedProps<SliderRef>;
@@ -188,7 +192,8 @@ const Slider = React.memo((props: Props) => {
188192
useGap = true,
189193
accessible = true,
190194
testID,
191-
enableThumbShadow = true
195+
enableThumbShadow = true,
196+
throttleTime = 200
192197
} = themeProps;
193198

194199
const accessibilityProps = useMemo(() => {
@@ -277,11 +282,11 @@ const Slider = React.memo((props: Props) => {
277282
} else {
278283
didValueUpdate.current = false;
279284
}
280-
}, 200), [onValueChange]);
285+
}, throttleTime), [onValueChange]);
281286

282287
const onRangeChangeThrottled = useCallback(_.throttle((min, max) => {
283288
onRangeChange?.({min, max});
284-
}, 100), [onRangeChange]);
289+
}, throttleTime), [onRangeChange]);
285290

286291
useAnimatedReaction(() => {
287292
return Math.round(defaultThumbOffset.value);

src/incubator/Slider/slider.api.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,11 @@
9191
"type": "boolean",
9292
"description": "If true the component will have accessibility features enabled"
9393
},
94+
{
95+
"name": "throttleTime",
96+
"type": "number",
97+
"description": "Control the throttle time of the onValueChange and onRangeChange callbacks"
98+
},
9499
{"name": "testID", "type": "string", "description": "The component test id"}
95100
],
96101
"snippet": [

0 commit comments

Comments
 (0)