React Native Expo StackNavigator重叠通知栏

And*_*rei 13 android reactjs react-native expo create-react-native-app

我正在尝试为我的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"
}
Run Code Online (Sandbox Code Playgroud)

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

我的应用:

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

export default App = StackNavigator({
  Home: { screen: Home }
})
Run Code Online (Sandbox Code Playgroud)

家:

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

    static navigationOptions = {
        title: 'Welcome'
    };

    // <...>
}
Run Code Online (Sandbox Code Playgroud)

Ada*_*icz 30

如果您将整个应用程序包装在View具有上边距的应用程序中,它将起作用.

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

在未来,我们将把它构建成反应导航,以便它自动发生.

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>
    )
  }
}
Run Code Online (Sandbox Code Playgroud)