-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathSLine.js
163 lines (138 loc) · 3.9 KB
/
SLine.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View,
TouchableHighlight,
Button,
Dimensions,
PixelRatio,
} from 'react-native';
import { throttle } from 'lodash'
const {width, height} = Dimensions.get('window');
import {
requireNativeComponent,
findNodeHandle,
NativeModules
} from 'react-native';
import {
GCanvasView,
} from 'react-native-gcanvas';
import EV from './EV';
import { enable, ReactNativeBridge, Image as GImage } from "gcanvas.js";
import getMockData from './stockdata';
import * as ClChart from './clchart/cl.api'
ReactNativeBridge.GCanvasModule = NativeModules.GCanvasModule;
ReactNativeBridge.Platform = Platform;
ReactNativeBridge.GCanvasModule.setLogLevel(0);
const deviceScale = PixelRatio.get();
const containerLayout = { width:width, height: (height) }
const canvasLayout = { width: containerLayout.width * deviceScale, height: containerLayout.height * deviceScale }
const eventCentral = new EV();
let count = 0
export default class App extends Component<{}> {
mainCanvasRef = null;
mainContext = null;
mainCanvas = null;
mainChart = null
onMainCanvasLayout = () => {
const canvas_tag = findNodeHandle(this.mainCanvasRef);
const el = { ref:""+canvas_tag, style: canvasLayout};
this.mainCanvas = enable(el, {bridge: ReactNativeBridge, disableAutoSwap: true});
this.mainContext = this.mainCanvas.getContext('2d');
this.mainContext._beforePaint = () => {
this.mainContext.scale(1 / deviceScale, 1 / deviceScale);
}
this.mainContext._afterPaint = () => {
this.mainCanvas._swapBuffers();
count ++;
}
}
clear = () => {
this.mainContext.clearRect(0, 0, width * deviceScale, height * deviceScale)
}
drawLine = (x, y) => {
this.clear()
x *= deviceScale
y *= deviceScale
this.mainContext._beforePaint();
this.mainContext.beginPath();
this.mainContext.lineWidth = 1
this.mainContext.moveTo(0, y)
this.mainContext.lineTo(width * deviceScale, y)
this.mainContext.moveTo(x, 0)
this.mainContext.lineTo(x, height * deviceScale)
this.mainContext.stroke();
this.mainContext._afterPaint()
}
render() {
return (
<View>
<View
style={[containerLayout, styles.canvasContainer]}
onTouchStart={(evt) => {
evt.nativeEvent.offsetX = evt.nativeEvent.locationX
evt.nativeEvent.offsetY = evt.nativeEvent.locationY
eventCentral.emit('touchstart', evt.nativeEvent)
}}
onTouchMove={(evt) => {
// evt.nativeEvent.offsetX = evt.nativeEvent.locationX
// evt.nativeEvent.offsetY = evt.nativeEvent.locationY
// eventCentral.emit('touchmove', evt.nativeEvent)
// alert('dd')
this.drawLine(evt.nativeEvent.locationX, evt.nativeEvent.locationY)
}}
onTouchEnd={(evt) => {
evt.nativeEvent.offsetX = evt.nativeEvent.locationX
evt.nativeEvent.offsetY = evt.nativeEvent.locationY
eventCentral.emit('touchend', evt.nativeEvent)
}}
>
<GCanvasView
onLayout={this.onMainCanvasLayout}
ref={(c) => {
this.mainCanvasRef = c
}}
style={[styles.gcanvas, containerLayout]}
>
</GCanvasView>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
canvasContainer: {
position: 'relative'
},
gcanvas: {
backgroundColor: '#FF000030',
},
coverCanvas: {
position: 'absolute',
top: 0,
left: 0
},
container: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#F5FCFF',
},
button: {
width: 80,
},
welcome: {
fontSize: 50,
textAlign: 'center',
margin: 10,
top:20,
height :40
}
});