2016-04-17 22:03:43 +00:00
|
|
|
/**
|
|
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
|
|
*
|
2018-02-17 02:24:55 +00:00
|
|
|
* This source code is licensed under the MIT license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree.
|
2016-04-17 22:03:43 +00:00
|
|
|
*
|
|
|
|
* @providesModule LazyRenderer
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2018-03-03 23:04:46 +00:00
|
|
|
const React = require('React');
|
|
|
|
const createReactClass = require('create-react-class');
|
|
|
|
const PropTypes = require('prop-types');
|
|
|
|
const TimerMixin = require('react-timer-mixin');
|
2016-04-17 22:03:43 +00:00
|
|
|
|
2018-03-03 23:04:46 +00:00
|
|
|
const LazyRenderer = createReactClass({
|
2017-07-07 21:24:25 +00:00
|
|
|
displayName: 'LazyRenderer',
|
2016-04-17 22:03:43 +00:00
|
|
|
mixin: [TimerMixin],
|
|
|
|
|
|
|
|
propTypes: {
|
2017-04-12 23:09:48 +00:00
|
|
|
render: PropTypes.func.isRequired,
|
2016-04-17 22:03:43 +00:00
|
|
|
},
|
|
|
|
|
2018-02-08 18:26:45 +00:00
|
|
|
UNSAFE_componentWillMount: function(): void {
|
2016-04-17 22:03:43 +00:00
|
|
|
this.setState({
|
|
|
|
_lazyRender : true,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
componentDidMount: function(): void {
|
|
|
|
requestAnimationFrame(() => {
|
|
|
|
this.setState({
|
|
|
|
_lazyRender : false,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2016-10-14 15:53:57 +00:00
|
|
|
render: function(): ?React.Element {
|
2016-04-17 22:03:43 +00:00
|
|
|
return this.state._lazyRender ? null : this.props.render();
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = LazyRenderer;
|