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

Ignore Image getSize when component unmounts #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Node CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [8.x, 10.x, 12.x]

steps:
- uses: actions/checkout@v1
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- name: npm install, build, and test
run: |
npm install
npm run build --if-present
npm test
env:
CI: true
10 changes: 9 additions & 1 deletion library/TransformableImage.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ export default class TransformableImage extends Component {
pixels: undefined,
keyAcumulator: 1
};

this.onLoadComplete = (width, height) => this.setState({pixels: {width, height}});
}

componentWillMount() {
Expand All @@ -53,6 +55,10 @@ export default class TransformableImage extends Component {
}
}

componentWillUnmount() {
this.onLoadComplete = undefined;
}

componentWillReceiveProps(nextProps) {
if (!sameSource(this.props.source, nextProps.source)) {
//image source changed, clear last image's pixels info if any
Expand Down Expand Up @@ -151,7 +157,9 @@ export default class TransformableImage extends Component {
if(this.state.pixels && this.state.pixels.width === width && this.state.pixels.height === height) {
//no need to update state
} else {
this.setState({pixels: {width, height}});
if (typeof this.onLoadComplete === 'function') {
this.onLoadComplete(width, height);
}
}
}
},
Expand Down