gpt4 book ai didi

android - React Native Expo StackNavigator 与通知栏重叠

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:33:59 25 4
gpt4 key购买 nike

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

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

我的应用:

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>
)
}
}

关于android - React Native Expo StackNavigator 与通知栏重叠,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45044941/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com