mirror of
https://github.com/zhigang1992/react-navigation.git
synced 2026-05-27 09:04:44 +08:00
Add withNavigation HOC (#137)
This commit is contained in:
committed by
Satyajit Sahoo
parent
d2fc150f69
commit
aead8ff9fb
33
examples/NavigationPlayground/js/WithNavigation.js
Normal file
33
examples/NavigationPlayground/js/WithNavigation.js
Normal file
@@ -0,0 +1,33 @@
|
||||
/* @flow */
|
||||
|
||||
import React from 'react';
|
||||
import {
|
||||
View,
|
||||
Text,
|
||||
Button,
|
||||
} from 'react-native';
|
||||
import { TabNavigator, withNavigation } from 'react-navigation';
|
||||
|
||||
const ButtonWithNavigation = withNavigation(({ navigation, to, ...rest }) => (
|
||||
<Button {...rest} onPress={() => navigation.navigate(to)} />
|
||||
));
|
||||
|
||||
const createTabWithNavigationButtons = (tabName: string, links: Array<string>) => {
|
||||
const Tab = () => (
|
||||
<View>
|
||||
<Text>This is tab: {tabName}</Text>
|
||||
<Text>You can navigate to:</Text>
|
||||
{links.map(link => (
|
||||
<ButtonWithNavigation key={link} to={link} title={link} />
|
||||
))}
|
||||
</View>
|
||||
);
|
||||
|
||||
return Tab;
|
||||
};
|
||||
|
||||
export default TabNavigator({
|
||||
Tab1: { screen: createTabWithNavigationButtons('Tab1', ['Tab2', 'Tab3']) },
|
||||
Tab2: { screen: createTabWithNavigationButtons('Tab2', ['Tab3', 'Tab1']) },
|
||||
Tab3: { screen: createTabWithNavigationButtons('Tab2', ['Tab2', 'Tab1']) },
|
||||
});
|
||||
Reference in New Issue
Block a user