React-Navigation 嵌套导航器

在移动app开发中,有各种形式的导航。导航组件中导航器和路由器是可以组合的,这样就可以定制你需要的导航组件了。

选项卡导航

效果截图:
作为一个顶层导航器

React-Navigation 嵌套导航器_第1张图片
_ZOKLTB$)94_%N9PD5Q9P{A.png

嵌套在导航器中

React-Navigation 嵌套导航器_第2张图片
J~%T{K7MW%~4HYZTXT)D(FC.png

对于页面内组件暂时还未找到好的方法。

1.顶层切换卡
index.android.js


import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Button
} from 'react-native';
import Tab from './tab';
class HomeScreen extends Component {
  render() {
    return (
          
    );
  }
}

AppRegistry.registerComponent('tang', () => HomeScreen);

tab.js

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Button
} from 'react-native';
import { TabNavigator,StackNavigator } from "react-navigation";

import { ChatScreen } from "./app";
class RecentChatsScreen extends React.Component {
  render() {
    return (
      作为单独组件123
    )
  }
}

class AllContactsScreen extends React.Component {
  render() {
    return 作为单独组件2
  }
}

const MainScreenNavigator = TabNavigator({
  Recent: { screen: RecentChatsScreen },
  All: { screen: AllContactsScreen },
});


export default MainScreenNavigator;

1.和导航器嵌套

tab.js

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Button
} from 'react-native';
import { TabNavigator,StackNavigator } from "react-navigation";

import { ChatScreen } from "./app";
class RecentChatsScreen extends React.Component {
  render() {
    return (
      作为单独组件123
    )
  }
}

class AllContactsScreen extends React.Component {
  render() {
    return 作为单独组件2
  }
}

const MainScreenNavigator = TabNavigator({
  Recent: { screen: RecentChatsScreen },
  All: { screen: AllContactsScreen },
});

MainScreenNavigator.navigationOptions = {
  title: 'My Chats',
};

ChatScreen.navigationOptions = {
  title: 'My Chats',
};

const SimpleApp = StackNavigator({
  Home: { screen: MainScreenNavigator },
  Chat: { screen: ChatScreen },
});

export default SimpleApp;

app.js

import React, { Component } from 'react';
import {
  AppRegistry,
  StyleSheet,
  Text,
  View,
  Button
} from 'react-native';

export  class ChatScreen extends Component {
  static navigationOptions = {
    title: 'Chat',
  };
  render() {
    return (
      
        Chat with Lucy
      
    );
  }
}

export  class HelloScreen extends Component {
  static navigationOptions = {
    title: 'Hello',
  };
  render() {
    return (
      
        Hello 组件 
      
    );
  }
}

你可能感兴趣的:(React-Navigation 嵌套导航器)