Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat:add get image ref support #29

Merged
merged 2 commits into from
Dec 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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