11// TODO: support commented props
2- import React , { useCallback , useContext , useEffect , useRef , useMemo , ReactElement } from 'react' ;
2+ import React , { useCallback , useContext , useEffect , useRef , useMemo , ReactElement , useState } from 'react' ;
33import { StyleSheet , TextStyle , LayoutChangeEvent , StyleProp , ViewStyle , TextProps } from 'react-native' ;
44import _ from 'lodash' ;
5- import Reanimated , { runOnJS , useAnimatedStyle , useSharedValue } from 'react-native-reanimated' ;
5+ import Reanimated , { runOnJS , useAnimatedReaction , useAnimatedStyle , useSharedValue } from 'react-native-reanimated' ;
66import { Gesture , GestureDetector } from 'react-native-gesture-handler' ;
77import { Colors , Typography , Spacings } from '../../style' ;
88import Badge , { BadgeProps } from '../badge' ;
@@ -144,6 +144,7 @@ export default function TabBarItem({
144144 // JSON.parse(JSON.stringify is due to an issue with reanimated
145145 const sharedLabelStyle = useSharedValue ( JSON . parse ( JSON . stringify ( StyleSheet . flatten ( labelStyle ) ) ) ) ;
146146 const sharedSelectedLabelStyle = useSharedValue ( JSON . parse ( JSON . stringify ( StyleSheet . flatten ( selectedLabelStyle ) ) ) ) ;
147+ const [ isSelected , setIsSelected ] = useState ( currentPage . value === index ) ;
147148
148149 // NOTE: We clone these color values in refs because they might contain a PlatformColor value
149150 // which throws an error (see https://github.com/software-mansion/react-native-reanimated/issues/3164)
@@ -157,6 +158,12 @@ export default function TabBarItem({
157158 }
158159 } , [ ] ) ;
159160
161+ useAnimatedReaction ( ( ) => currentPage . value === index , ( isSelected , prevIsSelected ) => {
162+ if ( isSelected !== prevIsSelected ) {
163+ runOnJS ( setIsSelected ) ( isSelected ) ;
164+ }
165+ } ) ;
166+
160167 const onLayout = useCallback ( ( event : LayoutChangeEvent ) => {
161168 const { width} = event . nativeEvent . layout ;
162169
@@ -201,6 +208,8 @@ export default function TabBarItem({
201208 return [ styles . tabItem , { flex} , style , constantWidthStyle , pressStyle ] ;
202209 } , [ style , spreadItems ] ) ;
203210
211+ const accessibilityState = useMemo ( ( ) => ( { selected : isSelected } ) , [ isSelected ] ) ;
212+
204213 const gesture = Gesture . Tap ( )
205214 . maxDuration ( 60000 )
206215 . onEnd ( ( ) => {
@@ -226,6 +235,9 @@ export default function TabBarItem({
226235 style = { _style }
227236 onLayout = { onLayout }
228237 testID = { testID }
238+ accessible
239+ accessibilityRole = "tab"
240+ accessibilityState = { accessibilityState }
229241 >
230242 { leadingAccessory }
231243 { icon && (
0 commit comments