UNPKG

react-native-web-hooks

Version:
35 lines 1.14 kB
import * as React from 'react'; import { element, func, oneOfType, oneOf } from 'prop-types'; import { Dimensions } from 'react-native'; export default class Resizable extends React.Component { constructor(props) { super(props); this.resize = props => { const { [this.props.target]: target = {} } = props; this.setState(state => ({ ...state, ...target })); }; this.state = { ...Dimensions.get(props.target), }; } componentDidMount() { Dimensions.addEventListener('change', this.resize); } componentWillUnmount() { Dimensions.removeEventListener('change', this.resize); } render() { const { children } = this.props; const child = typeof children === 'function' ? children(this.state) : children; return React.cloneElement(React.Children.only(child), {}); } } Resizable.displayName = 'Resizable'; Resizable.propTypes = { children: oneOfType([func, element]), target: oneOf(['window', 'screen']), }; Resizable.defaultProps = { target: 'window', }; //# sourceMappingURL=Resizable.js.map