javascript - React Native - 在图像上添加蒙版圆圈覆盖
解决方案
正如评论中提到的那样,实现这一点的方法是使用React Native Masked View。
通过运行将其安装到您的项目中:
npm install -S @react-native-community/masked-view
或者
yarn add @react-native-community/masked-view
然后您可以按如下方式使用它。我在README
这里为你改编了他们的例子:
import MaskedView from '@react-native-community/masked-view';
import React from 'react';
import { View } from 'react-native';
export default class App extends React.Component {
render() {
return (
<View
style={{
flex: 1,
backgroundColor: '#000000', // "Edge" background
maxHeight: 400,
}}
>
<MaskedView
style={{ flex: 1 }}
maskElement={
<View
style={{
// Transparent background mask
backgroundColor: '#00000077', // The '77' here sets the alpha
flex: 1,
}}
>
<View
style={{
// Solid background as the aperture of the lens-eye.
backgroundColor: '#ff00ff',
// If you have a set height or width, set this to half
borderRadius: 200,
flex: 1,
}}
/>
</View>
}
>
{/* Shows behind the mask, you can put anything here, such as an image */}
<View style={{ flex: 1, height: '100%', backgroundColor: '#324376' }} />
<View style={{ flex: 1, height: '100%', backgroundColor: '#F5DD90' }} />
<View style={{ flex: 1, height: '100%', backgroundColor: '#F76C5E' }} />
<View style={{ flex: 1, height: '100%', backgroundColor: '#2E6D3E' }} />
</MaskedView>
</View>
);
}
}
推荐阅读
- sql - 排序字母数字 ID 号
- java - 获取 net.sf.json.JSONException:java.lang.reflect.InvocationTargetException
- python - python错误:'int'对象不可下标
- swift - 更改默认蓝色 TabBar
- java - 在 Java 中动态创建嵌套哈希映射的名称
- python - 如何融化多个指标
- java - 将用户类对象添加到 GenericList
在 Java 中给出错误的类 (ClassCastException) - sql - sqlite3中的关键字计数
- excel - 为什么 VBA 代码在使用 .PasteExcelTable 后停止运行
- c# - 从大字符串中获取特定 URL