2018-02-18 02:00:56 +00:00
|
|
|
import React from "react";
|
|
|
|
import PropTypes from "prop-types";
|
|
|
|
import addEvent from "./utils/addEvent";
|
|
|
|
import removeEvent from "./utils/removeEvent";
|
2017-03-26 06:53:54 +00:00
|
|
|
|
2018-02-18 02:00:56 +00:00
|
|
|
const ResizeEvent = "resize";
|
2017-03-26 06:53:54 +00:00
|
|
|
|
|
|
|
class WindowSize extends React.Component {
|
|
|
|
static propTypes = {
|
|
|
|
onChange: PropTypes.func
|
2018-02-18 02:00:56 +00:00
|
|
|
};
|
2017-03-26 06:53:54 +00:00
|
|
|
|
|
|
|
handleWindowResize = () => {
|
|
|
|
if (this.props.onChange)
|
|
|
|
this.props.onChange({
|
|
|
|
width: window.innerWidth,
|
|
|
|
height: window.innerHeight
|
2018-02-18 02:00:56 +00:00
|
|
|
});
|
|
|
|
};
|
2017-03-26 06:53:54 +00:00
|
|
|
|
|
|
|
componentDidMount() {
|
2018-02-18 02:00:56 +00:00
|
|
|
addEvent(window, ResizeEvent, this.handleWindowResize);
|
2017-03-26 06:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
componentWillUnmount() {
|
2018-02-18 02:00:56 +00:00
|
|
|
removeEvent(window, ResizeEvent, this.handleWindowResize);
|
2017-03-26 06:53:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
2018-02-18 02:00:56 +00:00
|
|
|
return null;
|
2017-03-26 06:53:54 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-18 02:00:56 +00:00
|
|
|
export default WindowSize;
|