React Navigation - 在 Blurview 中包装 header 和选项卡导航器丢失道具

React Navigation - wrapping header and tab navigator in Blurview looses props

我正在将 React Navigation 2 用于带有 Expo 的简单 RN 项目。我试图让 header 和底部的选项卡显示在模糊的背景上,所以我做了一个 HOC 来用 BlurView 包装库 Header 以提供该功能。它使模糊效果很好,但不幸的是,标题、后退按钮等在此过程中丢失了。有没有办法在React Navigation中做到这一点,我使用的代码如下:

const wrappedHeader = props => (
    <BlurView tint="light" intensity={80} style={styles.header}>
        <Header {...props}/>
    </BlurView>
);

class HomeScreen extends React.Component {
    static navigationOptions = {
        header: props => wrappedHeader(props),
        headerTitle: "Home Screen",
    };
   ....
}

这个棘手的问题确实让我思考了一段时间。

这是我找到的解决方案,可以让 iOS 感觉 标签栏导航器 :

import React from 'react';
import { StyleSheet } from 'react-native';
import { BlurView } from 'expo';
import { BottomTabBar } from 'react-navigation-tabs';

const styles = StyleSheet.create({
  blurView: {
    position: 'absolute',
    bottom: 0,
    left: 0,
    right: 0,
  },
  bottomTabBar: {
    backgroundColor: 'transparent',
  },
});

export default function TabBar(props) {
  return (
    <BlurView tint="light" intensity={90} style={styles.blurView}>
      <BottomTabBar {...props} style={styles.bottomTabBar} />
    </BlurView>
  );
}

问题似乎与 BlurView 样式有关。

注意:只有在您的导航器上设置 tabBarComponent 选项后,此代码才有效,如下所示:

export default createBottomTabNavigator({
  // This part should be different on your side
  Feed: FeedScreen,
  Me: MeScreen,
  Settings: SettingsScreen,
}, {
  tabBarComponent: TabBar,
});

对于header,我想这一定是同样的把戏,但你需要用top: 0替换bottom: 0