Something went wrong. Try again.
Bluesky app fork with some witchin' additions 💫 forked from jollywhoppers.com/witchsky.app
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192import {useEffect, useState} from 'react'import {type ViewStyle} from 'react-native'import {Slider as RNSlider} from '@miblanchard/react-native-slider'
import {changeHue, useTheme} from '#/alf'
interface SliderProps { value: number onValueChange: (value: number) => void minimumValue?: number maximumValue?: number step?: number trackStyle?: ViewStyle minimumTrackStyle?: ViewStyle thumbStyle?: ViewStyle thumbTouchSize?: {width: number; height: number} debounceFull?: boolean}
export function Slider({ value, onValueChange, minimumValue = 0, maximumValue = 1, step = 1, trackStyle, minimumTrackStyle, thumbStyle, thumbTouchSize = {width: 40, height: 40}, debounceFull,}: SliderProps) { const t = useTheme() // We need local state to handle visual updates while dragging if debounceFull is true const [localValue, setLocalValue] = useState(value)
// Sync local state if the parent updates the value prop externally useEffect(() => { setLocalValue(value) }, [value])
return ( <RNSlider value={[localValue]} // Read from local state onValueChange={values => { const nextVal = values[0] setLocalValue(nextVal)
// If NOT debouncing, update parent immediately while dragging if (!debounceFull) { onValueChange(nextVal) } }} onSlidingComplete={values => { // If debouncing, update parent only when done dragging if (debounceFull) { onValueChange(values[0]) } }} minimumValue={minimumValue} maximumValue={maximumValue} step={step} trackStyle={{ height: 4, borderRadius: 2, backgroundColor: t.atoms.bg_contrast_50.backgroundColor, ...trackStyle, }} minimumTrackStyle={{ height: 4, borderRadius: 2, backgroundColor: changeHue(t.palette.primary_500, localValue - value), ...minimumTrackStyle, }} thumbStyle={{ width: 24, height: 24, borderRadius: 12, borderWidth: 1, borderColor: t.atoms.border_contrast_low.borderColor, backgroundColor: t.atoms.bg.backgroundColor, shadowColor: '#000', shadowOffset: {width: 0, height: 2}, shadowOpacity: 0.15, shadowRadius: 4, elevation: 3, ...thumbStyle, }} thumbTouchSize={thumbTouchSize} /> )}