【发布时间】:2020-08-21 07:41:01
【问题描述】:
我目前正在使用这个模块:https://github.com/mxmzb/react-native-gesture-detector。我希望能够从创建的点中画一条线。但是,它似乎只输出圆圈。
它有一个“创建手势”视图:
<View style={{ position: "relative", width: "100%", height: "100%" }}>
<GesturePath
path={gesture.map(coordinate => {
if (recorderOffset) {
return {
x: coordinate.x + recorderOffset.x,
y: coordinate.y + recorderOffset.y,
};
}
return coordinate;
})}
color="green"
slopRadius={30}
center={false}
/>
</View>
GesturePath 是这样定义的:
const GesturePath = ({ path, color, slopRadius, center = true }: GesturePathProps) => {
const baseStyle: ViewStyle = {
position: "absolute",
top: center ? "50%" : 0,
left: center ? "50%" : 0,
opacity: 1,
};
return (
<>
{path.map((point, index) => (
<Animated.View
style={Object.assign({}, baseStyle, {
width: slopRadius,
height: slopRadius,
borderRadius: slopRadius,
backgroundColor: color,
marginLeft: point.x - slopRadius,
marginTop: point.y - slopRadius,
})}
key={index}
/>
))}
</>
);
};
当您在该视图上绘图时,它会使用点勾勒出路径,如下所示:
我希望它是一条平滑的线,而不是上图的一系列圆圈。
【问题讨论】:
-
@ShehanDhaleesha 我快速浏览了一下,但似乎不可能画一条波浪线并获得坐标。
-
我是否正确假设您已经有了这些点并且您只是想从这些点绘制一条平滑线?
-
@grodzi - 我有上面链接的组件,它具有我想要的所有功能,除了它只在它制作的坐标上添加点。我希望它通过一条线连接,如果这条线是 squiqqly,我希望它是平滑的。
-
@jamesG 如果你使用 slopRadius={1} 会发生什么?
标签: javascript react-native expo gesture-recognition