【问题标题】:How to give gradient color to topBar wix's react-native-navigation V2如何为 topBar wix 的 react-native-navigation V2 赋予渐变色
【发布时间】:2019-06-30 13:30:46
【问题描述】:

我正在使用 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


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,但我想要 topBar 中的渐变色
    【解决方案2】:

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

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

    唯一的问题是组件不会在不安全区域渲染。

    【讨论】:

    • 谢谢,但我明白最后一行的意思,你能解释一下吗。
    • 该组件不会在有凹槽的手机的状态栏区域呈现
    • 谢谢,请解释一下原因
    猜你喜欢
    • 2018-12-03
    • 2019-10-22
    • 1970-01-01
    • 2018-12-02
    • 2018-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多