fbshipit-source-id: b6fc29740c6875d2e78953b8a7123890a67930f2 Co-authored-by: Sebastian McKenzie <sebmck@fb.com> Co-authored-by: John Knox <jknox@fb.com> Co-authored-by: Emil Sjölander <emilsj@fb.com> Co-authored-by: Pritesh Nandgaonkar <prit91@fb.com>
45 lines
1.0 KiB
JavaScript
45 lines
1.0 KiB
JavaScript
/**
|
|
* Copyright 2018-present Facebook.
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
* @format
|
|
*/
|
|
|
|
import {Component} from 'react';
|
|
|
|
type ViewWithSizeProps = {
|
|
onSize: (width: number, height: number) => any,
|
|
};
|
|
|
|
type ViewWithSizeState = {|
|
|
width: number,
|
|
height: number,
|
|
|};
|
|
|
|
export default class ViewWithSize extends Component<
|
|
ViewWithSizeProps,
|
|
ViewWithSizeState,
|
|
> {
|
|
constructor(props: ViewWithSizeProps, context: Object) {
|
|
super(props, context);
|
|
this.state = {height: window.innerHeight, width: window.innerWidth};
|
|
}
|
|
|
|
_onResize: Function;
|
|
|
|
componentDidMount() {
|
|
this._onResize = () => {
|
|
this.setState({height: window.innerHeight, width: window.innerWidth});
|
|
};
|
|
window.addEventListener('resize', this._onResize);
|
|
}
|
|
|
|
componentWillUnmount() {
|
|
window.removeEventListener('resize', this._onResize);
|
|
}
|
|
|
|
render() {
|
|
return this.props.onSize(this.state.width, this.state.height);
|
|
}
|
|
}
|