From f702e12b17a7a7e9ebc59fb6be0328be012de29b Mon Sep 17 00:00:00 2001 From: "whey.party" Date: Mon, 1 Dec 2025 11:09:27 +0100 Subject: [PATCH] possible slider android crash fix --- src/components/forms/Slider.tsx | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/components/forms/Slider.tsx b/src/components/forms/Slider.tsx index 401e4e842..247c00b5f 100644 --- a/src/components/forms/Slider.tsx +++ b/src/components/forms/Slider.tsx @@ -1,4 +1,4 @@ -import {useCallback, useEffect, useRef, useState} from 'react' +import {useCallback, useEffect, useRef} from 'react' // Removed useState import {type StyleProp, View, type ViewStyle} from 'react-native' import {Gesture, GestureDetector} from 'react-native-gesture-handler' import Animated, { @@ -38,7 +38,7 @@ export function Slider({ const playHaptic = useHaptics() const timerRef = useRef(undefined) - const [width, setWidth] = useState(0) + const width = useSharedValue(0) const progress = useSharedValue(0) const isPressed = useSharedValue(false) @@ -90,15 +90,17 @@ export function Slider({ .onBegin(e => { isPressed.value = true - if (width > 0) { - const newProgress = Math.min(Math.max(e.x / width, 0), 1) + // FIX 2: Access width.value instead of width + if (width.value > 0) { + const newProgress = Math.min(Math.max(e.x / width.value, 0), 1) progress.value = newProgress handleValueChange(newProgress) } }) .onUpdate(e => { - if (width === 0) return - const newProgress = Math.min(Math.max(e.x / width, 0), 1) + // FIX 3: Access width.value instead of width + if (width.value === 0) return + const newProgress = Math.min(Math.max(e.x / width.value, 0), 1) progress.value = newProgress handleValueChange(newProgress) }) @@ -108,7 +110,8 @@ export function Slider({ }) const thumbAnimatedStyle = useAnimatedStyle(() => { - const translateX = progress.value * width + // FIX 4: Access width.value for calculations + const translateX = progress.value * width.value return { transform: [ {translateX: translateX - 12}, @@ -134,7 +137,10 @@ export function Slider({ setWidth(e.nativeEvent.layout.width)}> + // FIX 5: Update width.value directly on layout + onLayout={e => { + width.value = e.nativeEvent.layout.width + }}>