Skip to content

Commit e0c8c46

Browse files
committed
Merge branch 'master' of github.com:Flipboard/react-canvas into unicode-linebreaking
2 parents 367b46f + ddfecb4 commit e0c8c46

File tree

10 files changed

+63
-22
lines changed

10 files changed

+63
-22
lines changed

README.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ This project is a work-in-progress. Though much of the code is in production on
88

99
## Motivation
1010

11-
Having a long history of building interfaces geared toward mobile devices, we found that the reason mobile web apps feel slow when compared to native apps is the DOM. CSS animations and transitions are the fastest path to smooth animations on the web, but they have several limitiations. React Canvas leverages the fact that most modern mobile browsers now have hardware accelerated canvas.
11+
Having a long history of building interfaces geared toward mobile devices, we found that the reason mobile web apps feel slow when compared to native apps is the DOM. CSS animations and transitions are the fastest path to smooth animations on the web, but they have several limitations. React Canvas leverages the fact that most modern mobile browsers now have hardware accelerated canvas.
1212

1313
While there have been other attempts to bind canvas drawing APIs to React, they are more focused on visualizations and games. Where React Canvas differs is in the focus on building application user interfaces. The fact that it renders to canvas is an implementation detail.
1414

@@ -175,6 +175,11 @@ npm install
175175
npm start
176176
```
177177

178-
This will start a live reloading server on port 8080.
178+
This will start a live reloading server on port 8080. To override the default server and live reload ports, run `npm start` with PORT and/or RELOAD_PORT environment variables.
179179

180180
**A note on NODE_ENV and React**: running the examples with `NODE_ENV=production` will noticeably improve scrolling performance. This is because React skips propType validation in production mode.
181+
182+
## Contributing
183+
184+
We welcome pull requests for bug fixes, new features, and improvements to React Canvas. Contributors to the main repository must accept Flipboard's Apache-style [Individual Contributor License Agreement (CLA)](https://docs.google.com/forms/d/1gh9y6_i8xFn6pA15PqFeye19VqasuI9-bGp_e0owy74/viewform) before any changes can be merged.
185+

examples/css-layout/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
5-
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
5+
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
66
<title>ReactCanvas: css-layout</title>
77
<link rel="stylesheet" type="text/css" href="/examples/common/examples.css">
88
<script src="/examples/common/touch-emulator.js"></script>
@@ -14,4 +14,4 @@
1414
<div id="main"></div>
1515
<script src="/build/css-layout.js"></script>
1616
</body>
17-
</html>
17+
</html>

examples/listview/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
5-
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
5+
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
66
<title>ReactCanvas: ListView</title>
77
<link rel="stylesheet" type="text/css" href="/examples/common/examples.css">
88
<script src="/examples/common/touch-emulator.js"></script>
@@ -14,4 +14,4 @@
1414
<div id="main"></div>
1515
<script src="/build/listview.js"></script>
1616
</body>
17-
</html>
17+
</html>

examples/timeline/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<html>
33
<head>
44
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
5-
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
5+
<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
66
<title>ReactCanvas: Timeline</title>
77
<link rel="stylesheet" type="text/css" href="/examples/common/examples.css">
88
<script src="/examples/common/touch-emulator.js"></script>
@@ -14,4 +14,4 @@
1414
<div id="main"></div>
1515
<script src="/build/timeline.js"></script>
1616
</body>
17-
</html>
17+
</html>

gulpfile.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
var gulp = require('gulp');
2-
var clean = require('gulp-clean');
2+
var del = require('del');
33
var connect = require('gulp-connect');
44
var webpack = require('gulp-webpack');
55
var webpackConfig = require('./webpack.config.js');
66

7+
var port = process.env.PORT || 8080;
8+
var reloadPort = process.env.RELOAD_PORT || 35729;
9+
710
gulp.task('clean', function () {
8-
return gulp.src('build', {read: false})
9-
.pipe(clean());
11+
del(['build']);
1012
});
1113

1214
gulp.task('build', function () {
@@ -17,7 +19,10 @@ gulp.task('build', function () {
1719

1820
gulp.task('serve', function () {
1921
connect.server({
20-
livereload: true
22+
port: port,
23+
livereload: {
24+
port: reloadPort
25+
}
2126
});
2227
});
2328

lib/Group.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var Group = createComponent('Group', LayerMixin, ContainerMixin, {
2323
this.applyLayerProps(prevProps, props);
2424
this.updateChildren(props.children, transaction, context);
2525
this._currentElement = nextComponent;
26+
this.node.invalidateLayout();
2627
},
2728

2829
unmountComponent: function () {

lib/Image.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,21 @@ var Image = React.createClass({
7676
render: function () {
7777
var rawImage;
7878
var imageStyle = assign({}, this.props.style);
79+
var style = assign({}, this.props.style);
80+
var backgroundStyle = assign({}, this.props.style);
7981
var useBackingStore = this.state.loaded ? this.props.useBackingStore : false;
8082

8183
// Hide the image until loaded.
8284
imageStyle.alpha = this.state.imageAlpha;
8385

86+
// Hide opaque background if image loaded so that images with transparent
87+
// do not render on top of solid color.
88+
style.backgroundColor = imageStyle.backgroundColor = null;
89+
backgroundStyle.alpha = clamp(1 - this.state.imageAlpha, 0, 1);
90+
8491
return (
85-
React.createElement(Group, {ref: 'main', style: this.props.style},
92+
React.createElement(Group, {ref: 'main', style: style},
93+
React.createElement(Layer, {ref: 'background', style: backgroundStyle}),
8694
React.createElement(RawImage, {ref: 'image', src: this.props.src, style: imageStyle, useBackingStore: useBackingStore})
8795
)
8896
);

lib/LayerMixin.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ var LayerMixin = {
5353
layer.alpha = style.alpha;
5454
layer.backgroundColor = style.backgroundColor;
5555
layer.borderColor = style.borderColor;
56+
layer.borderWidth = style.borderWidth;
5657
layer.borderRadius = style.borderRadius;
5758
layer.clipRect = style.clipRect;
5859
layer.frame = FrameUtils.make(style.left || 0, style.top || 0, style.width || 0, style.height || 0);

lib/hitTest.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,13 @@ function hitTest (e, rootLayer, rootNode) {
2121
touchX -= rootNodeBox.left;
2222
touchY -= rootNodeBox.top;
2323
}
24-
return getLayerAtPoint(rootLayer, e.type, FrameUtils.make(touchX, touchY, 1, 1));
24+
return getLayerAtPoint(
25+
rootLayer,
26+
e.type,
27+
FrameUtils.make(touchX, touchY, 1, 1),
28+
rootLayer.translateX || 0,
29+
rootLayer.translateY || 0
30+
);
2531
}
2632

2733
/**
@@ -48,11 +54,11 @@ function getHitHandle (type) {
4854
/**
4955
* @private
5056
*/
51-
function getLayerAtPoint (root, type, point) {
57+
function getLayerAtPoint (root, type, point, tx, ty) {
5258
var layer = null;
5359
var hitHandle = getHitHandle(type);
5460
var sortedChildren;
55-
var hitFrame = root.frame;
61+
var hitFrame = FrameUtils.clone(root.frame);
5662

5763
// Early bail for non-visible layers
5864
if (typeof root.alpha === 'number' && root.alpha < 0.01) {
@@ -63,7 +69,13 @@ function getLayerAtPoint (root, type, point) {
6369
if (root.children) {
6470
sortedChildren = root.children.slice().reverse().sort(sortByZIndexDescending);
6571
for (var i=0, len=sortedChildren.length; i < len; i++) {
66-
layer = getLayerAtPoint(sortedChildren[i], type, point);
72+
layer = getLayerAtPoint(
73+
sortedChildren[i],
74+
type,
75+
point,
76+
tx + (root.translateX || 0),
77+
ty + (root.translateY || 0)
78+
);
6779
if (layer) {
6880
break;
6981
}
@@ -78,6 +90,15 @@ function getLayerAtPoint (root, type, point) {
7890
);
7991
}
8092

93+
// Check for x/y translation
94+
if (tx) {
95+
hitFrame.x += tx;
96+
}
97+
98+
if (ty) {
99+
hitFrame.y += ty;
100+
}
101+
81102
// No child layer at the given point. Try the parent layer.
82103
if (!layer && root[hitHandle] && FrameUtils.intersects(hitFrame, point)) {
83104
layer = root;

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,15 @@
2121
"url": "https://github.com/Flipboard/react-canvas/issues"
2222
},
2323
"devDependencies": {
24-
"react": "^0.13.0-beta.1",
25-
"webpack": "^1.5.3",
26-
"transform-loader": "^0.2.1",
24+
"del": "^1.1.1",
2725
"envify": "^3.2.0",
28-
"jsx-loader": "^0.12.2",
2926
"gulp": "^3.8.10",
3027
"gulp-connect": "^2.2.0",
3128
"gulp-webpack": "^1.2.0",
32-
"gulp-clean": "^0.3.1"
29+
"jsx-loader": "^0.12.2",
30+
"react": "^0.13.0-beta.1",
31+
"transform-loader": "^0.2.1",
32+
"webpack": "^1.5.3"
3333
},
3434
"peerDependencies": {
3535
"react": "^0.13.0-beta.1"

0 commit comments

Comments
 (0)