BlurSwitch
BlurSwitch renders a toggle switch. Its behavior differs meaningfully by platform:
- Android: uses QmBlurView’s
BlurSwitchButtonView— the track itself is genuinely blurred, and colors are auto-calculated from a single base color. - iOS: renders React Native’s built-in
Switchcomponent unmodified. There is no blur on iOS —BlurSwitchexists mainly for cross-platform API convenience, andthumbColor/trackColor.falseonly take effect there.
Basic usage
import { BlurSwitch } from '@sbaiahmed1/react-native-blur';
function BlurSwitchExample() {
const [isEnabled, setIsEnabled] = useState(false);
return (
<BlurSwitch
value={isEnabled}
onValueChange={setIsEnabled}
blurAmount={20}
trackColor={{ true: '#34C759' }}
/>
);
}
Custom colors
<BlurSwitch
value={darkMode}
onValueChange={setDarkMode}
blurAmount={15}
trackColor={{ true: '#8B5CF6' }} // purple when on
disabled={false}
/>
On Android, only set the base
trackColor.true— QmBlurView automatically derives the off-state shade from it.thumbColorandtrackColor.falseare iOS-only.
Disabled state
<BlurSwitch
value={true}
onValueChange={() => {}}
blurAmount={20}
trackColor={{ true: '#10B981' }}
disabled={true} // prevents interaction, keeps the current value
/>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| value | boolean | false | The current value of the switch. |
| onValueChange | (value: boolean) => void | undefined | Callback invoked when the switch value changes. |
| blurAmount | number | 10 | AndroidThe intensity of the blur effect (0-100). Only Android renders a blurred track. |
| blurRounds | number | 5 | AndroidNumber of blur interactions for a smoother effect (1-15). |
| thumbColor | ColorValue | '#FFFFFF' | iOSThe color of the switch thumb. |
| trackColor | { false?: ColorValue; true?: ColorValue } | { false: '#E5E5EA', true: '#34C759' } | Track colors. On Android only `true` is used — QmBlurView auto-calculates the off-state shade from it. |
| disabled | boolean | false | Disables interaction while keeping the current value. |
| style | StyleProp<ViewStyle> | undefined | Style object for the switch view. |