如果我设置了headerTransparent: true
,那么通常呈现在下面的其他内容就会移动到它下面。我如何避免这种情况?
我的代码:
export class RegisterScreen extends Component {
static navigationOptions = {
title: strings.header,
headerTitleStyle: { color: '#fff' },
headerTintColor: '#fff',
headerTransparent: true,
};
render() {
return <Display onSignUpPressed={() => {}} onHelpPressed={() => {}} />;
}
}
字符串
带透明头(重叠:():
的数据
无透明头:
的
我想有一个标题的高度对齐的内容。所以我希望内容是像第二张图片,但在第一个透明的标题一样。
7条答案
按热度按时间xesrikrc1#
现在,您可以使用
headerStyle
属性为标题给予透明背景,同时保持其高度:字符串
uxhixvfz2#
如果设置了
headerTransparent: true
,标题会与下面的内容重叠。如果你不想让它重叠,你需要根据你的情况手动为你的内容添加一个顶部边距或填充。React Navigation不会自动这样做,但它提供了一个钩子来获取标题高度字符串
现在,你可以像这样在你的组件中获得高度:
型
rdlzhqv93#
您需要给予您的屏幕组件一个与标题高度相等的顶部填充,
efzxgjgh4#
关于React Native v6.x
而不是做
字符串
你可以像这样在标题样式中的backgroundColor中应用它
型
如果你还想留着这个
3df52oht5#
这是一个有点混乱,但你需要这一点https://reactnavigation.org/docs/native-stack-navigator/#headersearchbaroptions
你需要在你的页面中添加ScrollView或Flatlist参数:contentInsetAdjustmentBehavior=“automatic”。即使你没有使用
searchBar
。headerSearchBarOptions Options to render a native search bar on iOS. Search bars are rarely static so normally it is controlled by passing an object to headerSearchBarOptions navigation option in the component's body. You also need to specify contentInsetAdjustmentBehavior="automatic" in your ScrollView, FlatList etc. If you don't have a ScrollView, specify headerTransparent: false.
个tktrz96b6#
将标题背景添加到导航选项如下所示
字符串
dzjeubhm7#
我们可以在
标头透明:true
但我们还需要这样给予headerStyle以使头透明。
字符串
在我的情况下,我使它成为可能,给我的标题这种风格。
样式:{位置:'绝对',背景颜色:'透明',zIndex:100,上:0,左:0,右:0}