React Native Navigation中标题栏的保证金顶部

问题描述 投票:5回答:5

我是React Native的新手。我正在使用React-Navigation。但是,在我的设备上有标题导航问题。这样覆盖状态栏就像这样。

enter image description here

我的代码和React Navigation展示示例都会出现此问题。怎么解决?谢谢

javascript react-native react-navigation
5个回答
8
投票

你正在使用Expo,所以这种行为是正常的。

static navigationOptions = {
  title: "Welcome",
  headerStyle: { marginTop: 24 },
}

您可以像这样定义标题。

大约一年后编辑:

通过Expo,您现在可以使用:

import { Constants } from 'expo'

static navigationOptions = {
  title: "Welcome",
  headerStyle: { marginTop: Constants.statusBarHeight },
}

4
投票

这应该做你想要的。

import {
  StyleSheet,
  View,
  Platform
} from 'react-native';
import { Constants } from 'expo';

const App = () => (
    <View style={styles.container}>
        // Your content with margin for statusBar goes here
    </View>
)

const styles = StyleSheet.create({
  container: {
    marginTop: Platform.OS === 'ios' ? 0 : Constants.statusBarHeight
  }
}

3
投票

我发现这在运行同样的问题时很有用

export default StackNavigator({
    LoginScreen: { screen: Login.component }
}, {
    initialRouteName: 'LoginScreen',
    headerMode: 'none' <------------- This
})

只需在配置对象中添加headerMode:'none'即可

希望这可以帮助

顺便说一下Credit到This Link


2
投票

如果您正在使用世博会,请尝试设置这样的导航选项

navigationOptions:{
  headerStyle:{
    marginTop: (Platform.OS === 'ios') ? 0 : Expo.Constants.statusBarHeight }
  }
}

有了这个,填充只会影响android平台。欲了解更多信息,您可以访问link.


0
投票

如果你正在使用Expo,你可以使用Platformexpo core

import { Constants } from "expo";
import { Platform } from "expo-core"; //inside of Platfrom from 'react-native'

之后创建一个样式表:

const styles = StyleSheet.create({
  container: {
   marginTop: Platform.OS === "ios" ? 0 : Constants.statusBarHeight
   }
});
© www.soinside.com 2019 - 2024. All rights reserved.