Skip to content

Commit 6af147a

Browse files
author
Tomáš Vojtášek
committed
Update readme
1 parent 312eb20 commit 6af147a

File tree

1 file changed

+42
-85
lines changed

1 file changed

+42
-85
lines changed

README.md

Lines changed: 42 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
# react-canvas
22

3-
This is a fork of [Flipboard/react-canvas](https://github.com/Flipboard/react-canvas) which:
4-
- Upgrades to React 16 and uses a custom renderer with `react-reconciler`
5-
- Converts to ES modules and modern ES6+
6-
- Storybook for ease of testing examples
7-
- Removes the need to use [brfs](https://github.com/substack/brfs) and `transform-loader` when using webpack.
3+
`react-canvas` fork which supports React 18.6.8 using custom fiber renderer.
84

9-
This fork builds upon work by [CraigMorton](https://github.com/CraigMorton/react-canvas) and [CSBerger](https://github.com/CSberger/react-canvas)
5+
Previous work / forks:
6+
7+
- [Flipboard/react-canvas](https://github.com/Flipboard/react-canvas)
8+
- [CraigMorton/react-canvas](https://github.com/CraigMorton/react-canvas)
9+
- [CSBerger/react-canvas](https://github.com/CSberger/react-canvas)
1010

1111
# Original repo's README
1212

@@ -26,9 +26,7 @@ React Canvas brings some of the APIs web developers are familiar with and blends
2626

2727
## Installation
2828

29-
React Canvas is available through npm:
30-
31-
```npm install react-canvas```
29+
`yarn add react-canvas`
3230

3331
## React Canvas Components
3432

@@ -57,17 +55,20 @@ React Canvas provides a set of standard React components that abstract the under
5755
### <Gradient>
5856

5957
**Gradient** can be used to set the background of a group or surface.
58+
6059
```javascript
6160
render() {
6261
...
6362
return (
6463
<Group style={this.getStyle()}>
65-
<Gradient style={this.getGradientStyle()}
66-
colorStops={this.getGradientColors()} />
64+
<Gradient
65+
style={this.getGradientStyle()}
66+
colorStops={this.getGradientColors()} />
6767
</Group>
68-
);
68+
)
6969
}
70-
getGradientColors(){
70+
71+
getGradientColors() {
7172
return [
7273
{ color: "transparent", position: 0 },
7374
{ color: "#000", position: 1 }
@@ -86,64 +87,54 @@ For a full list of supported events see [EventTypes](lib/EventTypes.js).
8687
Here is a very simple component that renders text below an image:
8788

8889
```javascript
89-
var React = require('react');
90-
var ReactCanvas = require('react-canvas');
91-
92-
var Surface = ReactCanvas.Surface;
93-
var Image = ReactCanvas.Image;
94-
var Text = ReactCanvas.Text;
90+
import React from 'react'
91+
import { Surface, Image, Text } from 'react-canvas'
9592

96-
var MyComponent = React.createClass({
97-
98-
render: function () {
99-
var surfaceWidth = window.innerWidth;
100-
var surfaceHeight = window.innerHeight;
101-
var imageStyle = this.getImageStyle();
102-
var textStyle = this.getTextStyle();
103-
104-
return (
105-
<Surface width={surfaceWidth} height={surfaceHeight} left={0} top={0}>
106-
<Image style={imageStyle} src='...' />
107-
<Text style={textStyle}>
108-
Here is some text below an image.
109-
</Text>
110-
</Surface>
111-
);
112-
},
113-
114-
getImageHeight: function () {
115-
return Math.round(window.innerHeight / 2);
116-
},
93+
class MyComponent extends React.Component {
94+
getImageHeight() {
95+
return Math.round(window.innerHeight / 2)
96+
}
11797

118-
getImageStyle: function () {
98+
getImageStyle() {
11999
return {
120100
top: 0,
121101
left: 0,
122102
width: window.innerWidth,
123103
height: this.getImageHeight()
124-
};
125-
},
104+
}
105+
}
126106

127-
getTextStyle: function () {
107+
getTextStyle() {
128108
return {
129109
top: this.getImageHeight() + 10,
130110
left: 0,
131111
width: window.innerWidth,
132112
height: 20,
133113
lineHeight: 20,
134114
fontSize: 12
135-
};
115+
}
136116
}
137117

138-
});
118+
render() {
119+
const surfaceWidth = window.innerWidth
120+
const surfaceHeight = window.innerHeight
121+
const imageStyle = this.getImageStyle()
122+
const textStyle = this.getTextStyle()
123+
124+
return (
125+
<Surface width={surfaceWidth} height={surfaceHeight} left={0} top={0}>
126+
<Image style={imageStyle} src="..." />
127+
<Text style={textStyle}>Here is some text below an image.</Text>
128+
</Surface>
129+
)
130+
}
131+
}
139132
```
140133

141134
## Text sizing
142135

143136
React Canvas provides the `measureText` function for computing text metrics.
144137

145-
The [Page component](examples/timeline/components/Page.js) in the timeline example contains an example of using measureText to achieve precise multi-line ellipsized text.
146-
147138
Custom fonts are not currently supported but will be added in a future version.
148139

149140
## css-layout
@@ -154,43 +145,9 @@ Future versions may not support css-layout out of the box. The performance impli
154145

155146
See the [css-layout example](examples/css-layout).
156147

157-
## Accessibility
158-
159-
This area needs further exploration. Using fallback content (the canvas DOM sub-tree) should allow screen readers such as VoiceOver to interact with the content. We've seen mixed results with the iOS devices we've tested. Additionally there is a standard for [focus management](http://www.w3.org/TR/2010/WD-2dcontext-20100304/#dom-context-2d-drawfocusring) that is not supported by browsers yet.
160-
161-
One approach that was raised by [Bespin](http://vimeo.com/3195079) in 2009 is to keep a [parallel DOM](http://robertnyman.com/2009/04/03/mozilla-labs-online-code-editor-bespin/#comment-560310) in sync with the elements rendered in canvas.
162-
163-
## Running the examples
148+
## Running the examples (storybook)
164149

165150
```
166-
npm install
167-
npm start
151+
yarn install --pure-lockfile
152+
yarn storybook
168153
```
169-
170-
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.
171-
172-
**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.
173-
174-
175-
## Using with webpack
176-
177-
The [brfs](https://github.com/substack/brfs) transform is required in order to use the project with webpack.
178-
179-
```bash
180-
npm install -g brfs
181-
npm install --save-dev transform-loader brfs
182-
```
183-
184-
Then add the [brfs](https://github.com/substack/brfs) transform to your webpack config
185-
186-
```javascript
187-
module: {
188-
postLoaders: [
189-
{ loader: "transform?brfs" }
190-
]
191-
}
192-
```
193-
194-
## Contributing
195-
196-
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.

0 commit comments

Comments
 (0)