我希望我的应用程序上的所有屏幕都出现在iOS和安卓系统的状态栏下方,所以我要么必须在所有屏幕上添加一个StatusBar
组件,要么就必须添加一个paddingTop
。
有没有办法在全球范围内做到这一点?在Redux应用程序中添加StatusBar
的合适的顶层组件在哪里?(例如,https://github.com/react-community/react-navigation/tree/master/examples/ReduxExample的哪个部分)?
发布于 2018-06-15 15:25:22
步骤1:导入平台和StatusBar
import { Platform, StatusBar} from 'react-native';
第2步:在父视图中添加此样式
paddingTop: Platform.OS === 'android' ? StatusBar.currentHeight : 0
完整代码:
import React, { Component } from 'react';
import {
Text, View,
Platform, StatusBar
} from 'react-native';
export default class App extends Component {
render() {
return (
<View style={{ paddingTop: Platform.OS === 'android' ? StatusBar.currentHeight : 0 }}>
<Text>This is Text</Text>
</View>
);
}
}
发布于 2017-08-09 12:36:03
您可以创建一个<NavigationContainer/>
组件来容纳所有不同的页面,这样就不需要在每个单独的屏幕组件中重复StatusBar
和填充代码。
我在这里创建了一个示例:https://snack.expo.io/SyaCeMOwW
而且不需要根据您的导航结构或redux流进行任何更改。
https://stackoverflow.com/questions/45581440
复制相似问题