Skip to content
This repository was archived by the owner on Apr 4, 2025. It is now read-only.

Commit 9c6b47b

Browse files
committed
Add react-navigation example, update all-contributors
1 parent 69c76d5 commit 9c6b47b

File tree

3 files changed

+87
-8
lines changed

3 files changed

+87
-8
lines changed

.all-contributorsrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,8 @@
112112
"avatar_url": "https://avatars1.githubusercontent.com/u/64609?v=4",
113113
"profile": "https://github.com/lemming",
114114
"contributions": [
115-
"code"
115+
"code",
116+
"bug"
116117
]
117118
},
118119
{

README.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ export default class App extends React.Component {
104104
}
105105
]
106106

107+
state = {
108+
activeTab: 'games'
109+
}
110+
107111
renderIcon = icon => ({ isActive }) => (
108112
<Icon size={24} color="white" name={icon} />
109113
)
@@ -124,6 +128,7 @@ export default class App extends React.Component {
124128
{/* Your screen contents depending on current tab. */}
125129
</View>
126130
<BottomNavigation
131+
activeTab={this.state.activeTab}
127132
onTabPress={newTab => this.setState({ activeTab: newTab.key })}
128133
renderTab={this.renderTab}
129134
tabs={this.tabs}
@@ -152,13 +157,11 @@ You can also view the entire documentation on GitBook: https://timomeh.gitbook.i
152157

153158
### React Navigation Support
154159

155-
In contrary to earlier releases, this library _does not support_ React Navigation out of the box (called `NavigationComponent` in earlier releases). React Navigation now ships with an own Material Bottom Navigation: [`createMaterialBottomTabNavigator`](https://reactnavigation.org/docs/en/material-bottom-tab-navigator.html).
156-
157-
The API of React Navigation changes quite frequently, and (until now) it wasn't always easy to keep track of changes and be up-to-date. Also I don't want to favor and promote React Navigation over other Navigation Libraries.
160+
**Check [this example](/examples/with-react-navigation.js) for a custom React Navigation integration.**
158161

159-
You can still implement the Bottom Navigation on your own, for example by using React Navigation's [Custom Navigator](https://reactnavigation.org/docs/en/custom-navigator-overview.html).
162+
In contrary to earlier releases, this library does not support React Navigation _out of the box_. React Navigation now ships with its own Material Bottom Navigation: [`createMaterialBottomTabNavigator`](https://reactnavigation.org/docs/en/material-bottom-tab-navigator.html).
160163

161-
If you integrate material-bottom-navigation with a navigation library in your project, feel free to share your knowledge by contributing to the Documentation or event create your own module which uses react-native-material-bottom-navigation.
164+
You can still implement react-native-material-bottom-navigation manually by using React Navigation's [Custom Navigators](https://reactnavigation.org/docs/en/custom-navigators.html#api-for-building-custom-navigators). Check out [this example](/examples/with-react-navigation.js).
162165

163166
### Updated Material Design Specs
164167

@@ -176,9 +179,9 @@ Thanks goes to these wonderful people ([emoji key](https://github.com/kentcdodds
176179

177180
<!-- ALL-CONTRIBUTORS-LIST:START - Do not remove or modify this section -->
178181
<!-- prettier-ignore -->
179-
| [<img src="https://avatars3.githubusercontent.com/u/4227520?v=4" width="100px;"/><br /><sub><b>Timo Mämecke</b></sub>](https://twitter.com/timomeh)<br />[🐛](https://github.com/timomeh/react-native-material-bottom-navigation/issues?q=author%3Atimomeh "Bug reports") [💻](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=timomeh "Code") [🎨](#design-timomeh "Design") [📖](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=timomeh "Documentation") [💡](#example-timomeh "Examples") [🚇](#infra-timomeh "Infrastructure (Hosting, Build-Tools, etc)") [🤔](#ideas-timomeh "Ideas, Planning, & Feedback") [👀](#review-timomeh "Reviewed Pull Requests") | [<img src="https://avatars3.githubusercontent.com/u/11575429?v=4" width="100px;"/><br /><sub><b>Shayan Javadi</b></sub>](https://www.shayanjavadi.com/)<br />[💻](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=ShayanJavadi "Code") | [<img src="https://avatars2.githubusercontent.com/u/14214500?v=4" width="100px;"/><br /><sub><b>David</b></sub>](https://github.com/davidmpr)<br />[💻](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=davidmpr "Code") | [<img src="https://avatars2.githubusercontent.com/u/19354816?v=4" width="100px;"/><br /><sub><b>Jayser Mendez</b></sub>](http://steemia.io)<br />[📖](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=jayserdny "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/10601911?v=4" width="100px;"/><br /><sub><b>Peter Kottas</b></sub>](https://www.facebook.com/tipsforholiday)<br />[💻](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=PeterKottas "Code") | [<img src="https://avatars0.githubusercontent.com/u/97068?v=4" width="100px;"/><br /><sub><b>Matt Oakes</b></sub>](https://mattoakes.net)<br />[💻](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=matt-oakes "Code") | [<img src="https://avatars0.githubusercontent.com/u/1533112?v=4" width="100px;"/><br /><sub><b>Keeley Carrigan</b></sub>](http://www.keeleycarrigan.com)<br />[💻](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=keeleycarrigan "Code") |
182+
| [<img src="https://avatars3.githubusercontent.com/u/4227520?v=4" width="100px;" alt="Timo Mämecke"/><br /><sub><b>Timo Mämecke</b></sub>](https://twitter.com/timomeh)<br />[🐛](https://github.com/timomeh/react-native-material-bottom-navigation/issues?q=author%3Atimomeh "Bug reports") [💻](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=timomeh "Code") [🎨](#design-timomeh "Design") [📖](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=timomeh "Documentation") [💡](#example-timomeh "Examples") [🚇](#infra-timomeh "Infrastructure (Hosting, Build-Tools, etc)") [🤔](#ideas-timomeh "Ideas, Planning, & Feedback") [👀](#review-timomeh "Reviewed Pull Requests") | [<img src="https://avatars3.githubusercontent.com/u/11575429?v=4" width="100px;" alt="Shayan Javadi"/><br /><sub><b>Shayan Javadi</b></sub>](https://www.shayanjavadi.com/)<br />[💻](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=ShayanJavadi "Code") | [<img src="https://avatars2.githubusercontent.com/u/14214500?v=4" width="100px;" alt="David"/><br /><sub><b>David</b></sub>](https://github.com/davidmpr)<br />[💻](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=davidmpr "Code") | [<img src="https://avatars2.githubusercontent.com/u/19354816?v=4" width="100px;" alt="Jayser Mendez"/><br /><sub><b>Jayser Mendez</b></sub>](http://steemia.io)<br />[📖](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=jayserdny "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/10601911?v=4" width="100px;" alt="Peter Kottas"/><br /><sub><b>Peter Kottas</b></sub>](https://www.facebook.com/tipsforholiday)<br />[💻](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=PeterKottas "Code") | [<img src="https://avatars0.githubusercontent.com/u/97068?v=4" width="100px;" alt="Matt Oakes"/><br /><sub><b>Matt Oakes</b></sub>](https://mattoakes.net)<br />[💻](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=matt-oakes "Code") | [<img src="https://avatars0.githubusercontent.com/u/1533112?v=4" width="100px;" alt="Keeley Carrigan"/><br /><sub><b>Keeley Carrigan</b></sub>](http://www.keeleycarrigan.com)<br />[💻](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=keeleycarrigan "Code") |
180183
| :---: | :---: | :---: | :---: | :---: | :---: | :---: |
181-
| [<img src="https://avatars1.githubusercontent.com/u/177857?v=4" width="100px;"/><br /><sub><b>Sean Holbert</b></sub>](http://www.twitter.com/wildseansy)<br />[💻](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=wildseansy "Code") | [<img src="https://avatars0.githubusercontent.com/u/9802139?v=4" width="100px;"/><br /><sub><b>Alessandro Parolin</b></sub>](https://github.com/aparolin)<br />[📖](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=aparolin "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/1837764?v=4" width="100px;"/><br /><sub><b>Prashanth Acharya M</b></sub>](https://github.com/prashantham)<br />[📖](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=prashantham "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/64609?v=4" width="100px;"/><br /><sub><b>Alexey Tcherevatov</b></sub>](https://github.com/lemming)<br />[💻](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=lemming "Code") | [<img src="https://avatars2.githubusercontent.com/u/5009188?v=4" width="100px;"/><br /><sub><b>Trevor Atlas</b></sub>](https://blog.trevoratlas.com/)<br />[🐛](https://github.com/timomeh/react-native-material-bottom-navigation/issues?q=author%3Atrevor-atlas "Bug reports") |
184+
| [<img src="https://avatars1.githubusercontent.com/u/177857?v=4" width="100px;" alt="Sean Holbert"/><br /><sub><b>Sean Holbert</b></sub>](http://www.twitter.com/wildseansy)<br />[💻](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=wildseansy "Code") | [<img src="https://avatars0.githubusercontent.com/u/9802139?v=4" width="100px;" alt="Alessandro Parolin"/><br /><sub><b>Alessandro Parolin</b></sub>](https://github.com/aparolin)<br />[📖](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=aparolin "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/1837764?v=4" width="100px;" alt="Prashanth Acharya M"/><br /><sub><b>Prashanth Acharya M</b></sub>](https://github.com/prashantham)<br />[📖](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=prashantham "Documentation") | [<img src="https://avatars1.githubusercontent.com/u/64609?v=4" width="100px;" alt="Alexey Tcherevatov"/><br /><sub><b>Alexey Tcherevatov</b></sub>](https://github.com/lemming)<br />[💻](https://github.com/timomeh/react-native-material-bottom-navigation/commits?author=lemming "Code") [🐛](https://github.com/timomeh/react-native-material-bottom-navigation/issues?q=author%3Alemming "Bug reports") | [<img src="https://avatars2.githubusercontent.com/u/5009188?v=4" width="100px;" alt="Trevor Atlas"/><br /><sub><b>Trevor Atlas</b></sub>](https://blog.trevoratlas.com/)<br />[🐛](https://github.com/timomeh/react-native-material-bottom-navigation/issues?q=author%3Atrevor-atlas "Bug reports") |
182185
<!-- ALL-CONTRIBUTORS-LIST:END -->
183186

184187
This project follows the [all-contributors](https://github.com/kentcdodds/all-contributors) specification. Contributions of any kind welcome!

examples/with-react-navigation.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
import React, { useCallback } from 'react'
2+
import { View, Text } from 'react-native'
3+
import { createNavigator, TabRouter } from 'react-navigation'
4+
import BottomNavigation, {
5+
FullTab
6+
} from 'react-native-material-bottom-navigation'
7+
import Icon from '@expo/vector-icons/MaterialCommunityIcons'
8+
9+
// Screens. Normally you would put these in separate files.
10+
const Movies = () => (
11+
<View>
12+
<Text>Movies</Text>
13+
</View>
14+
)
15+
const Music = () => (
16+
<View>
17+
<Text>Music</Text>
18+
</View>
19+
)
20+
const Books = () => (
21+
<View>
22+
<Text>Books</Text>
23+
</View>
24+
)
25+
26+
function AppTabView(props) {
27+
const tabs = [
28+
{ key: 'Movies', label: 'Movies', barColor: '#00695C', icon: 'movie' },
29+
{ key: 'Music', label: 'Music', barColor: '#6A1B9A', icon: 'music-note' },
30+
{ key: 'Books', label: 'Books', barColor: '#1565C0', icon: 'book' }
31+
]
32+
33+
const { navigation, descriptors } = props
34+
const { routes, index } = navigation.state
35+
const activeScreenName = routes[index].key
36+
const descriptor = descriptors[activeScreenName]
37+
const ActiveScreen = descriptor.getComponent()
38+
39+
const handleTabPress = useCallback(
40+
newTab => navigation.navigate(newTab.key),
41+
[navigation]
42+
)
43+
44+
return (
45+
<View style={{ flex: 1 }}>
46+
<View style={{ flex: 1 }}>
47+
<ActiveScreen navigation={descriptor.navigation} />
48+
</View>
49+
50+
<BottomNavigation
51+
tabs={tabs}
52+
activeTab={activeScreenName}
53+
onTabPress={handleTabPress}
54+
renderTab={({ tab, isActive }) => (
55+
<FullTab
56+
isActive={isActive}
57+
key={tab.key}
58+
label={tab.label}
59+
renderIcon={() => <Icon name={tab.icon} size={24} color="white" />}
60+
/>
61+
)}
62+
/>
63+
</View>
64+
)
65+
}
66+
67+
const AppTabRouter = TabRouter({
68+
Movies: { screen: Movies },
69+
Music: { screen: Music },
70+
Books: { screen: Books }
71+
})
72+
73+
const AppNavigator = createNavigator(AppTabView, AppTabRouter, {})
74+
75+
export default AppNavigator

0 commit comments

Comments
 (0)