Skip to content

Commit 0f8d9be

Browse files
committed
Refactor Range component to optimize offset value update
1 parent ee62bfa commit 0f8d9be

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/components/Range.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ export default function Range({ value, setValue, Left, Right, accent = Colors.ac
1818
const scale = useSharedValue(1)
1919

2020
useEffect(() => {
21-
if (containerWidth > 0) {
22-
offset.value = withTiming(containerWidth * value)
23-
}
21+
const timer = setTimeout(() => {
22+
if (containerWidth > 0) offset.value = withTiming(containerWidth * value)
23+
}, 50)
24+
return () => clearTimeout(timer)
2425
// eslint-disable-next-line react-hooks/exhaustive-deps
2526
}, [containerWidth])
2627

@@ -48,7 +49,7 @@ export default function Range({ value, setValue, Left, Right, accent = Colors.ac
4849

4950
const handleLayout = useCallback((event: LayoutChangeEvent) => {
5051
const { width } = event.nativeEvent.layout
51-
setContainerWidth(width)
52+
if (width !== 0) setContainerWidth(width)
5253
}, [])
5354

5455
return (

0 commit comments

Comments
 (0)