React Native Expo StackNavigator 与通知栏重叠
React Native Expo StackNavigator overlaps Notification bar
我正在尝试为我的 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'
};
// <...>
}
如果您将整个应用包装在一个 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>
)
}
}
将此行添加到 app.json
文件
"translucent": false
在"androidStatusBar"
像这样:
"androidStatusBar": {
"barStyle": "light-content",
"backgroundColor": "#3a81fd",
"hidden": false,
"translucent": false
},
阅读更多内容:Configuring StatusBar Docs
我正在尝试为我的 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'
};
// <...>
}
如果您将整个应用包装在一个 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>
)
}
}
将此行添加到 app.json
文件
"translucent": false
在"androidStatusBar"
像这样:
"androidStatusBar": {
"barStyle": "light-content",
"backgroundColor": "#3a81fd",
"hidden": false,
"translucent": false
},
阅读更多内容:Configuring StatusBar Docs