React Native Expo StackNavigator overlaps Notification bar(React Native Expo StackNavigator 重叠通知栏)
问题描述
我正在尝试为我的 React Native Expo 应用程序实现导航栏.这里有一个问题:
I am trying to implement navigation bar for my React Native Expo app. Here is a problem:
"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 但它不起作用.它在视图上应用了边距,但不在导航栏上.
I don't know where and how I can set up styles for this component to make it not overlap with notifications bar. I tried to set marginTop: StatusBar.currentHeight for my root View but it didn't work. It applied the margin on the View but not on the navigation bar.
我的应用:
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'
};
// <...>
}
推荐答案
如果您将整个应用程序包装在一个 View 中并带有上边距,它会起作用.
If you wrap your entire app in a View with a top margin, it will work.
示例:https://snack.expo.io/r1gb9TGH-
未来,我们将把它构建到 react-navigation 中,这样它就会自动发生.
In the future, we're going to build this into react-navigation so it happens for you automatically.
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 Expo StackNavigator 重叠通知栏的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:React Native Expo StackNavigator 重叠通知栏
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
