Files
react-native/RNTester/js/DimensionsExample.js
James Ide 26cce3d7a8 Rewrite imports in RNTester to use standard paths (#24317)
Summary:
See https://github.com/facebook/react-native/issues/24316 for the motivation. This commit rewrites the imports in the RNTester project.

[General] [Changed] - Replaced Haste-style imports with standard path-style imports for RNTester
Pull Request resolved: https://github.com/facebook/react-native/pull/24317

Differential Revision: D14870504

Pulled By: cpojer

fbshipit-source-id: b14f22e7ce559efc332ced032617ca581196d90f
2019-04-10 10:20:25 -07:00

63 lines
1.3 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
* @flow
*/
'use strict';
const React = require('react');
const {Dimensions, Text, View} = require('react-native');
class DimensionsSubscription extends React.Component<
{dim: string},
{dims: Object},
> {
state = {
dims: Dimensions.get(this.props.dim),
};
componentDidMount() {
Dimensions.addEventListener('change', this._handleDimensionsChange);
}
componentWillUnmount() {
Dimensions.removeEventListener('change', this._handleDimensionsChange);
}
_handleDimensionsChange = dimensions => {
this.setState({
dims: dimensions[this.props.dim],
});
};
render() {
return (
<View>
<Text>{JSON.stringify(this.state.dims)}</Text>
</View>
);
}
}
exports.title = 'Dimensions';
exports.description = 'Dimensions of the viewport';
exports.examples = [
{
title: 'window',
render(): React.Element<any> {
return <DimensionsSubscription dim="window" />;
},
},
{
title: 'screen',
render(): React.Element<any> {
return <DimensionsSubscription dim="screen" />;
},
},
];