Expo Linear Gradient transparent is showing up blackish

喜欢而已 提交于 2019-12-23 02:38:18

问题


I'm trying to get a bottom to top white to transparent-white transition in my React Native screen using Expo Linear Gradients: https://docs.expo.io/versions/latest/sdk/linear-gradient.html

I copied the second example and flipped it around, and made it white instead of black. But now the "transparent" the white is supposed to fade in to is darker that the white is, see below:

The transparent actually is see through so that's good but is there a way to give it a white hue?

Code here:

     <LinearGradient
         colors={[ 'transparent', 'rgba(255,255,255,0.8)']}
         style={{
           position: 'absolute',
           left: 0,
           right: 0,
           bottom: 0,
           height: 200,
         }}
       />

回答1:


It's because transparent is equal to rgba(0,0,0,0)

Try using rgba(255,255,255,0) instead of transparent to get a white to white transition

The w3 spec defines transparent as transparent black as can be read here




回答2:


I actually found my own answer. "transparent" apparently translates to black-transparent, to get white just specify an rgba() in the white channel like so:

<LinearGradient
    colors={[ 'rgba(255,255,255,0)', 'rgba(255,255,255,1)']}
    style={{
        position: 'absolute',
        left: 0,
        right: 0,
        bottom: 0,
        height: 80,
    }}
/>


来源:https://stackoverflow.com/questions/48533133/expo-linear-gradient-transparent-is-showing-up-blackish

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!