Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/react-native/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
React native React Native-将渐变应用于导航选项卡Navigator_React Native_Gradient - Fatal编程技术网

React native React Native-将渐变应用于导航选项卡Navigator

React native React Native-将渐变应用于导航选项卡Navigator,react-native,gradient,React Native,Gradient,我正在使用React导航,并尝试将从白色到透明的线性渐变应用到选项卡导航器,并将其置于屏幕底部 我找到了一个很好的解决方案,可以在这里使用带有导航标题的react native linear gradient: 我不清楚的是如何将同样的逻辑应用于tabBar。我尝试定义一个组件,如链接示例中所示,然后将其传递给backgroundColor,但它抛出了一个错误 以下是我当前的tabBarOptions代码: { tabBarOptions: { activeTintColor: 'rgba(

我正在使用React导航,并尝试将从白色到透明的线性渐变应用到选项卡导航器,并将其置于屏幕底部

我找到了一个很好的解决方案,可以在这里使用带有导航标题的react native linear gradient:

我不清楚的是如何将同样的逻辑应用于tabBar。我尝试定义一个组件,如链接示例中所示,然后将其传递给backgroundColor,但它抛出了一个错误

以下是我当前的tabBarOptions代码:

{
tabBarOptions: {
  activeTintColor: 'rgba(248, 164, 2, 0.6)',  // Color of tab when pressed
  inactiveTintColor: 'rgba(0,0,0,0.5)', // Color of tab when not pressed
  showLabel: false,
  indicatorStyle: {
    backgroundColor: 'transparent'
  },
  style: {
    backgroundColor: 'rgba(255, 255, 255, 1.0)',
    borderTopColor: 'transparent',
    height: dynamicSize(60),
    position: 'absolute',
    left: 0,
    right: 0,
    bottom: 0
  },
},
},

然后,通过将选项卡定义为以下内容,将其传递到StackNavigator:

tabs: {
  screen: TabVisibleNavigator
},

决定采用一种似乎效果不错的黑客技术:

  • 在tabBarOptions样式中,将backgroundColor设置为透明;绝对定位

  • 创建渐变png图像,另存为项目中的资源

  • 将png作为元素加载到主视图容器的底部

  • 将png样式设置为绝对,以便在背景容器视图上进行渲染

这将在渐变图像上加载一个透明的选项卡栏。这不是最优雅的解决方案,但希望它能帮助陷入同样问题的人