forked from qntln/react-canvas
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
105 lines (90 loc) · 2.81 KB
/
app.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
var React = require('react');
var ReactDOM = require('react-dom');
var ReactCanvas = require('react-canvas');
var Surface = ReactCanvas.Surface;
var Group = ReactCanvas.Group;
var Image = ReactCanvas.Image;
var Text = ReactCanvas.Text;
var FontFace = ReactCanvas.FontFace;
var App = React.createClass({
componentDidMount: function () {
window.addEventListener('resize', this.handleResize, true);
},
render: function () {
var size = this.getSize();
return (
<Surface top={0} left={0} width={size.width} height={size.height} enableCSSLayout={true}>
<Group style={this.getPageStyle()}>
<Text style={this.getTitleStyle()}>
Professor PuddinPop
</Text>
<Group style={this.getImageGroupStyle()}>
<Image src='https://placekitten.com/720/840' style={this.getImageStyle()} fadeIn={true} />
</Group>
<Text style={this.getExcerptStyle()}>
With these words the Witch fell down in a brown, melted, shapeless mass and began to spread over the clean boards of the kitchen floor. Seeing that she had really melted away to nothing, Dorothy drew another bucket of water and threw it over the mess. She then swept it all out the door. After picking out the silver shoe, which was all that was left of the old woman, she cleaned and dried it with a cloth, and put it on her foot again. Then, being at last free to do as she chose, she ran out to the courtyard to tell the Lion that the Wicked Witch of the West had come to an end, and that they were no longer prisoners in a strange land.
</Text>
</Group>
</Surface>
);
},
// Styles
// ======
getSize: function () {
return document.getElementById('main').getBoundingClientRect();
},
getPageStyle: function () {
var size = this.getSize();
return {
position: 'relative',
padding: 14,
width: size.width,
height: size.height,
backgroundColor: '#f7f7f7',
flexDirection: 'column'
};
},
getImageGroupStyle: function () {
return {
position: 'relative',
flex: 1,
backgroundColor: '#eee'
};
},
getImageStyle: function () {
return {
position: 'absolute',
left: 0,
top: 0,
right: 0,
bottom: 0
};
},
getTitleStyle: function () {
return {
fontFace: FontFace('Georgia'),
fontSize: 22,
lineHeight: 28,
height: 28,
marginBottom: 10,
color: '#333',
textAlign: 'center'
};
},
getExcerptStyle: function () {
return {
fontFace: FontFace('Georgia'),
fontSize: 17,
lineHeight: 25,
marginTop: 15,
flex: 1,
color: '#333'
};
},
// Events
// ======
handleResize: function () {
this.forceUpdate();
}
});
ReactDOM.render(<App />, document.getElementById('main'));