|
1 | | -import { StyleSheet } from 'react-native'; |
2 | | -import TabView, { |
3 | | - type OnPageSelectedEventData, |
4 | | - type TabViewItems, |
5 | | -} from 'react-native-bottom-tabs'; |
| 1 | +import TabView, { SceneMap } from 'react-native-bottom-tabs'; |
6 | 2 | import { useState } from 'react'; |
7 | 3 | import { Article } from '../Screens/Article'; |
8 | 4 | import { Albums } from '../Screens/Albums'; |
9 | | -import { Chat } from '../Screens/Chat'; |
10 | 5 | import { Contacts } from '../Screens/Contacts'; |
| 6 | +import { Chat } from '../Screens/Chat'; |
11 | 7 |
|
12 | | -const items: TabViewItems = [ |
13 | | - { key: 'article', title: 'Article', icon: 'document.fill', badge: '!' }, |
14 | | - { key: 'albums', title: 'Albums', icon: 'square.grid.2x2.fill', badge: '5' }, |
15 | | - { key: 'contacts', title: 'Contacts', icon: 'person.fill' }, |
16 | | - { key: 'chat', title: 'Chat', icon: 'keyboard' }, |
17 | | -]; |
18 | | - |
19 | | -export default function FourTabs() { |
20 | | - const [selectedPage, setSelectedTab] = useState<string>('contacts'); |
21 | | - |
22 | | - const handlePageSelected = ({ |
23 | | - nativeEvent: { key }, |
24 | | - }: { |
25 | | - nativeEvent: OnPageSelectedEventData; |
26 | | - }) => setSelectedTab(key); |
| 8 | +export default function ThreeTabs() { |
| 9 | + const [index, setIndex] = useState(0); |
| 10 | + const [routes] = useState([ |
| 11 | + { key: 'article', title: 'Article', icon: 'document.fill', badge: '!' }, |
| 12 | + { |
| 13 | + key: 'albums', |
| 14 | + title: 'Albums', |
| 15 | + icon: 'square.grid.2x2.fill', |
| 16 | + badge: '5', |
| 17 | + }, |
| 18 | + { key: 'contacts', title: 'Contacts', icon: 'person.fill' }, |
| 19 | + { key: 'chat', title: 'Chat', icon: 'keyboard' }, |
| 20 | + ]); |
27 | 21 |
|
28 | | - const goToAlbums = () => { |
29 | | - setSelectedTab('albums'); |
30 | | - }; |
| 22 | + const renderScene = SceneMap({ |
| 23 | + article: Article, |
| 24 | + albums: Albums, |
| 25 | + contacts: Contacts, |
| 26 | + chat: Chat, |
| 27 | + }); |
31 | 28 |
|
32 | 29 | return ( |
33 | 30 | <TabView |
34 | | - style={styles.fullWidth} |
35 | | - items={items} |
36 | | - tabViewStyle="sidebarAdaptable" |
37 | | - selectedPage={selectedPage} |
38 | | - onPageSelected={handlePageSelected} |
39 | | - > |
40 | | - <Article onClick={goToAlbums} /> |
41 | | - <Albums /> |
42 | | - <Contacts /> |
43 | | - <Chat /> |
44 | | - </TabView> |
| 31 | + navigationState={{ index, routes }} |
| 32 | + onIndexChange={setIndex} |
| 33 | + renderScene={renderScene} |
| 34 | + /> |
45 | 35 | ); |
46 | 36 | } |
47 | | - |
48 | | -const styles = StyleSheet.create({ |
49 | | - fullWidth: { |
50 | | - width: '100%', |
51 | | - height: '100%', |
52 | | - }, |
53 | | -}); |
0 commit comments