Skip to content

Commit

Permalink
Merge pull request #29 from Sunshine168/refSupport
Browse files Browse the repository at this point in the history
feat:add get image ref support
  • Loading branch information
Sunshine168 committed Dec 9, 2018
2 parents 1d4e8ce + a5f326e commit 37b4e65
Show file tree
Hide file tree
Showing 7 changed files with 1,349 additions and 152 deletions.
15 changes: 15 additions & 0 deletions Docs/Api.md
Original file line number Diff line number Diff line change
Expand Up @@ -469,3 +469,18 @@ a callback on process finished
}}
/>
```

### getImageRef

**Type** - `function`

**Example** -

get image ref

```jsx
<ProcessImage
image={src}
getImageRef={image=>this.image=image}
/>
```
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,21 @@
**Example**

```jsx

const mix = {
color: 'mistyrose',
amount: 10
}

class App extends React.Component {
state = { src: '', err: null }

render() {
const params = {
mix: {
color: 'mistyrose',
amount: 10
}
}
return (
<ProcessImage
image='http://365.unsplash.com/assets/paul-jarvis-9530891001e7f4ccfcef9f3d7a2afecd.jpg'
colors={params}
colors={{
mix
}}
resize={{ width: 500, height: 500, mode: 'bilinear' }}
processedImage={(src, err) => this.setState({ src, err, })}
/>
Expand Down
8 changes: 8 additions & 0 deletions public/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ class App extends Component {
amount: this.state.mixAmount
}
}}
getImageRef={element => (this.image = element)}
/>
<button
disabled={this.state.isProcessing}
Expand All @@ -57,6 +58,13 @@ class App extends Component {
>
test2
</button>
<button
onClick={() => {
console.log(this.image);
}}
>
log ImageRef
</button>
</div>
);
}
Expand Down
11 changes: 8 additions & 3 deletions src/components/ProcessImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ class ProcessImage extends Component {

worker = null;

processedImage = (image, restProps, style) => (
<img src={image} {...restProps} style={style} />
processedImage = (image, restProps, style, getImageRef) => (
<img src={image} {...restProps} style={style} ref={getImageRef} />
);

placeholderImage = image =>
Expand All @@ -161,7 +161,12 @@ class ProcessImage extends Component {
placeholder={this.placeholderImage(props.image)}
>
{image =>
this.processedImage(image, restProps, this.getDefaultImageSize(props))
this.processedImage(
image,
restProps,
this.getDefaultImageSize(props),
props.getImageRef
)
}
</ProgressiveImage>
);
Expand Down
1 change: 1 addition & 0 deletions src/utils/propsFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ const getImageProps = props => {
disableRerender,
customCdn,
onProcessFinish,
getImageRef,
...rest
} = props;

Expand Down
3 changes: 2 additions & 1 deletion src/validators/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ const MainPropTypes = {
scaleToFit: scaleToFitPropType,
disableRerender: PropTypes.bool,
customCdn: PropTypes.string,
onProcessFinish: PropTypes.func
onProcessFinish: PropTypes.func,
getImageRef: PropTypes.func
};

export default MainPropTypes;
Loading

0 comments on commit 37b4e65

Please sign in to comment.