-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
86 lines (75 loc) · 2.25 KB
/
index.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
import React from 'react';
import ReactNative from 'react-native';
const OriginalView = ReactNative.View;
const OriginalImage = ReactNative.Image;
const OriginalTouchableOpacity = ReactNative.TouchableOpacity;
function getMockContainer(OriginalComponent) {
return class extends React.Component {
static displayName = 'View';
render() {
return <OriginalComponent {...this.props}><HighlightComponent />{this.props.children}</OriginalComponent>;
}
};
}
class ViewMock extends React.Component {
static displayName = 'View';
render() {
return <OriginalView {...this.props}><HighlightComponent />{this.props.children}</OriginalView>;
}
}
class ImageMock extends React.Component {
static displayName = 'View';
render() {
return <OriginalView style={{position: 'relative'}}><OriginalImage {...this.props} /><HighlightComponent /></OriginalView>;
}
}
Object.defineProperty(ReactNative, 'View', {
value: getMockContainer(OriginalView)
});
Object.defineProperty(ReactNative, 'TouchableOpacity', {
value: getMockContainer(OriginalTouchableOpacity)
});
// Object.defineProperty(ReactNative, 'Image', {
// value: ImageMock
// });
class HighlightComponent extends React.Component {
constructor(props) {
super(props);
this.renderCount = 0;
this.flag = true;
this.clearTimeout;
}
getColor() {
if (this.renderCount === 0) {
return 'transparent';
} else if (this.renderCount === 1) {
return '#0eed4d'; //green
} else if (this.renderCount === 2) {
return '#faff00';//yellow
} else if (this.renderCount === 3) {
return '#ffb600';//orange
} else {
return '#ff3f00'; //red
}
}
componentWillUnmount(){
clearTimeout(this.clearTimeout);
}
render() {
clearTimeout(this.clearTimeout);
this.clearTimeout = setTimeout(() => {
if (this.renderCount > 0) {
this.renderCount = 0;
this.flag = false;
this.setState({}, () => {
this.flag = true;
});
}
}, 500);
if (this.flag) {
this.renderCount++;
}
const colorLayerStyle = {borderWidth: 3, borderColor: this.getColor(), position: 'absolute', top: 0, bottom: 0, left: 0, right: 0};
return <OriginalView style={colorLayerStyle} pointerEvents="box-none" />;
}
}