React-native IT喵喵~路由之React Navigation
来源:互联网 发布:c语言入门视频教程 编辑:程序博客网 时间:2024/05/21 03:57
大家自己 去看文档吧!!! 为了业务快把文档看完了。。。 不过给大家翻译了一点。。。
欢迎大家关注一下 基于React-naive开发的“IT喵~”项目。技能GET、互联网资讯、程序员相亲、GitHub监控。。。 Github地址:https://github.com/cbamls/kitty_front
效果图
内置的Navigators
起react-navigation
包含了下列三种函数赖创建navigators
StackNavigator
一次性渲染一个screen, 或者提供screen之间的转换, 当打开一个新的screen会被放到栈顶TabNavigator
渲染一个tab bar 使得用户在screen之间切换DrawerNavigator
提供了一种“抽屉”模型,用在滑入或退出screen中
使用Navigators渲染screen
navigators渲染的应用screen实质上是一个个的React组件
- Screen navigation
prop 允许screen分发navigation事件,比如打开另一个screen
- ScreennavigationOptions
用来个性化Screen如何被navigator展现(使用header, title, tab label)
StackNavigator
class MyHomeScreen extends React.Component { static navigationOptions = { title: 'Home', } render() { return ( <Button onPress={() => this.props.navigation.navigate('Profile', {name: 'Lucy'})} title="Go to Lucy's profile" /> ); }}const ModalStack = StackNavigator({ Home: { screen: MyHomeScreen, }, Profile: { path: 'people/:name', screen: MyProfileScreen, },});
API 定义
StackNavigator(RouteConfigs, StackNavigatorConfig)
RouteConfigs
StackNavigator({ Profile: { //`ProfileScreen`是一个React component组件 screen: ProfileScreen, // 当`ProfileScreen` 被 StackNavigator加载, 他会被默认传递一个 `navigation` 属性. path: 'people/:name', // 传递action和路由参数 // Optional: 覆盖`ProfileScreen`的 `navigationOptions` navigationOptions: ({navigation}) => ({ title: `${navigation.state.params.name}'s Profile'`, }), }, ...MyOtherRoutes,});
StackNavigatorConfig
initialRouteName
设置默认screeninitialRouteParams
初始路由的默认参数navigationOptions
对于所有Screen的默认路由选项paths
覆盖 route configs中设置的path集
TabNavigator
class MyHomeScreen extends React.Component { static navigationOptions = { tabBarLabel: 'Home', // Note: By default the icon is only shown on iOS. Search the showIcon option below. tabBarIcon: ({ tintColor }) => ( <Image source={require('./chats-icon.png')} style={[styles.icon, {tintColor: tintColor}]} /> ), }; render() { return ( <Button onPress={() => this.props.navigation.navigate('Notifications')} title="Go to notifications" /> ); }}class MyNotificationsScreen extends React.Component { static navigationOptions = { tabBarLabel: 'Notifications', tabBarIcon: ({ tintColor }) => ( <Image source={require('./notif-icon.png')} style={[styles.icon, {tintColor: tintColor}]} /> ), }; render() { return ( <Button onPress={() => this.props.navigation.goBack()} title="Go back home" /> ); }}const styles = StyleSheet.create({ icon: { width: 26, height: 26, },});const MyApp = TabNavigator({ Home: { screen: MyHomeScreen, }, Notifications: { screen: MyNotificationsScreen, },}, { tabBarOptions: { activeTintColor: '#e91e63', },});
阅读全文
0 0
- React-native IT喵喵~路由之React Navigation
- React Native --react-navigation
- React Native react-navigation
- react-native结合react-navigation之TabNavigator
- 【React Native】react-Navigation之StackNavigator
- React-native Navigation之TabNavigator
- react-native 学习 ----- React Navigation
- react-navigation路由篇之StackRouter
- React Native导航器之react-navigation使用
- React Native导航器之react-navigation使用
- React Native导航器之react-navigation使用
- React Native导航器之react-navigation使用
- React Native开发之React Navigation的StackNavigator 详解
- react-native-navigation 原生路由组件的使用
- 【React Native开发】- React Navigation的使用
- React Native导航react-navigation经验浅谈
- React-Native 中 react-navigation 简单
- react-native Navigation使用一
- JTable表头也就是标题行给隐藏
- update语句
- 试试mysql文件缓存
- 管道重定向
- 错误: -source 1.6 中不支持 diamond 运算符 (请使用 -source 7 或更高版本以启用 diamond 运算符)
- React-native IT喵喵~路由之React Navigation
- TypeScript的使用(与Angular2搭配)
- 不平衡语料的分类
- 虚幻四引擎学习之C++编程(一)
- splunk
- WebSphere Application Server 中 Web 服务器插件工作原理及故障诊断
- java环境变量配置注意
- scala小练习四
- g2o小记