diff --git a/.github/workflows/nodejs.yml b/.github/workflows/nodejs.yml new file mode 100644 index 0000000..b15baf3 --- /dev/null +++ b/.github/workflows/nodejs.yml @@ -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 diff --git a/library/TransformableImage.js b/library/TransformableImage.js index eb20941..8dc7b38 100644 --- a/library/TransformableImage.js +++ b/library/TransformableImage.js @@ -45,6 +45,8 @@ export default class TransformableImage extends Component { pixels: undefined, keyAcumulator: 1 }; + + this.onLoadComplete = (width, height) => this.setState({pixels: {width, height}}); } componentWillMount() { @@ -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 @@ -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); + } } } },