-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLine.js
60 lines (54 loc) · 1.38 KB
/
Line.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
import React, { Component } from "react";
import { StyleSheet, View } from "react-native";
import * as Utils from "./Utils";
import PropTypes from "prop-types";
const styles = StyleSheet.create({
container: {
position: "absolute"
}
});
export default class Line extends Component {
//static defaultProps = {
// lineWidth: 1,
//}
// 构造
constructor(props) {
super(props);
// 初始状态
this.state = {};
}
render() {
let transform = Utils.getLineTransform(this.props.start, this.props.end);
return (
<View
style={[
styles.container,
{
backgroundColor: this.props.color,
width: transform.distance,
height: this.props.lineWidth,
left: this.props.start.x,
top: this.props.start.y - this.props.lineWidth / 2,
transform: [
{ translateX: transform.translateX },
{ translateY: transform.translateY },
{ rotateZ: transform.rotateRad + "rad" }
]
}
]}
/>
);
}
}
Line.propTypes = {
color: PropTypes.string.isRequired,
lineWidth: PropTypes.number,
start: PropTypes.shape({
x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired
}).isRequired,
end: PropTypes.shape({
x: PropTypes.number.isRequired,
y: PropTypes.number.isRequired
}).isRequired
};