|
@@ -10,15 +10,12 @@
|
10
|
10
|
// collect the polyfills' files.
|
11
|
11
|
import './features/base/lib-jitsi-meet/native/polyfills-bundler';
|
12
|
12
|
|
13
|
|
-import React, { Component } from 'react';
|
14
|
|
-import { AppRegistry, Linking, NativeModules } from 'react-native';
|
|
13
|
+import React, { PureComponent } from 'react';
|
|
14
|
+import { AppRegistry } from 'react-native';
|
15
|
15
|
|
16
|
16
|
import { App } from './features/app';
|
17
|
|
-import { equals } from './features/base/redux';
|
18
|
17
|
import { IncomingCallApp } from './features/mobile/incoming-call';
|
19
|
18
|
|
20
|
|
-const logger = require('jitsi-meet-logger').getLogger(__filename);
|
21
|
|
-
|
22
|
19
|
/**
|
23
|
20
|
* The type of the React {@code Component} props of {@link Root}.
|
24
|
21
|
*/
|
|
@@ -30,17 +27,6 @@ type Props = {
|
30
|
27
|
url: Object | string
|
31
|
28
|
};
|
32
|
29
|
|
33
|
|
-/**
|
34
|
|
- * The type of the React {@code Component} state of {@link Root}.
|
35
|
|
- */
|
36
|
|
-type State = {
|
37
|
|
-
|
38
|
|
- /**
|
39
|
|
- * The URL, if any, with which the app was launched.
|
40
|
|
- */
|
41
|
|
- url: ?Object | string
|
42
|
|
-};
|
43
|
|
-
|
44
|
30
|
/**
|
45
|
31
|
* React Native doesn't support specifying props to the main/root component (in
|
46
|
32
|
* the JS/JSX source code). So create a wrapper React Component (class) around
|
|
@@ -48,82 +34,7 @@ type State = {
|
48
|
34
|
*
|
49
|
35
|
* @extends Component
|
50
|
36
|
*/
|
51
|
|
-class Root extends Component<Props, State> {
|
52
|
|
- /**
|
53
|
|
- * Initializes a new {@code Root} instance.
|
54
|
|
- *
|
55
|
|
- * @param {Props} props - The read-only properties with which the new
|
56
|
|
- * instance is to be initialized.
|
57
|
|
- */
|
58
|
|
- constructor(props) {
|
59
|
|
- super(props);
|
60
|
|
-
|
61
|
|
- this.state = {
|
62
|
|
- url: this.props.url
|
63
|
|
- };
|
64
|
|
-
|
65
|
|
- // Handle the URL, if any, with which the app was launched. But props
|
66
|
|
- // have precedence.
|
67
|
|
- if (typeof this.props.url === 'undefined') {
|
68
|
|
- this._getInitialURL()
|
69
|
|
- .then(url => {
|
70
|
|
- if (typeof this.state.url === 'undefined') {
|
71
|
|
- this.setState({ url });
|
72
|
|
- }
|
73
|
|
- })
|
74
|
|
- .catch(err => {
|
75
|
|
- logger.error('Failed to get initial URL', err);
|
76
|
|
-
|
77
|
|
- if (typeof this.state.url === 'undefined') {
|
78
|
|
- // Start with an empty URL if getting the initial URL
|
79
|
|
- // fails; otherwise, nothing will be rendered.
|
80
|
|
- this.setState({ url: null });
|
81
|
|
- }
|
82
|
|
- });
|
83
|
|
- }
|
84
|
|
- }
|
85
|
|
-
|
86
|
|
- /**
|
87
|
|
- * Gets the initial URL the app was launched with. This can be a universal
|
88
|
|
- * (or deep) link, or a CallKit intent in iOS. Since the native
|
89
|
|
- * {@code Linking} module doesn't provide a way to access intents in iOS,
|
90
|
|
- * those are handled with the {@code LaunchOptions} module, which
|
91
|
|
- * essentially provides a replacement which takes that into consideration.
|
92
|
|
- *
|
93
|
|
- * @private
|
94
|
|
- * @returns {Promise} - A promise which will be fulfilled with the URL that
|
95
|
|
- * the app was launched with.
|
96
|
|
- */
|
97
|
|
- _getInitialURL() {
|
98
|
|
- if (NativeModules.LaunchOptions) {
|
99
|
|
- return NativeModules.LaunchOptions.getInitialURL();
|
100
|
|
- }
|
101
|
|
-
|
102
|
|
- return Linking.getInitialURL();
|
103
|
|
- }
|
104
|
|
-
|
105
|
|
- /**
|
106
|
|
- * Implements React's {@link Component#componentDidUpdate()}.
|
107
|
|
- *
|
108
|
|
- * New props can be set from the native side by setting the appProperties
|
109
|
|
- * property (on iOS) or calling setAppProperties (on Android).
|
110
|
|
- *
|
111
|
|
- * @inheritdoc
|
112
|
|
- */
|
113
|
|
- componentDidUpdate(prevProps, prevState) {
|
114
|
|
- // Ignore the special state update triggered on {@code Root}
|
115
|
|
- // instantiation where an undefined url prop is set to a default.
|
116
|
|
- if (typeof prevState.url === 'undefined'
|
117
|
|
- && typeof this.state.url !== 'undefined') {
|
118
|
|
- return;
|
119
|
|
- }
|
120
|
|
-
|
121
|
|
- if (!equals(prevProps.url, this.props.url)) {
|
122
|
|
- // eslint-disable-next-line react/no-did-update-set-state
|
123
|
|
- this.setState({ url: this.props.url || null });
|
124
|
|
- }
|
125
|
|
- }
|
126
|
|
-
|
|
37
|
+class Root extends PureComponent<Props> {
|
127
|
38
|
/**
|
128
|
39
|
* Implements React's {@link Component#render()}.
|
129
|
40
|
*
|
|
@@ -131,26 +42,9 @@ class Root extends Component<Props, State> {
|
131
|
42
|
* @returns {ReactElement}
|
132
|
43
|
*/
|
133
|
44
|
render() {
|
134
|
|
- const { url } = this.state;
|
135
|
|
-
|
136
|
|
- // XXX We don't render the App component until we get the initial URL.
|
137
|
|
- // Either it's null or some other non-null defined value.
|
138
|
|
- if (typeof url === 'undefined') {
|
139
|
|
- return null;
|
140
|
|
- }
|
141
|
|
-
|
142
|
|
- const {
|
143
|
|
- // The following props are forked in state:
|
144
|
|
- url: _, // eslint-disable-line no-unused-vars
|
145
|
|
-
|
146
|
|
- // The remaining props are passed through to App.
|
147
|
|
- ...props
|
148
|
|
- } = this.props;
|
149
|
|
-
|
150
|
45
|
return (
|
151
|
46
|
<App
|
152
|
|
- { ...props }
|
153
|
|
- url = { url } />
|
|
47
|
+ { ...this.props } />
|
154
|
48
|
);
|
155
|
49
|
}
|
156
|
50
|
}
|