Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// @flow
import React, { Component } from "react";
import { Dimensions } from "react-native";
type DimensionsState = { window: { width: number, height: number } };
type Props = {
children: (dimensions: DimensionsState) => React.Element<*>
};
export class WithDimensions extends Component {
state: DimensionsState;
props: Props;
constructor() {
super();
this.state = {
window: Dimensions.get("window")
};
}
_change = ({ window }: *) => {
this.setState({ window });
};
componentDidMount() {
Dimensions.addEventListener("change", this._change);
}
componentWillUnmount() {
Dimensions.removeEventListener("change", this._change);
}
render() {
return this.props.children(this.state);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.