React导航:透明头没有高度

vatpfxk5  于 6个月前  发布在  React
关注(0)|答案(7)|浏览(44)

如果我设置了headerTransparent: true,那么通常呈现在下面的其他内容就会移动到它下面。我如何避免这种情况?
我的代码:

export class RegisterScreen extends Component {
  static navigationOptions = {
    title: strings.header,
    headerTitleStyle: { color: '#fff' },
    headerTintColor: '#fff',
    headerTransparent: true,
  };
  render() {
    return <Display onSignUpPressed={() => {}} onHelpPressed={() => {}} />;
  }
}

字符串
带透明头(重叠:():


的数据
无透明头:



我想有一个标题的高度对齐的内容。所以我希望内容是像第二张图片,但在第一个透明的标题一样。

xesrikrc

xesrikrc1#

现在,您可以使用headerStyle属性为标题给予透明背景,同时保持其高度:

static navigationOptions = {
    title: strings.header,
    headerTitleStyle: { color: '#fff' },
    headerTintColor: '#fff',
    headerStyle: { backgroundColor: 'transparent' },
  };

字符串

uxhixvfz

uxhixvfz2#

如果设置了headerTransparent: true,标题会与下面的内容重叠。如果你不想让它重叠,你需要根据你的情况手动为你的内容添加一个顶部边距或填充。React Navigation不会自动这样做,但它提供了一个钩子来获取标题高度

import { useHeaderHeight } from '@react-navigation/stack';

字符串
现在,你可以像这样在你的组件中获得高度:

const headerHeight = useHeaderHeight();

rdlzhqv9

rdlzhqv93#

您需要给予您的屏幕组件一个与标题高度相等的顶部填充,

efzxgjgh

efzxgjgh4#

关于React Native v6.x
而不是做

screenOptions={{headerTransparent: true}}

字符串
你可以像这样在标题样式中的backgroundColor中应用它

screenOptions={{
    headerStyle: {
        backgroundColor: 'transparent';
    }
}}


如果你还想留着这个

3df52oht

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.

tktrz96b

tktrz96b6#

将标题背景添加到导航选项如下所示

static navigationOptions = {
    title: strings.header,
    headerTitleStyle: { color: '#fff' },
    headerTintColor: '#fff',
    headerTransparent: true,
    headerBackground: Platform.select({
        ios: <BlurView style={{ flex: 1 }} intensity={98} />,
        android: (
          <View style={{ flex: 1, backgroundColor: 'rgba(255,255,255,0.7)' }} />
    ),
  }),
};

字符串

dzjeubhm

dzjeubhm7#

我们可以在
标头透明:true
但我们还需要这样给予headerStyle以使头透明。

static navigationOptions = {
headerTransparent: true,
headerStyle: { borderBottomWidth: 0 }
};

字符串
在我的情况下,我使它成为可能,给我的标题这种风格。
样式:{位置:'绝对',背景颜色:'透明',zIndex:100,上:0,左:0,右:0}

相关问题