首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >React导航标题如何正确显示

React导航标题如何正确显示
EN

Stack Overflow用户
提问于 2018-08-17 02:25:56
回答 1查看 32关注 0票数 0

考虑以下导航堆栈代码:

代码语言:javascript
运行
复制
import React, { Component } from "react";
import PropTypes from "prop-types";

import {
  createBottomTabNavigator,
  createSwitchNavigator
} from "react-navigation";

import Icon from "react-native-vector-icons/Ionicons";


import StackedTest from "./StackedTest";
import Test1 from "./Test1";

import { View, StyleSheet } from "react-native";


const LoggedInNavigator = createBottomTabNavigator(
  {
    test: {
      screen: Test1,
      navigationOptions: {
        tabBarIcon: ({ tintColor, focused }) => (
          <Icon
            name={"ios-list-box-outline"}
            size={24}
            color={focused ? tintColor : "#cdcdcd"}
          />
        )
      }
    },
    stacked: {
      screen: StackedTest,
      navigationOptions: {
        tabBarIcon: ({ tintColor, focused }) => (
          <Icon
            name={"ios-list-box-outline"}
            size={24}
            color={focused ? tintColor : "#cdcdcd"}
          />
        )
      }
    },
  },
  {
    tabBarOptions: {
      showLabel: false,
      activeTintColor: "white",
      activeBackgroundColor: "#dedede",
      style: {
        backgroundColor: "#FFFFFF"
      }
    },
    animationEnabled: true,
    swipeEnabled: true
  }
);

export const createRootNavigator = (loggedIn = false) => {
  return createSwitchNavigator(
    {
      LoggedIn: {
        screen: LoggedInNavigator
      }
    }
  );
};

然后:

代码语言:javascript
运行
复制
import React, { Component } from "react";
import PropTypes from "prop-types";

import { createStackNavigator } from "react-navigation";

import Test1 from "./Test2";
import Test2 from "./Test2";


const stackedTest = createStackNavigator(
  {
    Test1: {
      screen: Test1
    },
    Test2: {
      screen: Test2
    }
  },
  {
    navigationOptions: {
      headerStyle: {
        backgroundColor: "#cdcdcd"
      },
      headerTintColor: "#fff",
      headerTitleStyle: {
        fontWeight: "bold"
      }
    }
  }
);

export default stackedTest;

测试1.js

代码语言:javascript
运行
复制
import React, { Component } from "react";
import { View, Text, StyleSheet } from "react-native";

class Test1 extends Component {
  static navigationOptions = {
    title: "TEST 1 TITLE",
  };

  render = () => {
    return (
      <View style={styles.container}>
        <Text>TEST VIEW 1</Text>
      </View>
    );
  };
}

export default Test1;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center"
  }
});

Test2.js

代码语言:javascript
运行
复制
import React, { Component } from "react";
import { View, Text, StyleSheet } from "react-native";

class Test2 extends Component {
  static navigationOptions = {
    title: "TEST 2 TITLE",
  };

  render = () => {
    return (
      <View style={styles.container}>
        <Text>TEST VIEW 2</Text>
      </View>
    );
  };
}

export default Test2;

const styles = StyleSheet.create({
  container: {
    flex: 1,
    justifyContent: "center",
    alignItems: "center"
  }
});

我得到了以下信息:

显示的

  1. My TEST1视图没有标题:

  1. My TEST2视图显示标题,但顶部有很多填充(填充正常吗?我如何减少它?)

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51883251

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档