@@ -8,14 +8,69 @@ import LottieView from 'lottie-react-native';
88
99const { width : screenWidth } = Dimensions . get ( 'window' ) ;
1010
11+ export default function App ( ) {
12+ const tabs = useMemo ( ( ) => tabData , [ ] ) ;
13+ const flatListRef = useRef < FlatList > ( null ) ;
14+
15+ const onTabChange = useCallback ( ( _item : TabsType , index : number ) => {
16+ flatListRef . current ?. scrollToIndex ( {
17+ animated : true ,
18+ index : index ,
19+ } ) ;
20+ } , [ ] ) ;
21+
22+ return (
23+ < View style = { styles . container } >
24+ < FlatList
25+ ref = { flatListRef }
26+ data = { tabs }
27+ keyExtractor = { ( item ) => item . name }
28+ renderItem = { ( { item } : { item : TabsDataType } ) => {
29+ return (
30+ < View
31+ style = { [
32+ styles . slide ,
33+ {
34+ backgroundColor : item . activeTintColor ,
35+ } ,
36+ ] }
37+ >
38+ < Text style = { styles . titleText } > { item . name } </ Text >
39+ </ View >
40+ ) ;
41+ } }
42+ scrollEnabled = { false }
43+ horizontal
44+ bounces = { false }
45+ pagingEnabled
46+ showsHorizontalScrollIndicator = { false }
47+ />
48+ < TabBar
49+ tabs = { tabs as Array < TabsType > }
50+ onTabChange = { onTabChange }
51+ containerWidth = { screenWidth - 30 }
52+ containerBottomSpace = { 30 }
53+ />
54+ </ View >
55+ ) ;
56+ }
57+
58+ const styles = StyleSheet . create ( {
59+ container : { flex : 1 } ,
60+ box : { width : 60 , height : 60 , marginVertical : 20 } ,
61+ slide : { width : screenWidth , justifyContent : 'center' , alignItems : 'center' } ,
62+ titleText : { color : 'white' } ,
63+ tabStyle : { width : 40 , height : 40 } ,
64+ } ) ;
65+
1166const lottieIconStyle = {
1267 width : 30 ,
1368 height : 30 ,
1469} ;
1570
1671const activeHome = ( isPlay : boolean ) => {
1772 return (
18- < View style = { { width : 40 , height : 40 } } >
73+ < View style = { styles . tabStyle } >
1974 < LottieView
2075 source = { require ( `../assets/bar.json` ) }
2176 autoPlay = { isPlay }
@@ -28,7 +83,7 @@ const activeHome = (isPlay: boolean) => {
2883
2984const activeList = ( isPlay : boolean ) => {
3085 return (
31- < View style = { { width : 40 , height : 40 } } >
86+ < View style = { styles . tabStyle } >
3287 < LottieView
3388 source = { require ( `../assets/cart.json` ) }
3489 autoPlay = { isPlay }
@@ -41,7 +96,7 @@ const activeList = (isPlay: boolean) => {
4196
4297const activeSearch = ( isPlay : boolean ) => {
4398 return (
44- < View style = { { width : 40 , height : 40 } } >
99+ < View style = { styles . tabStyle } >
45100 < LottieView
46101 source = { require ( `../assets/search.json` ) }
47102 autoPlay = { isPlay }
@@ -75,57 +130,3 @@ const tabData: Array<TabsDataType> = [
75130 inactiveIcon : activeSearch ( false ) ,
76131 } ,
77132] ;
78-
79- export default function App ( ) {
80- const tabs = useMemo ( ( ) => tabData , [ ] ) ;
81- const flatListRef = useRef < FlatList > ( null ) ;
82-
83- const onTabChange = useCallback ( ( _item : TabsType , index : number ) => {
84- flatListRef . current ?. scrollToIndex ( {
85- animated : true ,
86- index : index ,
87- } ) ;
88- } , [ ] ) ;
89-
90- return (
91- < View style = { styles . container } >
92- < FlatList
93- ref = { flatListRef }
94- data = { tabs }
95- keyExtractor = { ( item ) => item . name }
96- renderItem = { ( { item } : { item : TabsDataType } ) => {
97- return (
98- < View
99- style = { [
100- styles . slide ,
101- {
102- backgroundColor : item . activeTintColor ,
103- } ,
104- ] }
105- >
106- < Text style = { styles . titleText } > { item . name } </ Text >
107- </ View >
108- ) ;
109- } }
110- scrollEnabled = { false }
111- horizontal
112- bounces = { false }
113- pagingEnabled
114- showsHorizontalScrollIndicator = { false }
115- />
116- < TabBar
117- tabs = { tabs as Array < TabsType > }
118- onTabChange = { onTabChange }
119- containerWidth = { screenWidth - 30 }
120- containerBottomSpace = { 30 }
121- />
122- </ View >
123- ) ;
124- }
125-
126- const styles = StyleSheet . create ( {
127- container : { flex : 1 } ,
128- box : { width : 60 , height : 60 , marginVertical : 20 } ,
129- slide : { width : screenWidth , justifyContent : 'center' , alignItems : 'center' } ,
130- titleText : { color : 'white' } ,
131- } ) ;
0 commit comments