我一直在处理一个有黑色和透明边的图像上的渐变矩形,我一直在寻找react native中的渐变对象,但我没有找到,但有一个react native模块可以做到这一点,但问题是它在android中的透明度确实有效,但在iOS中,它不起作用,它显示白色代替透明边
然后我在寻找一个原生的iOS解决方案,我做了,但它有点复杂,我不能在react native中实现这个片段
CAGradientLayer *gradientMask = [CAGradientLayer layer];
gradientMask.frame = self.imageView.bounds;
gradientMask.colors = @[(id)[UIColor whiteColor].CGColor,
(id)[UIColor clearColor].CGColor];
self.imageView.layer.mask = gradientMask; <-- // looking for a way to achieve this in react native
这是我的react native代码
<Image ref={r => this.image = r} style={styles.container} source={require('../assets/default_profile_picture.jpg')}>
<LinearGradient ref={r => this.gradiant = r} locations={[0, 1.0]} colors={['rgba(0,0,0,0.00)', 'rgba(0,0,0,0.80)']} style={styles.linearGradient}>
</LinearGradient>
</Image>
我不知道如何将LinearGradient
作为掩码传递给Image
4条答案
按热度按时间z5btuh9x1#
尝试
positioning LinearGradient absolute
将样式添加到LinearGradientmo49yndu2#
只需为
styles.linearGradient
设置opacity: 0.5
hkmswyz63#
你可以使用我的react-native-image-filter-kit库来实现:
安卓系统:
iOS:
vmdwslir4#
如果你正在寻找这种类型的实现
包安装npm i react-native-linear-gradient