css - 如何使用 React Native 实现这样的目标
问题描述
我怎样才能制作这样的组件:
这是我的代码的样子:
viewStyle: {
backgroundColor: color.bgColor,
alignSelf: 'center',
width: 100,
height: '100%',
top: '30%',
transform: [{ scaleX: 4 }],
zIndex: 1,
borderTopEndRadius: 20,
borderTopLeftRadius: 20,
borderTopRightRadius: 20
},
解决方案
改用图像更容易。但是您可以使用react-native-svg尝试一下
您搜索的形状可能尚未制作,因此您可以先学习如何制作矩形和圆形,如下所示:
import Svg, {
Circle,
Ellipse,
G,
Text,
TSpan,
TextPath,
Path,
Polygon,
Polyline,
Line,
Rect,
Use,
Image,
Symbol,
Defs,
LinearGradient,
RadialGradient,
Stop,
ClipPath,
Pattern,
Mask,
} from 'react-native-svg';
/* Use this if you are using Expo
import * as Svg from 'react-native-svg';
const { Circle, Rect } = Svg;
*/
import React from 'react';
import { View, StyleSheet } from 'react-native';
export default class SvgExample extends React.Component {
render() {
return (
<View
style={[
StyleSheet.absoluteFill,
{ alignItems: 'center', justifyContent: 'center' },
]}
>
<Svg height="50%" width="50%" viewBox="0 0 100 100">
<Circle
cx="50"
cy="50"
r="45"
stroke="blue"
strokeWidth="2.5"
fill="green"
/>
<Rect
x="15"
y="15"
width="70"
height="70"
stroke="red"
strokeWidth="2"
fill="yellow"
/>
</Svg>
</View>
);
}
}
这是输出:
您正在搜索的内容可能会更长,并且需要以下许多精确配置:
position
colors
borders
等等...
但如果您不想使用图像,可以使用 react-native-svg 制作。
推荐阅读
- hyperledger - 每次都处于挂起状态的交易
- amazon-dynamodb - 如何在 DynamoDB 中的单个查询中查询一个应该存在而另一个不应该存在于表中的条件
- .net - 如何使用 VB.NET 应用程序动态获取 AssemblyCustomAttribute 的值?
- android - ReactXP VirtualListView 未在 Android 上显示
- c# - 在鼠标处绘制一个矩形 C#
- c++ - 为什么使用 ffmpeg avcodec_send_frame 函数会导致分段错误?
- html - 没有水平滚动条的溢出屏幕自定义导航栏(引导)
- java - android中带有Recyclerview的报警管理器
- javascript - 如何在 Typescript 中导入 Javascript 模块
- android - 即使明显错误,旋转矢量传感器也能保持高精度报告