Skip to content

Commit 94a2bb8

Browse files
committed
View component support renderDelay prop for delaying rendering content
1 parent 873b6d5 commit 94a2bb8

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

generatedTypes/components/view/index.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ export interface ViewPropTypes extends ViewProps, ContainerModifiers {
2222
* TODO: probobly isn't needed
2323
*/
2424
height?: string | number;
25+
/**
26+
* Experimental: Pass time in ms to delay render
27+
*/
28+
renderDelay?: number;
2529
}
2630
declare const _default: React.ComponentClass<ViewPropTypes, any> | React.FunctionComponent<ViewPropTypes>;
2731
export default _default;

src/components/view/index.tsx

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,47 @@ export interface ViewPropTypes extends ViewProps, ContainerModifiers {
2424
* TODO: probobly isn't needed
2525
*/
2626
height?: string | number;
27+
/**
28+
* Experimental: Pass time in ms to delay render
29+
*/
30+
renderDelay?: number;
2731
}
2832
type PropsTypes = BaseComponentInjectedProps & ForwardRefInjectedProps & ViewPropTypes;
2933

34+
interface ViewState {
35+
ready: boolean;
36+
}
37+
3038
/**
3139
* @description: An enhanced View component
3240
* @extends: View
3341
* @extendslink: https://facebook.github.io/react-native/docs/view.html
3442
* @modifiers: margins, paddings, alignments, background, borderRadius
3543
*/
36-
class View extends PureComponent<PropsTypes> {
44+
class View extends PureComponent<PropsTypes, ViewState> {
3745
static displayName = 'View';
3846
private Container: React.ClassType<any, any, any>;
47+
3948
constructor(props: PropsTypes) {
4049
super(props);
4150

4251
this.Container = props.useSafeArea && Constants.isIOS ? SafeAreaView : RNView;
4352
if (props.animated) {
4453
this.Container = Animated.createAnimatedComponent(this.Container);
4554
}
55+
56+
this.state = {
57+
ready: !props.renderDelay
58+
};
59+
}
60+
61+
componentDidMount() {
62+
const {renderDelay} = this.props;
63+
if (renderDelay) {
64+
setTimeout(() => {
65+
this.setState({ready: true});
66+
}, renderDelay);
67+
}
4668
}
4769

4870
// TODO: do we need this?
@@ -52,6 +74,10 @@ class View extends PureComponent<PropsTypes> {
5274
}
5375

5476
render() {
77+
if (!this.state.ready) {
78+
return null;
79+
}
80+
5581
// (!) extract left, top, bottom... props to avoid passing them on Android
5682
// eslint-disable-next-line
5783
const {

0 commit comments

Comments
 (0)