18

我正在尝试为我的 React Native Expo 应用程序实现导航栏。这里有一个问题:

在此处输入图像描述

"dependencies": {
    "expo": "^18.0.3",
    "react": "16.0.0-alpha.12",
    "react-native": "^0.45.1",
    "react-navigation": "^1.0.0-beta.11"
}

我不知道在哪里以及如何设置此组件的样式以使其不与通知栏重叠。我试图marginTop: StatusBar.currentHeight为我的根视图设置,但它没有用。它在视图上应用了边距,但不在导航栏上。

我的应用程序:

import {StackNavigator} from 'react-navigation';
import Home from './app/screens/Home';

export default App = StackNavigator({
  Home: { screen: Home }
})

家:

export default class Home extends Component {
    constructor() {
        super();  
        // <...>
    }

    static navigationOptions = {
        title: 'Welcome'
    };

    // <...>
}
4

2 回答 2

39

如果您将整个应用程序包装在View一个顶部边距中,它将起作用。

示例:https ://snack.expo.io/r1gb9TGH-

将来,我们将把它构建到 react-navigation 中,这样它就会自动发生。

import React, {Component} from 'react';
import {StatusBar, View} from 'react-native'
import {StackNavigator} from 'react-navigation';
import Home from './app/screens/Home';

const RootNavigator = StackNavigator({
  Home: { screen: Home }
})

export default class App extends Component {
  render() {
    return (
      <View style={{ flex: 1, marginTop: StatusBar.currentHeight }}>
        <RootNavigator />
      </View>
    )
  }
}
于 2017-07-11T21:58:38.567 回答
3

将此行添加到app.json文件

"translucent": false

"androidStatusBar"

像这样:

"androidStatusBar": {
  "barStyle": "light-content",
  "backgroundColor": "#3a81fd",
  "hidden": false,
  "translucent": false
},

阅读更多:配置状态栏文档

于 2020-04-03T11:22:28.033 回答