android - React Navigation - 在 Blurview 中包装标题和选项卡导航器会丢失 Prop

标签 android ios react-native react-navigation blur

我将 React Navigation 2 用于一个带有 Expo 的简单 RN 项目。我试图让底部的标题和选项卡显示在模糊的背景上,所以我做了一个 HOC 来用 BlurView 包装库标题以提供该功能。它使模糊效果很好,但不幸的是,标题、后退按钮等在此过程中丢失了。有没有办法在 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 ,我想这一定是相同的技巧,但您需要将 bottom: 0 替换为 top: 0 .

关于android - React Navigation - 在 Blurview 中包装标题和选项卡导航器会丢失 Prop ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51656804/

相关文章:

Android:onBindViewHolder无法缓存图像

Android Videoview - 删除两侧的黑色空间

javascript - 在 xcode6 中向 UIWebView 添加 2 个 .js 文件和一个 .css 文件

ios - 通过 iOS 登录 Facebook

React-Native:需要未知模块 "react/lib/ReactPropTypesSecret"

react-native - 在 react-navigation 5.x 选项卡中预加载嵌套堆栈

android - react - 错误 : package expo. modules.updates 不存在

java - 如何以编程方式添加 webview

java - Android - 静态上下文

ios - UISwitch 似乎没有显示正确的状态