【问题标题】:React Native Expo StackNavigator overlaps Notification barReact Native Expo StackNavigator 重叠通知栏
【发布时间】:2017-12-16 03:06:47
【问题描述】:

我正在尝试为我的 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'
    };

    // <...>
}

【问题讨论】:

    标签: android reactjs react-native expo create-react-native-app


    【解决方案1】:

    如果您将整个应用程序包装在带有上边距的 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>
        )
      }
    }
    

    【讨论】:

    • 正是我想要的!
    【解决方案2】:

    将此行添加到app.json 文件中

    "translucent": false
    

    "androidStatusBar"

    像这样:

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

    阅读更多:Configuring StatusBar Docs

    【讨论】:

    • 这对于最近的expo版本来说是一个更好的解决方案
    • iOS状态栏怎么样?
    猜你喜欢
    • 2022-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-08
    • 1970-01-01
    相关资源
    最近更新 更多