Skip to content

Commit 1690a1a

Browse files
Merge pull request #7 from vojty/feature/react-18.6.8
Support React 18.6.8
2 parents 1364367 + 39ec2d2 commit 1690a1a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+6318
-5542
lines changed

.babelrc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"presets": [
33
[
4-
"env", {
4+
"@babel/preset-env",
5+
{
56
"targets": {
67
"browsers": ["last 2 versions"]
78
}
89
}
910
],
10-
"react",
11-
"stage-2"
12-
]
11+
"@babel/preset-react"
12+
],
13+
"plugins": [["@babel/plugin-proposal-class-properties", { "loose": false }]]
1314
}

.eslintrc.js

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,39 @@
1+
const prettierConfig = require('./.prettierrc.js')
2+
13
module.exports = {
2-
parser: "babel-eslint",
4+
parser: 'babel-eslint',
5+
parserOptions: {
6+
ecmaVersion: 2017,
7+
sourceType: 'module',
8+
ecmaFeatures: {
9+
jsx: true
10+
}
11+
},
312
env: {
413
browser: true,
514
es6: true,
615
node: true
716
},
8-
plugins: ["prettier", "react"],
9-
extends: ["prettier", "plugin:react/recommended", "eslint:recommended"]
10-
};
17+
extends: ['airbnb', 'prettier', 'prettier/react'],
18+
plugins: ['prettier'],
19+
rules: {
20+
'prettier/prettier': [2, prettierConfig],
21+
'no-param-reassign': 0,
22+
'no-underscore-dangle': 0,
23+
'no-plusplus': 0,
24+
'no-restricted-syntax': 0,
25+
'import/prefer-default-export': 0,
26+
'react/prefer-stateless-function': 0,
27+
'react/destructuring-assignment': 0,
28+
'import/no-extraneous-dependencies': [
29+
'error',
30+
{ devDependencies: ['stories/**/*'] }
31+
],
32+
'jsx-a11y/mouse-events-have-key-events': 0
33+
},
34+
settings: {
35+
react: {
36+
version: 'detect'
37+
}
38+
}
39+
}

.npmignore

Lines changed: 0 additions & 3 deletions
This file was deleted.

.prettierrc.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
module.exports = {
2+
printWidth: 80,
3+
trailingComma: 'none',
4+
semi: false,
5+
singleQuote: true,
6+
jsxBracketSameLine: true
7+
}

README.md

Lines changed: 42 additions & 130 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

@@ -56,28 +54,27 @@ React Canvas provides a set of standard React components that abstract the under
5654

5755
### <Gradient>
5856

59-
**Gradient** can be used to set the background of a group or surface.
57+
**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 }
7475
]
7576
}
76-
```
77-
78-
### &lt;ListView&gt;
79-
80-
**ListView** is a touch scrolling container that renders a list of elements in a column. Think of it like UITableView for the web. It leverages many of the same optimizations that make table views on iOS and list views on Android fast.
77+
```
8178

8279
## Events
8380

@@ -90,105 +87,54 @@ For a full list of supported events see [EventTypes](lib/EventTypes.js).
9087
Here is a very simple component that renders text below an image:
9188

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

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

122-
getImageStyle: function () {
98+
getImageStyle() {
12399
return {
124100
top: 0,
125101
left: 0,
126102
width: window.innerWidth,
127103
height: this.getImageHeight()
128-
};
129-
},
104+
}
105+
}
130106

131-
getTextStyle: function () {
107+
getTextStyle() {
132108
return {
133109
top: this.getImageHeight() + 10,
134110
left: 0,
135111
width: window.innerWidth,
136112
height: 20,
137113
lineHeight: 20,
138114
fontSize: 12
139-
};
115+
}
140116
}
141117

142-
});
143-
```
144-
145-
## ListView
146-
147-
Many mobile interfaces involve an infinitely long scrolling list of items. React Canvas provides the ListView component to do just that.
148-
149-
Because ListView virtualizes elements outside of the viewport, passing children to it is different than a normal React component where children are declared in render().
150-
151-
The `numberOfItemsGetter`, `itemHeightGetter` and `itemGetter` props are all required.
152-
153-
```javascript
154-
var ListView = ReactCanvas.ListView;
155-
156-
var MyScrollingListView = React.createClass({
118+
render() {
119+
const surfaceWidth = window.innerWidth
120+
const surfaceHeight = window.innerHeight
121+
const imageStyle = this.getImageStyle()
122+
const textStyle = this.getTextStyle()
157123

158-
render: function () {
159124
return (
160-
<ListView
161-
numberOfItemsGetter={this.getNumberOfItems}
162-
itemHeightGetter={this.getItemHeight}
163-
itemGetter={this.renderItem} />
164-
);
165-
},
166-
167-
getNumberOfItems: function () {
168-
// Return the total number of items in the list
169-
},
170-
171-
getItemHeight: function () {
172-
// Return the height of a single item
173-
},
174-
175-
renderItem: function (index) {
176-
// Render the item at the given index, usually a <Group>
177-
},
178-
179-
});
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+
}
180132
```
181133

182-
See the [timeline example](examples/timeline/app.js) for a more complete example.
183-
184-
Currently, ListView requires that each item is of the same height. Future versions will support variable height items.
185-
186134
## Text sizing
187135

188136
React Canvas provides the `measureText` function for computing text metrics.
189137

190-
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.
191-
192138
Custom fonts are not currently supported but will be added in a future version.
193139

194140
## css-layout
@@ -199,43 +145,9 @@ Future versions may not support css-layout out of the box. The performance impli
199145

200146
See the [css-layout example](examples/css-layout).
201147

202-
## Accessibility
203-
204-
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.
205-
206-
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.
207-
208-
## Running the examples
209-
210-
```
211-
npm install
212-
npm start
213-
```
214-
215-
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.
216-
217-
**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.
218-
219-
220-
## Using with webpack
221-
222-
The [brfs](https://github.com/substack/brfs) transform is required in order to use the project with webpack.
148+
## Running the examples (storybook)
223149

224-
```bash
225-
npm install -g brfs
226-
npm install --save-dev transform-loader brfs
227150
```
228-
229-
Then add the [brfs](https://github.com/substack/brfs) transform to your webpack config
230-
231-
```javascript
232-
module: {
233-
postLoaders: [
234-
{ loader: "transform?brfs" }
235-
]
236-
}
151+
yarn install --pure-lockfile
152+
yarn storybook
237153
```
238-
239-
## Contributing
240-
241-
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)