1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | 'use strict';
|
12 |
|
13 | const IncrementalGroup = require('./IncrementalGroup');
|
14 | const PropTypes = require('prop-types');
|
15 | const React = require('react');
|
16 | const View = require('../Components/View/View');
|
17 |
|
18 | import type {ViewStyleProp} from '../StyleSheet/StyleSheet';
|
19 | import type {LayoutEvent} from '../Types/CoreEventTypes';
|
20 | import type {Context} from './Incremental';
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 | type Props = $ReadOnly<{|
|
35 | name: string,
|
36 | disabled?: boolean,
|
37 | onDone?: () => mixed,
|
38 | onLayout?: (event: LayoutEvent) => mixed,
|
39 | style?: ViewStyleProp,
|
40 | children?: React.Node,
|
41 | |}>;
|
42 |
|
43 | class IncrementalPresenter extends React.Component<Props> {
|
44 | context: Context;
|
45 | _isDone: boolean;
|
46 |
|
47 | static contextTypes:
|
48 | | any
|
49 | | $TEMPORARY$object<{|
|
50 | incrementalGroup: React$PropType$Primitive<any>,
|
51 | incrementalGroupEnabled: React$PropType$Primitive<boolean>,
|
52 | |}> = {
|
53 | incrementalGroup: PropTypes.object,
|
54 | incrementalGroupEnabled: PropTypes.bool,
|
55 | };
|
56 |
|
57 | constructor(props: Props, context: Context) {
|
58 | super(props, context);
|
59 | this._isDone = false;
|
60 | (this: any).onDone = this.onDone.bind(this);
|
61 | }
|
62 | onDone() {
|
63 | this._isDone = true;
|
64 | if (
|
65 | this.props.disabled !== true &&
|
66 | this.context.incrementalGroupEnabled !== false
|
67 | ) {
|
68 |
|
69 | this.refs.view.setNativeProps({
|
70 | style: [this.props.style, {opacity: 1, position: 'relative'}],
|
71 | });
|
72 | }
|
73 | this.props.onDone && this.props.onDone();
|
74 | }
|
75 | render(): React.Node {
|
76 | let style: ViewStyleProp;
|
77 | if (
|
78 | this.props.disabled !== true &&
|
79 | this.context.incrementalGroupEnabled !== false &&
|
80 | !this._isDone
|
81 | ) {
|
82 | style = [this.props.style, {opacity: 0, position: 'absolute'}];
|
83 | } else {
|
84 | style = this.props.style;
|
85 | }
|
86 | return (
|
87 | <IncrementalGroup
|
88 | onDone={this.onDone}
|
89 | name={this.props.name}
|
90 | disabled={this.props.disabled}>
|
91 | <View
|
92 | children={this.props.children}
|
93 | ref="view"
|
94 | style={style}
|
95 | onLayout={this.props.onLayout}
|
96 | />
|
97 | </IncrementalGroup>
|
98 | );
|
99 | }
|
100 | }
|
101 |
|
102 | module.exports = IncrementalPresenter;
|