11import React , { useEffect , useState } from 'react' ;
22import { LayoutChangeEvent , View , ViewStyle } from 'react-native' ;
3- import { PanGestureHandler , PanGestureHandlerGestureEvent } from 'react-native-gesture-handler' ;
3+ import {
4+ PanGestureHandler ,
5+ PanGestureHandlerGestureEvent
6+ } from 'react-native-gesture-handler' ;
47import Animated , { Easing } from 'react-native-reanimated' ;
58import { timing } from 'react-native-redash' ;
69
@@ -11,11 +14,13 @@ import styles from './SegmentedControlStyles';
1114
1215export interface SegmentedControlProps {
1316 activeTintColor ?: string ;
14- inactiveTintColor ?: string ;
15- initialSelectedName ?: string ;
1617 children :
1718 | React . ReactElement < SegmentProps >
1819 | React . ReactElement < SegmentProps > [ ] ;
20+ disabled ?: boolean ;
21+ disabledStyle ?: ViewStyle ;
22+ inactiveTintColor ?: string ;
23+ initialSelectedName ?: string ;
1924 onChangeValue ?: ( name : string ) => void ;
2025 sliderStyle ?: ViewStyle ;
2126 style ?: ViewStyle ;
@@ -24,6 +29,8 @@ export interface SegmentedControlProps {
2429export const SegmentedControl = ( {
2530 activeTintColor = '#000000' ,
2631 children,
32+ disabled = false ,
33+ disabledStyle,
2734 inactiveTintColor = '#000000' ,
2835 initialSelectedName,
2936 onChangeValue,
@@ -115,6 +122,8 @@ export const SegmentedControl = ({
115122 } ;
116123
117124 const handleGestureEvent = ( event : PanGestureHandlerGestureEvent ) : void => {
125+ if ( disabled ) return ;
126+
118127 const { x } = event . nativeEvent ;
119128
120129 const calculatedIndex = Math . floor ( ( x / _width ) * values . length ) ;
@@ -126,10 +135,21 @@ export const SegmentedControl = ({
126135
127136 return (
128137 < SegmentedContext . Provider
129- value = { { selectedName : _activeName , onChange : handleChangeValue } }
138+ value = { {
139+ selectedName : _activeName ,
140+ onChange : handleChangeValue ,
141+ } }
130142 >
131143 < PanGestureHandler onGestureEvent = { handleGestureEvent } >
132- < View onLayout = { handleLayout } style = { [ styles . container , style ] } >
144+ < View
145+ onLayout = { handleLayout }
146+ style = { [
147+ styles . container ,
148+ style ,
149+ disabled && styles . disabledContainer ,
150+ disabled && disabledStyle ,
151+ ] }
152+ >
133153 { typeof _activeName !== 'undefined' && (
134154 < Animated . View
135155 testID = "SegmentedControl_Slider"
@@ -159,9 +179,10 @@ export const SegmentedControl = ({
159179 { {
160180 ...child ,
161181 props : {
162- ... child . props ,
182+ disabled ,
163183 inactiveTintColor,
164184 activeTintColor,
185+ ...child . props ,
165186 } ,
166187 } }
167188 </ React . Fragment >
0 commit comments