如何为topBar wix的react-native-navigation V2提供渐变色

问题描述 投票:0回答:2

我正在使用Wix的react-native-navigation V2。我想给topBar提供渐变色。我已经成功安装了react-native-linear-gradient。但我没有得到如何给topBar提供渐变色。

以下是将屏幕推入堆栈的代码。

Navigation.push('mainStack', {
      component: {
        name: 'SignIn',
        options: {
          topBar: {
            visible: true,
            animate: false,
            //hideOnScroll: true,
            //buttonColor: 'white',
            drawBehind: false,
            title: {
              text: 'Sign In',
              fontSize: 18,
              //color: 'white',
              fontFamily: 'Ubuntu',
              alignment: 'center'
            },
            backButton: {
              // icon: require('icon.png'),
              id: 'backButton',
              visible: true,
              //color: 'white'
            },
            background: {
              color: '#1abc9c'
            }
          },
          sideMenu: {
            left: {
              enabled: false
            }
          },
          animations: {
            push: { // It works! Push with animation from right to left
              content: {
                x: {
                  from: 1000,
                  to: 0,
                  duration: 100,
                },
                alpha: {
                  from: 1,
                  to: 1,
                  duration: 100,
                }
              }
            },
            pop: { // It works! Pop with animation from left to right
              content: {
                x: {
                  from: 0,
                  to: 1000,
                  duration: 50,
                },
                alpha: {
                  from: 1,
                  to: 1,
                  duration: 50,
                }
              }
            }
          }
        }
      }
    });

我尝试在下面的选项中给出渐变颜色

background: {
              color: <LinearGradient colors={['#a8ff78', '#78ffd6']} style={styles.container} />
            } 

但它没有用。

android react-native linear-gradients wix-react-native-navigation react-native-navigation-v2
2个回答
0
投票

我不确定它是否有效,我总是使用该库包装我想要具有渐变颜色的组件,如下所示

<LinearGradient
      colors={["#34495E", "#2e4154", "#485b6e"]}
      start={{x: 0.0, y: 0}}
      end={{x: 0.60, y: 0}}
>
  <View>
    {...}
  </View>
</LinearGradient>

0
投票

在React组件中渲染<LinearGradient colors={['#a8ff78', '#78ffd6']} style={styles.container} />并使用Navigation.registerComponent()注册它,然后按如下方式使用它

topBar: {
  background: {
    component: {
      name: "" // The name of the registered component
    }
  }
}

唯一的问题是组件不会在不安全的区域中呈现。

© www.soinside.com 2019 - 2024. All rights reserved.