Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon committed Oct 21, 2014
1 parent 0e94426 commit ba613c6
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions README.md
Expand Up @@ -272,16 +272,16 @@ You can optionally specify images to be used as drag thumbnails.
Browsers can't do this reliably until image is loaded, so `ImagePreloaderMixin` provides an API to do just that:
```javascript
mixins : [DragDropMixin, ImagePreloaderMixin],
mixins: [DragDropMixin, ImagePreloaderMixin],

// This method should return array of image urls for preloading
getImageUrlsToPreload() {
return ['some-img-url1', 'some-img-url2'];
}
},

// You can now use `this.hasPreloadedImage(url)` and `this.getPreloadedImage(url)` in your `dragSource`:
configureDragDrop(registerType) {
registerType(ItemTypes.IMAGE, {
registerType(ItemTypes.MY_ITEM, {
dragSource: {
canDrag() {
return this.hasPreloadedImage('some-img-url1');
Expand All @@ -298,12 +298,9 @@ configureDragDrop(registerType) {
}
```
Above code will load the images after `componentDidMount` is executed, and cache them until component unmounted.
In `componentDidUpdate`, mixin will check if `getImageUrlsToPreload` has changed, and load images again if needed.
Above code will load the images after `componentDidMount` is executed, and cache them until component unmounted. In `componentDidUpdate`, mixin will check if `getImageUrlsToPreload` has changed, and load images again if needed.
Note that, for best results, you want to use `this.calculateDragPreviewSize({ width, height }: desiredSize)`.
It will return the exact size of image you need to download, considering browser differences in handling Retina screens.
Of course you can only use this if you have some kind of custom image resizer.
Note that, for best results, you want to use `this.calculateDragPreviewSize({ width, height }: desiredSize)`. It will return the exact size of image you need to download, considering browser differences in handling Retina screens. Of course you can only use this if you have some kind of custom image resizer.
## Thanks
Expand Down

0 comments on commit ba613c6

Please sign in to comment.