@sbaiahmed1/react-native-blur 4.3.1 → 4.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @sbaiahmed1/react-native-blur
2
2
 
3
- A modern React Native library providing **four specialized components** for advanced visual effects: `BlurView` for native blur effects, `LiquidGlassView` for cutting-edge liquid glass effects on iOS 26+ (with Android fallback to enhanced blur), `LiquidGlassContainer` for iOS 26+ glass container effects with configurable spacing, and `ProgressiveBlurView` for smooth, variable blur transitions.
3
+ A modern React Native library providing **five specialized components** for advanced visual effects: `BlurView` for native blur effects, `LiquidGlassView` for cutting-edge liquid glass effects on iOS 26+ (with Android fallback to enhanced blur), `LiquidGlassContainer` for iOS 26+ glass container effects with configurable spacing, `ProgressiveBlurView` for smooth, variable blur transitions, and `BlurSwitch` for beautiful blur switch buttons on Android.
4
4
 
5
5
  > **⚠️ Breaking Changes**: If upgrading from 3.x, see [Breaking Changes](#️-breaking-changes-in-v400) section.
6
6
 
@@ -133,11 +133,12 @@ import { LiquidGlassView } from '@sbaiahmed1/react-native-blur';
133
133
 
134
134
  ## Features
135
135
 
136
- - ✨ **Four Specialized Components**:
136
+ - ✨ **Five Specialized Components**:
137
137
  - `BlurView` - Dedicated blur effects component with multiple blur types
138
138
  - `ProgressiveBlurView` - Variable/gradient blur transitions (iOS & Android)
139
139
  - `LiquidGlassView` - Separate component for iOS 26+ liquid glass effects
140
140
  - `LiquidGlassContainer` - iOS 26+ glass container with configurable spacing for grouping glass elements
141
+ - `BlurSwitch` - Beautiful blur switch button using QmBlurView (Android)
141
142
  - �🌊 **Liquid Glass Effects**: Revolutionary glass effects using iOS 26+ UIGlassEffect API
142
143
  - 🎨 **Multiple Blur Types**: Support for various blur styles including system materials on iOS
143
144
  - 📱 **Cross-Platform**: Works on both iOS and Android
@@ -154,7 +155,7 @@ import { LiquidGlassView } from '@sbaiahmed1/react-native-blur';
154
155
 
155
156
  ### Key Advantages
156
157
 
157
- - **Four Specialized Components**: Separate `BlurView`, `LiquidGlassView`, `LiquidGlassContainer`, and `ProgressiveBlurView` components for clean architecture
158
+ - **Five Specialized Components**: Separate `BlurView`, `LiquidGlassView`, `LiquidGlassContainer`, `ProgressiveBlurView`, and `BlurSwitch` components for clean architecture
158
159
  - **Liquid Glass Effects**: Only library with iOS 26+ UIGlassEffect and UIGlassContainerEffect support
159
160
  - **Real Android Blur**: Hardware-accelerated blur on Android (not overlay)
160
161
  - **New Architecture**: Built for Fabric/Turbo Modules
@@ -257,7 +258,7 @@ The implementation automatically handles different Android versions:
257
258
 
258
259
  ## Usage
259
260
 
260
- The library now provides **four specialized components** for different visual effects:
261
+ The library now provides **five specialized components** for different visual effects:
261
262
 
262
263
  ### BlurView - Standard Blur Effects
263
264
 
@@ -506,9 +507,72 @@ function AnimatedGlassContainer() {
506
507
  }
507
508
  ```
508
509
 
510
+ ### BlurSwitch - Blur Switch Button (Android)
511
+
512
+ Use `BlurSwitch` for beautiful switch buttons with blur effects. On Android, this uses QmBlurView's `BlurSwitchButtonView`. On iOS, it falls back to the native `Switch` component.
513
+
514
+ > **Note**: On Android, you only need to set the base color (`trackColor.true`), and QmBlurView will automatically calculate the colors for on/off states. The `thumbColor` and `trackColor.false` props are only supported on iOS.
515
+
516
+ #### Basic Usage
517
+
518
+ ```tsx
519
+ import React, { useState } from 'react';
520
+ import { View, Text } from 'react-native';
521
+ import { BlurSwitch } from '@sbaiahmed1/react-native-blur';
522
+
523
+ function BlurSwitchExample() {
524
+ const [isEnabled, setIsEnabled] = useState(false);
525
+
526
+ return (
527
+ <View style={{ flexDirection: 'row', alignItems: 'center' }}>
528
+ <Text>Enable Feature</Text>
529
+ <BlurSwitch
530
+ value={isEnabled}
531
+ onValueChange={setIsEnabled}
532
+ blurAmount={20}
533
+ trackColor={{ true: '#34C759' }}
534
+ />
535
+ </View>
536
+ );
537
+ }
538
+ ```
539
+
540
+ #### With Custom Colors
541
+
542
+ ```tsx
543
+ import React, { useState } from 'react';
544
+ import { BlurSwitch } from '@sbaiahmed1/react-native-blur';
545
+
546
+ function CustomBlurSwitch() {
547
+ const [darkMode, setDarkMode] = useState(false);
548
+
549
+ return (
550
+ <BlurSwitch
551
+ value={darkMode}
552
+ onValueChange={setDarkMode}
553
+ blurAmount={15}
554
+ trackColor={{ true: '#8B5CF6' }} // Purple when on
555
+ disabled={false}
556
+ />
557
+ );
558
+ }
559
+ ```
560
+
561
+ #### Disabled State
562
+
563
+ ```tsx
564
+ <BlurSwitch
565
+ value={true}
566
+ onValueChange={() => {}}
567
+ blurAmount={20}
568
+ trackColor={{ true: '#10B981' }}
569
+ disabled={true} // Prevents user interaction, maintains current value
570
+ />
571
+ ```
572
+
509
573
  ## Props
510
574
 
511
- The library now provides four separate components with their own props:
575
+ The library now provides five separate components with their own props:
512
576
 
513
577
  ### BlurView Props
514
578
 
@@ -569,6 +633,20 @@ All props are optional and have sensible defaults.
569
633
  | `style` | `ViewStyle` | `undefined` | Style object for the glass container |
570
634
  | `children` | `ReactNode` | `undefined` | Child components to render inside the glass container (typically `LiquidGlassView` components) |
571
635
 
636
+ ### BlurSwitch Props
637
+
638
+ All props are optional and have sensible defaults.
639
+
640
+ | Prop | Type | Default | Description |
641
+ | -------------- | ----------------------------------------- | ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
642
+ | `value` | `boolean` | `false` | The current value of the switch |
643
+ | `onValueChange`| `(value: boolean) => void` | `undefined` | Callback invoked when the switch value changes |
644
+ | `blurAmount` | `number` | `10` | (Android only) The intensity of the blur effect (0-100) |
645
+ | `thumbColor` | `ColorValue` | `'#FFFFFF'` | (iOS only) The color of the switch thumb |
646
+ | `trackColor` | `{ false?: ColorValue; true?: ColorValue }`| `{ false: '#E5E5EA', true: '#34C759' }` | Track colors. On Android, only `true` is used - QmBlurView auto-calculates on/off colors from base color |
647
+ | `disabled` | `boolean` | `false` | Whether the switch is disabled (prevents interaction but maintains current value) |
648
+ | `style` | `ViewStyle` | `undefined` | Style object for the switch view |
649
+
572
650
  > **Note**: The `BlurType` and `GlassType` are exported types from the library. See [Blur Types](#blur-types) and [Glass Types](#glass-types) sections below for all available values.
573
651
 
574
652
  > **Platform Note**: `LiquidGlassView` automatically falls back to `BlurView` on Android and iOS versions older than iOS 26.
@@ -669,12 +747,14 @@ import {
669
747
  LiquidGlassView,
670
748
  LiquidGlassContainer,
671
749
  ProgressiveBlurView,
750
+ BlurSwitch,
672
751
  BlurType,
673
752
  GlassType,
674
753
  BlurViewProps,
675
754
  LiquidGlassViewProps,
676
755
  LiquidGlassContainerProps,
677
756
  ProgressiveBlurViewProps,
757
+ BlurSwitchProps,
678
758
  } from '@sbaiahmed1/react-native-blur';
679
759
 
680
760
  // BlurType is exported for type checking
@@ -718,6 +798,15 @@ const liquidGlassProps: LiquidGlassViewProps = {
718
798
  const liquidGlassContainerProps: LiquidGlassContainerProps = {
719
799
  spacing: 20,
720
800
  };
801
+
802
+ // Example with BlurSwitch properties
803
+ const blurSwitchProps: BlurSwitchProps = {
804
+ value: true,
805
+ onValueChange: (value) => console.log(value),
806
+ blurAmount: 20,
807
+ trackColor: { true: '#34C759' },
808
+ disabled: false,
809
+ };
721
810
  ```
722
811
 
723
812
  ## Example App
@@ -728,6 +817,7 @@ The package includes a comprehensive example app that demonstrates all component
728
817
  - **LiquidGlassView Demo**: Showcase of iOS 26+ glass effects with customizable properties
729
818
  - **LiquidGlassContainer Demo**: Interactive demonstrations of glass container spacing with animated examples
730
819
  - **ProgressiveBlurView Demo**: Variable blur gradient examples for different use cases
820
+ - **BlurSwitch Demo**: Blur switch buttons with various color configurations
731
821
  - **Practical Use Cases**: Real-world examples like cards, modals, and overlays using all components
732
822
  - **Comparison Views**: Side-by-side comparisons between different effect types
733
823
  - **Platform Fallbacks**: Visual demonstrations of how effects degrade gracefully on older platforms
@@ -798,7 +888,7 @@ yarn android
798
888
 
799
889
  ### 🎯 Component Separation (BREAKING CHANGE)
800
890
 
801
- - **Four Specialized Components**: Split single `BlurView` into dedicated `BlurView`, `LiquidGlassView`, `LiquidGlassContainer`, and `ProgressiveBlurView` components
891
+ - **Five Specialized Components**: Split single `BlurView` into dedicated `BlurView`, `LiquidGlassView`, `LiquidGlassContainer`, `ProgressiveBlurView`, and `BlurSwitch` components
802
892
  - **Removed `type` prop**: No more switching between blur/liquidGlass modes - use the appropriate component instead
803
893
  - **Cleaner APIs**: Each component has focused props without mixing blur and glass properties
804
894
  - **Better Architecture**: True separation of concerns following React best practices
@@ -830,7 +920,7 @@ yarn android
830
920
 
831
921
  ### 🛠️ Developer Experience
832
922
 
833
- - Full TypeScript support with separate prop types for each component (`BlurViewProps`, `LiquidGlassViewProps`, `LiquidGlassContainerProps`, `ProgressiveBlurViewProps`)
923
+ - Full TypeScript support with separate prop types for each component (`BlurViewProps`, `LiquidGlassViewProps`, `LiquidGlassContainerProps`, `ProgressiveBlurViewProps`, `BlurSwitchProps`)
834
924
  - Cleaner, more intuitive API design
835
925
  - Improved component layout handling
836
926
  - Better accessibility support with smart fallbacks
@@ -74,7 +74,7 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
74
74
  dependencies {
75
75
  implementation "com.facebook.react:react-android"
76
76
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
77
- implementation 'com.qmdeve.blurview:core:1.0.6'
77
+ implementation 'com.qmdeve.blurview:core:1.1.1'
78
78
  }
79
79
 
80
80
  react {
@@ -11,6 +11,7 @@ class ReactNativeBlurViewPackage : ReactPackage {
11
11
  val viewManagers: MutableList<ViewManager<*, *>> = ArrayList()
12
12
  viewManagers.add(ReactNativeBlurViewManager())
13
13
  viewManagers.add(ReactNativeProgressiveBlurViewManager())
14
+ viewManagers.add(ReactNativeBlurSwitchManager())
14
15
  return viewManagers
15
16
  }
16
17
 
@@ -0,0 +1,218 @@
1
+ package com.sbaiahmed1.reactnativeblur
2
+
3
+ import android.content.Context
4
+ import android.util.AttributeSet
5
+ import android.util.Log
6
+ import android.util.TypedValue
7
+ import android.view.MotionEvent
8
+ import com.qmdeve.blurview.widget.BlurSwitchButtonView
9
+
10
+ /**
11
+ * Android implementation of React Native BlurSwitch component.
12
+ * Provides a blur switch button using the QmBlurView library.
13
+ *
14
+ * QmBlurView is a high-performance blur library that uses native blur algorithms
15
+ * implemented with underlying Native calls for optimal performance.
16
+ *
17
+ * Note: You only need to set the base color (trackColorOn), and QmBlurView will
18
+ * automatically calculate the colors for on and off states. The thumbColor and
19
+ * trackColorOff props are not supported by this component.
20
+ */
21
+ class ReactNativeBlurSwitch : BlurSwitchButtonView {
22
+ private var onValueChangeListener: ((Boolean) -> Unit)? = null
23
+ private var currentValue = false
24
+ private var isDisabled = false
25
+
26
+ companion object {
27
+ private const val TAG = "ReactNativeBlurSwitch"
28
+ private const val DEFAULT_WIDTH_DP = 65f
29
+ private const val DEFAULT_HEIGHT_DP = 36f
30
+ private const val MIN_BLUR_AMOUNT = 0f
31
+ private const val MAX_BLUR_AMOUNT = 100f
32
+ private const val MAX_BLUR_RADIUS = 25f
33
+ private const val DEBUG = false
34
+
35
+ private fun logDebug(message: String) {
36
+ if (DEBUG) {
37
+ Log.d(TAG, message)
38
+ }
39
+ }
40
+
41
+ private fun logWarning(message: String) {
42
+ Log.w(TAG, message)
43
+ }
44
+
45
+ private fun logError(message: String, throwable: Throwable? = null) {
46
+ Log.e(TAG, message, throwable)
47
+ }
48
+
49
+ /**
50
+ * Maps blur amount (0-100) to blur radius (0-25).
51
+ * @param amount The blur amount from 0-100
52
+ * @return The corresponding blur radius from 0-25
53
+ */
54
+ private fun mapBlurAmountToRadius(amount: Float): Float {
55
+ val clampedAmount = amount.coerceIn(MIN_BLUR_AMOUNT, MAX_BLUR_AMOUNT)
56
+ return (clampedAmount / MAX_BLUR_AMOUNT) * MAX_BLUR_RADIUS
57
+ }
58
+ }
59
+
60
+ constructor(context: Context?) : super(context, null) {
61
+ initializeSwitch()
62
+ }
63
+
64
+ constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) {
65
+ initializeSwitch()
66
+ }
67
+
68
+ /**
69
+ * Initialize the blur switch with default settings.
70
+ */
71
+ private fun initializeSwitch() {
72
+ try {
73
+ setOnCheckedChangeListener { isChecked ->
74
+ if (isDisabled) {
75
+ setChecked(currentValue, false)
76
+ return@setOnCheckedChangeListener
77
+ }
78
+ if (currentValue != isChecked) {
79
+ currentValue = isChecked
80
+ onValueChangeListener?.invoke(isChecked)
81
+ logDebug("Value changed: $isChecked")
82
+ }
83
+ }
84
+ logDebug("BlurSwitch initialized")
85
+ } catch (e: Exception) {
86
+ logError("Failed to initialize switch: ${e.message}", e)
87
+ }
88
+ }
89
+
90
+ /**
91
+ * Called when the view is detached from a window.
92
+ * Performs cleanup to prevent memory leaks.
93
+ */
94
+ override fun onDetachedFromWindow() {
95
+ super.onDetachedFromWindow()
96
+ cleanup()
97
+ }
98
+
99
+ /**
100
+ * Cleanup method to reset state.
101
+ * Helps prevent memory leaks and ensures clean state.
102
+ */
103
+ fun cleanup() {
104
+ setOnCheckedChangeListener(null)
105
+ onValueChangeListener = null
106
+ logDebug("View cleaned up")
107
+ }
108
+
109
+ /**
110
+ * Set the switch value.
111
+ * @param value The boolean value (true = on, false = off)
112
+ */
113
+ fun setValue(value: Boolean) {
114
+ if (currentValue != value) {
115
+ currentValue = value
116
+ setChecked(value, false)
117
+ logDebug("setValue: $value")
118
+ }
119
+ }
120
+
121
+ /**
122
+ * Set the value change listener.
123
+ * @param listener The callback to invoke when value changes
124
+ */
125
+ fun setOnValueChangeListener(listener: ((Boolean) -> Unit)?) {
126
+ onValueChangeListener = listener
127
+ }
128
+
129
+ /**
130
+ * Set the thumb color.
131
+ * @param color The color int for the thumb
132
+ */
133
+ fun setThumbColor(color: Int) {
134
+ logDebug("setThumbColor: $color (not supported by BlurSwitchButtonView)")
135
+ }
136
+
137
+ /**
138
+ * Set the track color when switch is off.
139
+ * @param color The color int for the off state track
140
+ */
141
+ fun setTrackColorOff(color: Int) {
142
+ logDebug("setTrackColorOff: $color (not supported by BlurSwitchButtonView)")
143
+ }
144
+
145
+ /**
146
+ * Set the track color when switch is on.
147
+ * @param color The color int for the on state track
148
+ */
149
+ fun setTrackColorOn(color: Int) {
150
+ try {
151
+ setBaseColor(color)
152
+ logDebug("setTrackColorOn: $color")
153
+ } catch (e: Exception) {
154
+ logError("Failed to set track color: ${e.message}", e)
155
+ }
156
+ }
157
+
158
+ /**
159
+ * Set the blur amount with cross-platform mapping.
160
+ * @param amount The blur amount value (0-100)
161
+ */
162
+ fun setBlurAmount(amount: Float) {
163
+ val radius = mapBlurAmountToRadius(amount)
164
+ logDebug("setBlurAmount: $amount -> $radius")
165
+
166
+ try {
167
+ setBlurRadius(radius)
168
+ } catch (e: Exception) {
169
+ logError("Failed to set blur radius: ${e.message}", e)
170
+ }
171
+ }
172
+
173
+ /**
174
+ * Set whether the switch is disabled.
175
+ * @param disabled True to disable, false to enable
176
+ */
177
+ fun setDisabled(disabled: Boolean) {
178
+ isDisabled = disabled
179
+ isEnabled = !disabled
180
+ isClickable = !disabled
181
+ alpha = if (disabled) 0.5f else 1f
182
+ logDebug("setDisabled: $disabled")
183
+ }
184
+
185
+ override fun onTouchEvent(event: MotionEvent?): Boolean {
186
+ if (isDisabled) {
187
+ return false
188
+ }
189
+ return super.onTouchEvent(event)
190
+ }
191
+
192
+ override fun dispatchTouchEvent(event: MotionEvent?): Boolean {
193
+ if (isDisabled) {
194
+ return false
195
+ }
196
+ return super.dispatchTouchEvent(event)
197
+ }
198
+
199
+ override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
200
+ val defaultWidth = TypedValue.applyDimension(
201
+ TypedValue.COMPLEX_UNIT_DIP,
202
+ DEFAULT_WIDTH_DP,
203
+ context.resources.displayMetrics
204
+ ).toInt()
205
+
206
+ val defaultHeight = TypedValue.applyDimension(
207
+ TypedValue.COMPLEX_UNIT_DIP,
208
+ DEFAULT_HEIGHT_DP,
209
+ context.resources.displayMetrics
210
+ ).toInt()
211
+
212
+ val width = resolveSize(defaultWidth, widthMeasureSpec)
213
+ val height = resolveSize(defaultHeight, heightMeasureSpec)
214
+
215
+ setMeasuredDimension(width, height)
216
+ }
217
+ }
218
+
@@ -0,0 +1,100 @@
1
+ package com.sbaiahmed1.reactnativeblur
2
+
3
+ import android.graphics.Color
4
+ import com.facebook.react.bridge.Arguments
5
+ import com.facebook.react.common.MapBuilder
6
+ import com.facebook.react.module.annotations.ReactModule
7
+ import com.facebook.react.uimanager.SimpleViewManager
8
+ import com.facebook.react.uimanager.ThemedReactContext
9
+ import com.facebook.react.uimanager.annotations.ReactProp
10
+ import com.facebook.react.uimanager.events.RCTEventEmitter
11
+ import androidx.core.graphics.toColorInt
12
+
13
+ @ReactModule(name = ReactNativeBlurSwitchManager.NAME)
14
+ class ReactNativeBlurSwitchManager : SimpleViewManager<ReactNativeBlurSwitch>() {
15
+
16
+ override fun getName(): String {
17
+ return NAME
18
+ }
19
+
20
+ public override fun createViewInstance(context: ThemedReactContext): ReactNativeBlurSwitch {
21
+ val view = ReactNativeBlurSwitch(context)
22
+
23
+ view.setOnValueChangeListener { value ->
24
+ context.getJSModule(RCTEventEmitter::class.java)
25
+ .receiveEvent(view.id, "topValueChange", Arguments.createMap().apply {
26
+ putBoolean("value", value)
27
+ })
28
+ }
29
+
30
+ return view
31
+ }
32
+
33
+ @ReactProp(name = "value")
34
+ fun setValue(view: ReactNativeBlurSwitch?, value: Boolean) {
35
+ view?.setValue(value)
36
+ }
37
+
38
+ @ReactProp(name = "blurAmount", defaultDouble = 10.0)
39
+ fun setBlurAmount(view: ReactNativeBlurSwitch?, blurAmount: Double) {
40
+ view?.setBlurAmount(blurAmount.toFloat())
41
+ }
42
+
43
+ @ReactProp(name = "thumbColor")
44
+ fun setThumbColor(view: ReactNativeBlurSwitch?, color: String?) {
45
+ color?.let {
46
+ try {
47
+ view?.setThumbColor(it.toColorInt())
48
+ } catch (e: Exception) {
49
+ android.util.Log.w("ReactNativeBlurSwitchManager", "Invalid thumbColor: $color", e)
50
+ }
51
+ }
52
+ }
53
+
54
+ @ReactProp(name = "trackColorOff")
55
+ fun setTrackColorOff(view: ReactNativeBlurSwitch?, color: String?) {
56
+ color?.let {
57
+ try {
58
+ view?.setTrackColorOff(it.toColorInt())
59
+ } catch (e: Exception) {
60
+ android.util.Log.w("ReactNativeBlurSwitchManager", "Invalid trackColorOff: $color", e)
61
+ }
62
+ }
63
+ }
64
+
65
+ @ReactProp(name = "trackColorOn")
66
+ fun setTrackColorOn(view: ReactNativeBlurSwitch?, color: String?) {
67
+ color?.let {
68
+ try {
69
+ view?.setTrackColorOn(it.toColorInt())
70
+ } catch (e: Exception) {
71
+ android.util.Log.w("ReactNativeBlurSwitchManager", "Invalid trackColorOn: $color", e)
72
+ }
73
+ }
74
+ }
75
+
76
+ @ReactProp(name = "disabled")
77
+ fun setDisabled(view: ReactNativeBlurSwitch?, disabled: Boolean) {
78
+ view?.setDisabled(disabled)
79
+ }
80
+
81
+ /**
82
+ * Called when view is detached from view hierarchy and allows for cleanup.
83
+ */
84
+ override fun onDropViewInstance(view: ReactNativeBlurSwitch) {
85
+ super.onDropViewInstance(view)
86
+ // Call cleanup to reset state and prevent white screen artifacts
87
+ view.cleanup()
88
+ }
89
+
90
+ override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any> {
91
+ return MapBuilder.builder<String, Any>()
92
+ .put("topValueChange", MapBuilder.of("registrationName", "onValueChange"))
93
+ .build()
94
+ }
95
+
96
+ companion object {
97
+ const val NAME = "ReactNativeBlurSwitch"
98
+ }
99
+ }
100
+
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+
3
+ import React from 'react';
4
+ import { Platform, Switch } from 'react-native';
5
+ import ReactNativeBlurSwitch from './ReactNativeBlurSwitchNativeComponent';
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ const toColorString = (color, fallback) => {
8
+ if (typeof color === 'string') return color;
9
+ return fallback;
10
+ };
11
+ /**
12
+ * A cross-platform blur switch component.
13
+ *
14
+ * On iOS, this uses the native Switch component.
15
+ * On Android, this uses QmBlurView's BlurSwitchButtonView for blur effects.
16
+ *
17
+ * Note: On Android, you only need to set the base color (`trackColor.true`),
18
+ * and QmBlurView will automatically calculate the colors for on/off states.
19
+ * The `thumbColor` and `trackColor.false` props are only supported on iOS.
20
+ *
21
+ * @example
22
+ * ```tsx
23
+ * <BlurSwitch
24
+ * value={isEnabled}
25
+ * onValueChange={setIsEnabled}
26
+ * blurAmount={20}
27
+ * trackColor={{ true: '#34C759' }}
28
+ * />
29
+ * ```
30
+ */
31
+ export const BlurSwitch = ({
32
+ value = false,
33
+ onValueChange,
34
+ blurAmount = 10,
35
+ thumbColor = '#FFFFFF',
36
+ trackColor = {
37
+ false: '#E5E5EA',
38
+ true: '#34C759'
39
+ },
40
+ disabled = false,
41
+ style,
42
+ ...props
43
+ }) => {
44
+ if (Platform.OS === 'ios') {
45
+ return /*#__PURE__*/_jsx(Switch, {
46
+ value: value,
47
+ onValueChange: onValueChange,
48
+ thumbColor: thumbColor,
49
+ trackColor: trackColor,
50
+ disabled: disabled,
51
+ style: style,
52
+ ...props
53
+ });
54
+ }
55
+ return /*#__PURE__*/_jsx(ReactNativeBlurSwitch, {
56
+ style: [{
57
+ width: 65,
58
+ height: 36
59
+ }, style],
60
+ value: value,
61
+ onValueChange: event => {
62
+ onValueChange?.(event.nativeEvent.value);
63
+ },
64
+ blurAmount: blurAmount,
65
+ thumbColor: toColorString(thumbColor, '#FFFFFF'),
66
+ trackColorOff: toColorString(trackColor?.false, '#E5E5EA'),
67
+ trackColorOn: toColorString(trackColor?.true, '#34C759'),
68
+ disabled: disabled,
69
+ ...props
70
+ });
71
+ };
72
+ export default BlurSwitch;
73
+ //# sourceMappingURL=BlurSwitch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","Platform","Switch","ReactNativeBlurSwitch","jsx","_jsx","toColorString","color","fallback","BlurSwitch","value","onValueChange","blurAmount","thumbColor","trackColor","false","true","disabled","style","props","OS","width","height","event","nativeEvent","trackColorOff","trackColorOn"],"sourceRoot":"../../src","sources":["BlurSwitch.tsx"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SAASC,QAAQ,EAAEC,MAAM,QAAQ,cAAc;AAE/C,OAAOC,qBAAqB,MAAM,wCAAwC;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAE3E,MAAMC,aAAa,GAAGA,CACpBC,KAA6B,EAC7BC,QAAgB,KACL;EACX,IAAI,OAAOD,KAAK,KAAK,QAAQ,EAAE,OAAOA,KAAK;EAC3C,OAAOC,QAAQ;AACjB,CAAC;AA8DD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAqC,GAAGA,CAAC;EACpDC,KAAK,GAAG,KAAK;EACbC,aAAa;EACbC,UAAU,GAAG,EAAE;EACfC,UAAU,GAAG,SAAS;EACtBC,UAAU,GAAG;IAAEC,KAAK,EAAE,SAAS;IAAEC,IAAI,EAAE;EAAU,CAAC;EAClDC,QAAQ,GAAG,KAAK;EAChBC,KAAK;EACL,GAAGC;AACL,CAAC,KAAK;EACJ,IAAIlB,QAAQ,CAACmB,EAAE,KAAK,KAAK,EAAE;IACzB,oBACEf,IAAA,CAACH,MAAM;MACLQ,KAAK,EAAEA,KAAM;MACbC,aAAa,EAAEA,aAAc;MAC7BE,UAAU,EAAEA,UAAW;MACvBC,UAAU,EAAEA,UAAW;MACvBG,QAAQ,EAAEA,QAAS;MACnBC,KAAK,EAAEA,KAAM;MAAA,GACTC;IAAK,CACV,CAAC;EAEN;EAEA,oBACEd,IAAA,CAACF,qBAAqB;IACpBe,KAAK,EAAE,CAAC;MAAEG,KAAK,EAAE,EAAE;MAAEC,MAAM,EAAE;IAAG,CAAC,EAAEJ,KAAK,CAAE;IAC1CR,KAAK,EAAEA,KAAM;IACbC,aAAa,EAAGY,KAAK,IAAK;MACxBZ,aAAa,GAAGY,KAAK,CAACC,WAAW,CAACd,KAAK,CAAC;IAC1C,CAAE;IACFE,UAAU,EAAEA,UAAW;IACvBC,UAAU,EAAEP,aAAa,CAACO,UAAU,EAAE,SAAS,CAAE;IACjDY,aAAa,EAAEnB,aAAa,CAACQ,UAAU,EAAEC,KAAK,EAAE,SAAS,CAAE;IAC3DW,YAAY,EAAEpB,aAAa,CAACQ,UAAU,EAAEE,IAAI,EAAE,SAAS,CAAE;IACzDC,QAAQ,EAAEA,QAAS;IAAA,GACfE;EAAK,CACV,CAAC;AAEN,CAAC;AAED,eAAeV,UAAU","ignoreList":[]}
@@ -0,0 +1,62 @@
1
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
2
+ import type { ViewProps } from 'react-native';
3
+ import type {
4
+ WithDefault,
5
+ Double,
6
+ DirectEventHandler,
7
+ } from 'react-native/Libraries/Types/CodegenTypes';
8
+
9
+ export interface ValueChangeEvent {
10
+ value: boolean;
11
+ }
12
+
13
+ interface NativeProps extends ViewProps {
14
+ /**
15
+ * The current value of the switch
16
+ * @default false
17
+ */
18
+ value?: WithDefault<boolean, false>;
19
+
20
+ /**
21
+ * The intensity of the blur effect (0-100)
22
+ * @default 10.0
23
+ */
24
+ blurAmount?: WithDefault<Double, 10.0>;
25
+
26
+ /**
27
+ * The color of the switch thumb
28
+ * Note: Not supported by the Android implementation (no-op).
29
+ * Use the native iOS Switch for platform-specific thumb colors.
30
+ * @default '#FFFFFF'
31
+ */
32
+ thumbColor?: WithDefault<string, '#FFFFFF'>;
33
+
34
+ /**
35
+ * The track color when switch is off
36
+ * Note: Not supported by the Android implementation (no-op).
37
+ * Use the native iOS Switch for platform-specific off-state colors.
38
+ * @default '#E5E5EA'
39
+ */
40
+ trackColorOff?: WithDefault<string, '#E5E5EA'>;
41
+
42
+ /**
43
+ * The track color when switch is on
44
+ * @default '#34C759'
45
+ */
46
+ trackColorOn?: WithDefault<string, '#34C759'>;
47
+
48
+ /**
49
+ * Whether the switch is disabled
50
+ * @default false
51
+ */
52
+ disabled?: WithDefault<boolean, false>;
53
+
54
+ /**
55
+ * Callback invoked when the switch value changes
56
+ */
57
+ onValueChange?: DirectEventHandler<Readonly<ValueChangeEvent>>;
58
+ }
59
+
60
+ export default codegenNativeComponent<NativeProps>('ReactNativeBlurSwitch', {
61
+ excludedPlatforms: ['iOS'],
62
+ });
@@ -9,4 +9,6 @@ export { default as ReactNativeProgressiveBlurView } from './ReactNativeProgress
9
9
  export { ProgressiveBlurView } from "./ProgressiveBlurView.js";
10
10
  export { default as ReactNativeLiquidGlassContainer } from './ReactNativeLiquidGlassContainerNativeComponent';
11
11
  export { LiquidGlassContainer } from "./LiquidGlassContainer.js";
12
+ export { default as ReactNativeBlurSwitch } from './ReactNativeBlurSwitchNativeComponent';
13
+ export { BlurSwitch } from "./BlurSwitch.js";
12
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["default","ReactNativeBlurView","BlurView","ReactNativeLiquidGlassView","LiquidGlassView","ReactNativeProgressiveBlurView","ProgressiveBlurView","ReactNativeLiquidGlassContainer","LiquidGlassContainer"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,OAAO,IAAIC,mBAAmB,QAAQ,sCAAsC;AACrF,cAAc,sCAAsC;AAEpD,SAASC,QAAQ,IAAIF,OAAO,EAAEE,QAAQ,QAAQ,eAAY;AAG1D,SAASF,OAAO,IAAIG,0BAA0B,QAAQ,6CAA6C;AAGnG,SAASC,eAAe,QAAQ,sBAAmB;AAGnD,SAASJ,OAAO,IAAIK,8BAA8B,QAAQ,iDAAiD;AAG3G,SAASC,mBAAmB,QAAQ,0BAAuB;AAG3D,SAASN,OAAO,IAAIO,+BAA+B,QAAQ,kDAAkD;AAE7G,SAASC,oBAAoB,QAAQ,2BAAwB","ignoreList":[]}
1
+ {"version":3,"names":["default","ReactNativeBlurView","BlurView","ReactNativeLiquidGlassView","LiquidGlassView","ReactNativeProgressiveBlurView","ProgressiveBlurView","ReactNativeLiquidGlassContainer","LiquidGlassContainer","ReactNativeBlurSwitch","BlurSwitch"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,SAASA,OAAO,IAAIC,mBAAmB,QAAQ,sCAAsC;AACrF,cAAc,sCAAsC;AAEpD,SAASC,QAAQ,IAAIF,OAAO,EAAEE,QAAQ,QAAQ,eAAY;AAG1D,SAASF,OAAO,IAAIG,0BAA0B,QAAQ,6CAA6C;AAGnG,SAASC,eAAe,QAAQ,sBAAmB;AAGnD,SAASJ,OAAO,IAAIK,8BAA8B,QAAQ,iDAAiD;AAG3G,SAASC,mBAAmB,QAAQ,0BAAuB;AAG3D,SAASN,OAAO,IAAIO,+BAA+B,QAAQ,kDAAkD;AAE7G,SAASC,oBAAoB,QAAQ,2BAAwB;AAG7D,SAASR,OAAO,IAAIS,qBAAqB,QAAQ,wCAAwC;AAGzF,SAASC,UAAU,QAAQ,iBAAc","ignoreList":[]}
@@ -0,0 +1,78 @@
1
+ import React from 'react';
2
+ import type { ViewStyle, StyleProp, ColorValue } from 'react-native';
3
+ export interface BlurSwitchProps {
4
+ /**
5
+ * @description The current value of the switch
6
+ *
7
+ * @default false
8
+ */
9
+ value?: boolean;
10
+ /**
11
+ * @description Callback invoked when the switch value changes
12
+ *
13
+ * @default undefined
14
+ */
15
+ onValueChange?: (value: boolean) => void;
16
+ /**
17
+ * @description The intensity of the blur effect (0-100)
18
+ *
19
+ * @platform android
20
+ * @default 10
21
+ */
22
+ blurAmount?: number;
23
+ /**
24
+ * @description The color of the switch thumb
25
+ *
26
+ * @platform ios
27
+ * @default '#FFFFFF'
28
+ */
29
+ thumbColor?: ColorValue;
30
+ /**
31
+ * @description The track colors for off and on states
32
+ *
33
+ * Note: On Android, you only need to set the `true` (base) color.
34
+ * QmBlurView will automatically calculate the on/off state colors.
35
+ * The `false` color is only used on iOS.
36
+ *
37
+ * @default { false: '#E5E5EA', true: '#34C759' }
38
+ */
39
+ trackColor?: {
40
+ false?: ColorValue;
41
+ true?: ColorValue;
42
+ };
43
+ /**
44
+ * @description Whether the switch is disabled
45
+ *
46
+ * @default false
47
+ */
48
+ disabled?: boolean;
49
+ /**
50
+ * @description Style object for the switch view
51
+ *
52
+ * @default undefined
53
+ */
54
+ style?: StyleProp<ViewStyle>;
55
+ }
56
+ /**
57
+ * A cross-platform blur switch component.
58
+ *
59
+ * On iOS, this uses the native Switch component.
60
+ * On Android, this uses QmBlurView's BlurSwitchButtonView for blur effects.
61
+ *
62
+ * Note: On Android, you only need to set the base color (`trackColor.true`),
63
+ * and QmBlurView will automatically calculate the colors for on/off states.
64
+ * The `thumbColor` and `trackColor.false` props are only supported on iOS.
65
+ *
66
+ * @example
67
+ * ```tsx
68
+ * <BlurSwitch
69
+ * value={isEnabled}
70
+ * onValueChange={setIsEnabled}
71
+ * blurAmount={20}
72
+ * trackColor={{ true: '#34C759' }}
73
+ * />
74
+ * ```
75
+ */
76
+ export declare const BlurSwitch: React.FC<BlurSwitchProps>;
77
+ export default BlurSwitch;
78
+ //# sourceMappingURL=BlurSwitch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BlurSwitch.d.ts","sourceRoot":"","sources":["../../../src/BlurSwitch.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAWrE,MAAM,WAAW,eAAe;IAC9B;;;;OAIG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;IAEhB;;;;OAIG;IACH,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IAEzC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;OAKG;IACH,UAAU,CAAC,EAAE,UAAU,CAAC;IAExB;;;;;;;;OAQG;IACH,UAAU,CAAC,EAAE;QACX,KAAK,CAAC,EAAE,UAAU,CAAC;QACnB,IAAI,CAAC,EAAE,UAAU,CAAC;KACnB,CAAC;IAEF;;;;OAIG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IAEnB;;;;OAIG;IACH,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC9B;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAuChD,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -0,0 +1,48 @@
1
+ import type { ViewProps } from 'react-native';
2
+ import type { WithDefault, Double, DirectEventHandler } from 'react-native/Libraries/Types/CodegenTypes';
3
+ export interface ValueChangeEvent {
4
+ value: boolean;
5
+ }
6
+ interface NativeProps extends ViewProps {
7
+ /**
8
+ * The current value of the switch
9
+ * @default false
10
+ */
11
+ value?: WithDefault<boolean, false>;
12
+ /**
13
+ * The intensity of the blur effect (0-100)
14
+ * @default 10.0
15
+ */
16
+ blurAmount?: WithDefault<Double, 10.0>;
17
+ /**
18
+ * The color of the switch thumb
19
+ * Note: Not supported by the Android implementation (no-op).
20
+ * Use the native iOS Switch for platform-specific thumb colors.
21
+ * @default '#FFFFFF'
22
+ */
23
+ thumbColor?: WithDefault<string, '#FFFFFF'>;
24
+ /**
25
+ * The track color when switch is off
26
+ * Note: Not supported by the Android implementation (no-op).
27
+ * Use the native iOS Switch for platform-specific off-state colors.
28
+ * @default '#E5E5EA'
29
+ */
30
+ trackColorOff?: WithDefault<string, '#E5E5EA'>;
31
+ /**
32
+ * The track color when switch is on
33
+ * @default '#34C759'
34
+ */
35
+ trackColorOn?: WithDefault<string, '#34C759'>;
36
+ /**
37
+ * Whether the switch is disabled
38
+ * @default false
39
+ */
40
+ disabled?: WithDefault<boolean, false>;
41
+ /**
42
+ * Callback invoked when the switch value changes
43
+ */
44
+ onValueChange?: DirectEventHandler<Readonly<ValueChangeEvent>>;
45
+ }
46
+ declare const _default: import("react-native/Libraries/Utilities/codegenNativeComponent").NativeComponentType<NativeProps>;
47
+ export default _default;
48
+ //# sourceMappingURL=ReactNativeBlurSwitchNativeComponent.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ReactNativeBlurSwitchNativeComponent.d.ts","sourceRoot":"","sources":["../../../src/ReactNativeBlurSwitchNativeComponent.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAC9C,OAAO,KAAK,EACV,WAAW,EACX,MAAM,EACN,kBAAkB,EACnB,MAAM,2CAA2C,CAAC;AAEnD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,OAAO,CAAC;CAChB;AAED,UAAU,WAAY,SAAQ,SAAS;IACrC;;;OAGG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAEpC;;;OAGG;IACH,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAEvC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAE5C;;;;;OAKG;IACH,aAAa,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAE/C;;;OAGG;IACH,YAAY,CAAC,EAAE,WAAW,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAE9C;;;OAGG;IACH,QAAQ,CAAC,EAAE,WAAW,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IAEvC;;OAEG;IACH,aAAa,CAAC,EAAE,kBAAkB,CAAC,QAAQ,CAAC,gBAAgB,CAAC,CAAC,CAAC;CAChE;;AAED,wBAEG"}
@@ -13,4 +13,8 @@ export type { ProgressiveBlurViewProps } from './ProgressiveBlurView';
13
13
  export { default as ReactNativeLiquidGlassContainer } from './ReactNativeLiquidGlassContainerNativeComponent';
14
14
  export { LiquidGlassContainer } from './LiquidGlassContainer';
15
15
  export type { LiquidGlassContainerProps } from './LiquidGlassContainer';
16
+ export { default as ReactNativeBlurSwitch } from './ReactNativeBlurSwitchNativeComponent';
17
+ export type { ValueChangeEvent } from './ReactNativeBlurSwitchNativeComponent';
18
+ export { BlurSwitch } from './BlurSwitch';
19
+ export type { BlurSwitchProps } from './BlurSwitch';
16
20
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AACtF,cAAc,sCAAsC,CAAC;AAErD,OAAO,EAAE,QAAQ,IAAI,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3D,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,MAAM,6CAA6C,CAAC;AACpG,YAAY,EAAE,SAAS,EAAE,MAAM,6CAA6C,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAE9D,OAAO,EAAE,OAAO,IAAI,8BAA8B,EAAE,MAAM,iDAAiD,CAAC;AAC5G,YAAY,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAC;AAEhG,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,YAAY,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,EAAE,OAAO,IAAI,+BAA+B,EAAE,MAAM,kDAAkD,CAAC;AAE9G,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AACtF,cAAc,sCAAsC,CAAC;AAErD,OAAO,EAAE,QAAQ,IAAI,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAC3D,YAAY,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEhD,OAAO,EAAE,OAAO,IAAI,0BAA0B,EAAE,MAAM,6CAA6C,CAAC;AACpG,YAAY,EAAE,SAAS,EAAE,MAAM,6CAA6C,CAAC;AAE7E,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,YAAY,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAE9D,OAAO,EAAE,OAAO,IAAI,8BAA8B,EAAE,MAAM,iDAAiD,CAAC;AAC5G,YAAY,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAC;AAEhG,OAAO,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AAC5D,YAAY,EAAE,wBAAwB,EAAE,MAAM,uBAAuB,CAAC;AAEtE,OAAO,EAAE,OAAO,IAAI,+BAA+B,EAAE,MAAM,kDAAkD,CAAC;AAE9G,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,YAAY,EAAE,yBAAyB,EAAE,MAAM,wBAAwB,CAAC;AAExE,OAAO,EAAE,OAAO,IAAI,qBAAqB,EAAE,MAAM,wCAAwC,CAAC;AAC1F,YAAY,EAAE,gBAAgB,EAAE,MAAM,wCAAwC,CAAC;AAE/E,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sbaiahmed1/react-native-blur",
3
- "version": "4.3.1",
3
+ "version": "4.4.1",
4
4
  "description": "React native modern blur view",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",
@@ -0,0 +1,135 @@
1
+ import React from 'react';
2
+ import { Platform, Switch } from 'react-native';
3
+ import type { ViewStyle, StyleProp, ColorValue } from 'react-native';
4
+ import ReactNativeBlurSwitch from './ReactNativeBlurSwitchNativeComponent';
5
+
6
+ const toColorString = (
7
+ color: ColorValue | undefined,
8
+ fallback: string
9
+ ): string => {
10
+ if (typeof color === 'string') return color;
11
+ return fallback;
12
+ };
13
+
14
+ export interface BlurSwitchProps {
15
+ /**
16
+ * @description The current value of the switch
17
+ *
18
+ * @default false
19
+ */
20
+ value?: boolean;
21
+
22
+ /**
23
+ * @description Callback invoked when the switch value changes
24
+ *
25
+ * @default undefined
26
+ */
27
+ onValueChange?: (value: boolean) => void;
28
+
29
+ /**
30
+ * @description The intensity of the blur effect (0-100)
31
+ *
32
+ * @platform android
33
+ * @default 10
34
+ */
35
+ blurAmount?: number;
36
+
37
+ /**
38
+ * @description The color of the switch thumb
39
+ *
40
+ * @platform ios
41
+ * @default '#FFFFFF'
42
+ */
43
+ thumbColor?: ColorValue;
44
+
45
+ /**
46
+ * @description The track colors for off and on states
47
+ *
48
+ * Note: On Android, you only need to set the `true` (base) color.
49
+ * QmBlurView will automatically calculate the on/off state colors.
50
+ * The `false` color is only used on iOS.
51
+ *
52
+ * @default { false: '#E5E5EA', true: '#34C759' }
53
+ */
54
+ trackColor?: {
55
+ false?: ColorValue;
56
+ true?: ColorValue;
57
+ };
58
+
59
+ /**
60
+ * @description Whether the switch is disabled
61
+ *
62
+ * @default false
63
+ */
64
+ disabled?: boolean;
65
+
66
+ /**
67
+ * @description Style object for the switch view
68
+ *
69
+ * @default undefined
70
+ */
71
+ style?: StyleProp<ViewStyle>;
72
+ }
73
+
74
+ /**
75
+ * A cross-platform blur switch component.
76
+ *
77
+ * On iOS, this uses the native Switch component.
78
+ * On Android, this uses QmBlurView's BlurSwitchButtonView for blur effects.
79
+ *
80
+ * Note: On Android, you only need to set the base color (`trackColor.true`),
81
+ * and QmBlurView will automatically calculate the colors for on/off states.
82
+ * The `thumbColor` and `trackColor.false` props are only supported on iOS.
83
+ *
84
+ * @example
85
+ * ```tsx
86
+ * <BlurSwitch
87
+ * value={isEnabled}
88
+ * onValueChange={setIsEnabled}
89
+ * blurAmount={20}
90
+ * trackColor={{ true: '#34C759' }}
91
+ * />
92
+ * ```
93
+ */
94
+ export const BlurSwitch: React.FC<BlurSwitchProps> = ({
95
+ value = false,
96
+ onValueChange,
97
+ blurAmount = 10,
98
+ thumbColor = '#FFFFFF',
99
+ trackColor = { false: '#E5E5EA', true: '#34C759' },
100
+ disabled = false,
101
+ style,
102
+ ...props
103
+ }) => {
104
+ if (Platform.OS === 'ios') {
105
+ return (
106
+ <Switch
107
+ value={value}
108
+ onValueChange={onValueChange}
109
+ thumbColor={thumbColor}
110
+ trackColor={trackColor}
111
+ disabled={disabled}
112
+ style={style}
113
+ {...props}
114
+ />
115
+ );
116
+ }
117
+
118
+ return (
119
+ <ReactNativeBlurSwitch
120
+ style={[{ width: 65, height: 36 }, style]}
121
+ value={value}
122
+ onValueChange={(event) => {
123
+ onValueChange?.(event.nativeEvent.value);
124
+ }}
125
+ blurAmount={blurAmount}
126
+ thumbColor={toColorString(thumbColor, '#FFFFFF')}
127
+ trackColorOff={toColorString(trackColor?.false, '#E5E5EA')}
128
+ trackColorOn={toColorString(trackColor?.true, '#34C759')}
129
+ disabled={disabled}
130
+ {...props}
131
+ />
132
+ );
133
+ };
134
+
135
+ export default BlurSwitch;
@@ -0,0 +1,62 @@
1
+ import codegenNativeComponent from 'react-native/Libraries/Utilities/codegenNativeComponent';
2
+ import type { ViewProps } from 'react-native';
3
+ import type {
4
+ WithDefault,
5
+ Double,
6
+ DirectEventHandler,
7
+ } from 'react-native/Libraries/Types/CodegenTypes';
8
+
9
+ export interface ValueChangeEvent {
10
+ value: boolean;
11
+ }
12
+
13
+ interface NativeProps extends ViewProps {
14
+ /**
15
+ * The current value of the switch
16
+ * @default false
17
+ */
18
+ value?: WithDefault<boolean, false>;
19
+
20
+ /**
21
+ * The intensity of the blur effect (0-100)
22
+ * @default 10.0
23
+ */
24
+ blurAmount?: WithDefault<Double, 10.0>;
25
+
26
+ /**
27
+ * The color of the switch thumb
28
+ * Note: Not supported by the Android implementation (no-op).
29
+ * Use the native iOS Switch for platform-specific thumb colors.
30
+ * @default '#FFFFFF'
31
+ */
32
+ thumbColor?: WithDefault<string, '#FFFFFF'>;
33
+
34
+ /**
35
+ * The track color when switch is off
36
+ * Note: Not supported by the Android implementation (no-op).
37
+ * Use the native iOS Switch for platform-specific off-state colors.
38
+ * @default '#E5E5EA'
39
+ */
40
+ trackColorOff?: WithDefault<string, '#E5E5EA'>;
41
+
42
+ /**
43
+ * The track color when switch is on
44
+ * @default '#34C759'
45
+ */
46
+ trackColorOn?: WithDefault<string, '#34C759'>;
47
+
48
+ /**
49
+ * Whether the switch is disabled
50
+ * @default false
51
+ */
52
+ disabled?: WithDefault<boolean, false>;
53
+
54
+ /**
55
+ * Callback invoked when the switch value changes
56
+ */
57
+ onValueChange?: DirectEventHandler<Readonly<ValueChangeEvent>>;
58
+ }
59
+
60
+ export default codegenNativeComponent<NativeProps>('ReactNativeBlurSwitch', {
61
+ excludedPlatforms: ['iOS'],
62
+ });
package/src/index.tsx CHANGED
@@ -20,3 +20,9 @@ export { default as ReactNativeLiquidGlassContainer } from './ReactNativeLiquidG
20
20
 
21
21
  export { LiquidGlassContainer } from './LiquidGlassContainer';
22
22
  export type { LiquidGlassContainerProps } from './LiquidGlassContainer';
23
+
24
+ export { default as ReactNativeBlurSwitch } from './ReactNativeBlurSwitchNativeComponent';
25
+ export type { ValueChangeEvent } from './ReactNativeBlurSwitchNativeComponent';
26
+
27
+ export { BlurSwitch } from './BlurSwitch';
28
+ export type { BlurSwitchProps } from './BlurSwitch';