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

enter image description here

"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({
  主页: { screen: Home }
})

主页:

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

    static navigationOptions = {
        title: 'Welcome'
    };

    // <...>
}

推荐答案

如果你把你的整个应用程序包装在一个View的顶部空白处,它就会工作.

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

在future ,我们将把它构建到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>
    )
  }
}

React-native相关问答推荐

'无法解析模块.安装react-native-pager-view后的实用程序/平台

使用FETCH发送BLOB/文件时为空

在 React Native 中,水平滚动不适用于我的整个应用程序

哪个版本的@stripe/stripe-react-native 模块支持 react native 0.62.0 typscript 模板?

FlatList 总是增长到 100% 高度

新的 react-native ios 应用程序没有构建?

PanResponder 在第二次拖动时将 Animated.View 捕捉回原始位置

如何在 react-native 中设置 Onpress On Textinput

在Windows中连接到远程调试器时react-native 超时

React-native 在浏览器中打开链接并返回应用程序

以编程方式在 React Native 中添加组件

将 svg 转换为 react-native-svg

如何在 React-Native 的alert中设置alert框标题?

在Android上更改高度时react-native TextInput显示错误

React Native:当我从 XCode 运行应用程序时看不到 console.logs

React Native vs Swift/Objective-C/Java Native

在 React Native 中使用小数

使用 React-Native Navigation 传递数据

React Native,AppStore 请求 NSLocationAlwaysUsageDescription 值

当前未启用语法nullishCoalescingOperator