使用基本的DrawerNavigator时,有适当的paddingTop可以避免在状态栏上覆盖内容;但是,添加自定义contentComponent时,不存在填充。代码:https://github.com/myplaceonline/testreactexpo/tree/drawermargin
在Android上没有自定义contentComponent:
在Android上具有自定义contentComponent:
我可以添加一些明确的边距,但是我应该选择什么值?我已经在使用SafeAreaView
,但我相信这仅适用于iOS。
这是代码。注释contentComponent: CustomDrawerContentComponent,
行以查看工作视图。
import React from 'react';
import { SafeAreaView, ScrollView, Text, View } from 'react-native';
import { createAppContainer, createDrawerNavigator, createStackNavigator, DrawerItems } from 'react-navigation';
class TestScreen extends React.Component {
static navigationOptions = {
title: "Test",
};
render() {
return (
<View style={{flex: 1, alignItems: "center", justifyContent: "center" }}>
<Text>Test</Text>
</View>
);
}
}
const CustomDrawerContentComponent = props => (
<SafeAreaView style={{flex: 1}} forceInset={{ top: "always", horizontal: "never" }}>
<ScrollView>
<DrawerItems {...props} />
</ScrollView>
</SafeAreaView>
);
export default AppDrawer = createAppContainer(
createDrawerNavigator(
{
DrawerTest: {
screen: createStackNavigator(
{
Test: TestScreen
},
),
navigationOptions: {
drawerLabel: "Test",
}
},
},
{
contentComponent: CustomDrawerContentComponent,
}
)
);
<div data-snack-id="@git/github.com/myplaceonline/testreactexpo@drawermargin" data-snack-platform="ios" data-snack-preview="true" data-snack-theme="light" style="overflow:hidden;background:#fafafa;border:1px solid rgba(0,0,0,.08);border-radius:4px;height:505px;width:100%"></div>
<script async src="https://snack.expo.io/embed.js"></script>
答案 0 :(得分:0)
解决了:
<ScrollView style={{paddingTop: Constants.statusBarHeight}}>