You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -26,9 +26,7 @@ React Canvas brings some of the APIs web developers are familiar with and blends
26
26
27
27
## Installation
28
28
29
-
React Canvas is available through npm:
30
-
31
-
```npm install react-canvas```
29
+
`yarn add react-canvas`
32
30
33
31
## React Canvas Components
34
32
@@ -56,28 +54,27 @@ React Canvas provides a set of standard React components that abstract the under
56
54
57
55
### <Gradient>
58
56
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
+
60
59
```javascript
61
60
render() {
62
61
...
63
62
return (
64
63
<Group style={this.getStyle()}>
65
-
<Gradient style={this.getGradientStyle()}
66
-
colorStops={this.getGradientColors()} />
64
+
<Gradient
65
+
style={this.getGradientStyle()}
66
+
colorStops={this.getGradientColors()} />
67
67
</Group>
68
-
);
68
+
)
69
69
}
70
-
getGradientColors(){
70
+
71
+
getGradientColors() {
71
72
return [
72
73
{ color:"transparent", position:0 },
73
74
{ color:"#000", position:1 }
74
75
]
75
76
}
76
-
```
77
-
78
-
### <ListView>
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
+
```
81
78
82
79
## Events
83
80
@@ -90,105 +87,54 @@ For a full list of supported events see [EventTypes](lib/EventTypes.js).
90
87
Here is a very simple component that renders text below an image:
91
88
92
89
```javascript
93
-
var React =require('react');
94
-
var ReactCanvas =require('react-canvas');
90
+
importReactfrom'react'
91
+
import { Surface, Image, Text } from'react-canvas'
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
+
constsurfaceWidth=window.innerWidth
120
+
constsurfaceHeight=window.innerHeight
121
+
constimageStyle=this.getImageStyle()
122
+
consttextStyle=this.getTextStyle()
157
123
158
-
render:function () {
159
124
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>
<Text style={textStyle}>Here is some text below an image.</Text>
128
+
</Surface>
129
+
)
130
+
}
131
+
}
180
132
```
181
133
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
-
186
134
## Text sizing
187
135
188
136
React Canvas provides the `measureText` function for computing text metrics.
189
137
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
-
192
138
Custom fonts are not currently supported but will be added in a future version.
193
139
194
140
## css-layout
@@ -199,43 +145,9 @@ Future versions may not support css-layout out of the box. The performance impli
199
145
200
146
See the [css-layout example](examples/css-layout).
201
147
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)
223
149
224
-
```bash
225
-
npm install -g brfs
226
-
npm install --save-dev transform-loader brfs
227
150
```
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
237
153
```
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