Ave*_*235 10 android ios react-native redux react-redux
我希望我的应用程序上的所有屏幕都显示在iOS和Android上的状态栏下方,因此我要么必须在我的所有屏幕上添加StatusBar
组件或a paddingTop
.
有没有办法在全球范围内做到这一点?在StatusBar
Redux应用程序中添加适当的顶级组件在哪里?(例如https://github.com/react-community/react-navigation/tree/master/examples/ReduxExample的哪一部分)?
Jit*_*har 25
第1步:导入平台和StatusBar
import { Platform, StatusBar} from 'react-native';
Run Code Online (Sandbox Code Playgroud)
第2步:在父视图中添加此样式
paddingTop: Platform.OS === 'ios' ? StatusBar.currentHeight : 0
Run Code Online (Sandbox Code Playgroud)
完整代码:
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 === 'ios' ? StatusBar.currentHeight : 0 }}>
<Text>This is Text</Text>
</View>
);
}
}
Run Code Online (Sandbox Code Playgroud)
您可以创建一个<NavigationContainer/>
组件来保存所有不同的页面,这样您就不需要StatusBar
在每个屏幕组件中重复填充代码。
我在这里创建了一个示例:\xe3\x80\x80 https://snack.expo.io/SyaCeMOwW
\n\n导航结构或 redux 流程不需要改变。
\n 归档时间: |
|
查看次数: |
7444 次 |
最近记录: |