1
1
// TODO: support commented props
2
- import React , { PropsWithChildren , useMemo , useEffect , useState , useCallback } from 'react' ;
3
2
import _ from 'lodash' ;
3
+ import React , { PropsWithChildren , useMemo , useEffect , useState , useCallback } from 'react' ;
4
4
import { useAnimatedReaction , useSharedValue , withTiming , runOnJS } from 'react-native-reanimated' ;
5
5
import { useOrientation , useThemeProps } from '../../hooks' ;
6
6
import { Constants } from '../../commons/new' ;
7
- import { LogService } from '../../services' ;
8
7
import TabBarContext from './TabBarContext' ;
9
8
import TabBar from './TabBar' ;
10
9
import TabBarItem , { TabControllerItemProps } from './TabBarItem' ;
@@ -13,8 +12,6 @@ import PageCarousel from './PageCarousel';
13
12
import useImperativeTabControllerHandle , { TabControllerImperativeMethods } from './useImperativeTabControllerHandle' ;
14
13
export { TabControllerItemProps , TabControllerImperativeMethods } ;
15
14
16
- // TODO: should migrate selectedIndex to initialIndex (and make this prop uncontrolled)
17
-
18
15
interface TabControllerStatics {
19
16
TabBar : typeof TabBar ;
20
17
TabBarItem : typeof TabBarItem ;
@@ -31,10 +28,6 @@ export interface TabControllerProps extends ThemeComponent {
31
28
* Initial selected index
32
29
*/
33
30
initialIndex ?: number ;
34
- /**
35
- * DEPRECATED: use initialIndex instead
36
- */
37
- selectedIndex ?: number ;
38
31
/**
39
32
* callback for when index has change (will not be called on ignored items)
40
33
*/
@@ -70,7 +63,6 @@ const TabController = React.forwardRef((props: PropsWithChildren<TabControllerPr
70
63
const themeProps = useThemeProps ( props , 'TabController' ) ;
71
64
const {
72
65
initialIndex = 0 ,
73
- selectedIndex,
74
66
asCarousel = false ,
75
67
items,
76
68
onChangeIndex = _ . noop ,
@@ -98,29 +90,19 @@ const TabController = React.forwardRef((props: PropsWithChildren<TabControllerPr
98
90
return _ . filter < TabControllerItemProps [ ] > ( items , ( item : TabControllerItemProps ) => item . ignore ) ;
99
91
} , [ items ] ) ;
100
92
101
- /* backwards compatibility for `selectedIndex` prop. this line eventually should be removed */
102
- const _initialIndex = selectedIndex || initialIndex ;
103
-
104
93
/* currentPage - static page index */
105
- const currentPage = useSharedValue ( _initialIndex ) ;
94
+ const currentPage = useSharedValue ( initialIndex ) ;
106
95
/* targetPage - transitioned page index (can be a fraction when transitioning between pages) */
107
- const targetPage = useSharedValue ( _initialIndex ) ;
108
- // const carouselOffset = useSharedValue(initialIndex * Math.round(pageWidth));
96
+ const targetPage = useSharedValue ( initialIndex ) ;
109
97
110
98
const setCurrentIndex = useCallback ( ( index : number ) => {
111
99
'worklet' ;
112
100
currentPage . value = index ;
113
101
} , [ ] ) ;
114
102
115
103
useEffect ( ( ) => {
116
- if ( ! _ . isUndefined ( selectedIndex ) ) {
117
- LogService . deprecationWarn ( { component : 'TabController' , oldProp : 'selectedIndex' , newProp : 'initialIndex' } ) ;
118
- }
119
- } , [ selectedIndex ] ) ;
120
-
121
- useEffect ( ( ) => {
122
- setCurrentIndex ( _initialIndex ) ;
123
- } , [ _initialIndex ] ) ;
104
+ setCurrentIndex ( initialIndex ) ;
105
+ } , [ initialIndex ] ) ;
124
106
125
107
useAnimatedReaction ( ( ) => {
126
108
return currentPage . value ;
@@ -137,7 +119,7 @@ const TabController = React.forwardRef((props: PropsWithChildren<TabControllerPr
137
119
const context = useMemo ( ( ) => {
138
120
return {
139
121
/* Pass Props */
140
- initialIndex : _initialIndex ,
122
+ initialIndex,
141
123
asCarousel,
142
124
pageWidth,
143
125
/* Items */
@@ -147,13 +129,12 @@ const TabController = React.forwardRef((props: PropsWithChildren<TabControllerPr
147
129
/* Animated Values */
148
130
targetPage,
149
131
currentPage,
150
- // carouselOffset,
151
132
containerWidth : screenWidth ,
152
133
/* Callbacks */
153
134
onChangeIndex,
154
135
setCurrentIndex
155
136
} ;
156
- } , [ _initialIndex , asCarousel , items , onChangeIndex , screenWidth ] ) ;
137
+ } , [ initialIndex , asCarousel , items , onChangeIndex , screenWidth ] ) ;
157
138
158
139
return < TabBarContext . Provider value = { context } > { children } </ TabBarContext . Provider > ;
159
140
} ) ;
0 commit comments