Files
react-native/Libraries/Experimental/IncrementalPresenter.js
James Ide 0ee5f68929 Migrate "Libraries" from Haste to standard path-based requires (sans vendor & renderers) (#24749)
Summary:
This is the next step in moving RN towards standard path-based requires. All the requires in `Libraries` have been rewritten to use relative requires with a few exceptions, namely, `vendor` and `Renderer/oss` since those need to be changed upstream. This commit uses relative requires instead of `react-native/...` so that if Facebook were to stop syncing out certain folders and therefore remove code from the react-native package, internal code at Facebook would not need to change.

See the umbrella issue at https://github.com/facebook/react-native/issues/24316 for more detail.

[General] [Changed] - Migrate "Libraries" from Haste to standard path-based requires
Pull Request resolved: https://github.com/facebook/react-native/pull/24749

Differential Revision: D15258017

Pulled By: cpojer

fbshipit-source-id: a1f480ea36c05c659b6f37c8f02f6f9216d5a323
2019-05-08 08:48:59 -07:00

98 lines
2.7 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 IncrementalGroup = require('./IncrementalGroup');
const PropTypes = require('prop-types');
const React = require('react');
const View = require('../Components/View/View');
import type {Context} from './Incremental';
import type {ViewStyleProp} from '../StyleSheet/StyleSheet';
import type {LayoutEvent} from '../Types/CoreEventTypes';
/**
* 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
* descendants have finished rendering, at which point they are drawn all at once
* so the UI doesn't jump around during the incremental rendering process.
*
* See Incremental.js for more info.
*/
type Props = $ReadOnly<{|
name: string,
disabled?: boolean,
onDone?: () => mixed,
onLayout?: (event: LayoutEvent) => mixed,
style?: ViewStyleProp,
children?: React.Node,
|}>;
class IncrementalPresenter extends React.Component<Props> {
context: Context;
_isDone: boolean;
static contextTypes = {
incrementalGroup: PropTypes.object,
incrementalGroupEnabled: PropTypes.bool,
};
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() {
let style: ViewStyleProp;
if (
this.props.disabled !== true &&
this.context.incrementalGroupEnabled !== false &&
!this._isDone
) {
style = [this.props.style, {opacity: 0, position: 'absolute'}];
} else {
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;