2016-03-10 16:12:34 +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-03-10 16:12:34 +00:00
|
|
|
*
|
|
|
|
* @providesModule IncrementalPresenter
|
|
|
|
* @flow
|
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const IncrementalGroup = require('IncrementalGroup');
|
|
|
|
const React = require('React');
|
2017-04-12 23:09:48 +00:00
|
|
|
const PropTypes = require('prop-types');
|
2016-03-10 16:12:34 +00:00
|
|
|
const View = require('View');
|
|
|
|
|
2017-03-24 07:22:57 +00:00
|
|
|
const ViewPropTypes = require('ViewPropTypes');
|
|
|
|
|
2016-03-10 16:12:34 +00:00
|
|
|
import type {Context} from 'Incremental';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* WARNING: EXPERIMENTAL. Breaking changes will probably happen a lot and will
|
|
|
|
* not be reliably announced. The whole thing might be deleted, who knows? Use
|
|
|
|
* at your own risk.
|
|
|
|
*
|
|
|
|
* `<IncrementalPresenter>` can be used to group sets of `<Incremental>` renders
|
|
|
|
* such that they are initially invisible and removed from layout until all
|
2018-01-13 06:03:51 +00:00
|
|
|
* descendants have finished rendering, at which point they are drawn all at once
|
2016-03-10 16:12:34 +00:00
|
|
|
* so the UI doesn't jump around during the incremental rendering process.
|
|
|
|
*
|
|
|
|
* See Incremental.js for more info.
|
|
|
|
*/
|
|
|
|
type Props = {
|
2016-08-09 13:32:41 +00:00
|
|
|
name: string,
|
|
|
|
disabled?: boolean,
|
|
|
|
onDone?: () => void,
|
|
|
|
onLayout?: (event: Object) => void,
|
|
|
|
style?: mixed,
|
|
|
|
children?: any,
|
2016-03-10 16:12:34 +00:00
|
|
|
}
|
2017-08-18 01:36:54 +00:00
|
|
|
class IncrementalPresenter extends React.Component<Props> {
|
2016-03-10 16:12:34 +00:00
|
|
|
context: Context;
|
|
|
|
_isDone: boolean;
|
2016-04-22 02:46:36 +00:00
|
|
|
|
|
|
|
static propTypes = {
|
2017-04-12 23:09:48 +00:00
|
|
|
name: PropTypes.string,
|
|
|
|
disabled: PropTypes.bool,
|
|
|
|
onDone: PropTypes.func,
|
|
|
|
onLayout: PropTypes.func,
|
2017-03-24 07:22:57 +00:00
|
|
|
style: ViewPropTypes.style,
|
2016-04-22 02:46:36 +00:00
|
|
|
};
|
|
|
|
static contextTypes = {
|
2017-04-12 23:09:48 +00:00
|
|
|
incrementalGroup: PropTypes.object,
|
|
|
|
incrementalGroupEnabled: PropTypes.bool,
|
2016-04-22 02:46:36 +00:00
|
|
|
};
|
|
|
|
|
2016-03-10 16:12:34 +00:00
|
|
|
constructor(props: Props, context: Context) {
|
|
|
|
super(props, context);
|
|
|
|
this._isDone = false;
|
|
|
|
(this: any).onDone = this.onDone.bind(this);
|
|
|
|
}
|
|
|
|
onDone() {
|
|
|
|
this._isDone = true;
|
|
|
|
if (this.props.disabled !== true &&
|
|
|
|
this.context.incrementalGroupEnabled !== false) {
|
|
|
|
// Avoid expensive re-renders and use setNativeProps
|
|
|
|
this.refs.view.setNativeProps(
|
|
|
|
{style: [this.props.style, {opacity: 1, position: 'relative'}]}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
this.props.onDone && this.props.onDone();
|
|
|
|
}
|
|
|
|
render() {
|
|
|
|
if (this.props.disabled !== true &&
|
|
|
|
this.context.incrementalGroupEnabled !== false &&
|
|
|
|
!this._isDone) {
|
|
|
|
var style = [this.props.style, {opacity: 0, position: 'absolute'}];
|
|
|
|
} else {
|
|
|
|
var style = this.props.style;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<IncrementalGroup
|
|
|
|
onDone={this.onDone}
|
|
|
|
name={this.props.name}
|
|
|
|
disabled={this.props.disabled}>
|
|
|
|
<View
|
|
|
|
children={this.props.children}
|
|
|
|
ref="view"
|
|
|
|
style={style}
|
|
|
|
onLayout={this.props.onLayout}
|
|
|
|
/>
|
|
|
|
</IncrementalGroup>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = IncrementalPresenter;
|