Sfoglia il codice sorgente

[RN] NetworkActivityIndicator

The basic indicator is extracted into a LoadingIndicator component,
which then NetworkActivityIndicator displays (or not) based on network
activity.
master
Saúl Ibarra Corretgé 8 anni fa
parent
commit
35da39becf

+ 0
- 1
react/features/app/components/App.native.js Vedi File

@@ -10,7 +10,6 @@ import '../../mobile/audio-mode';
10 10
 import '../../mobile/background';
11 11
 import '../../mobile/external-api';
12 12
 import '../../mobile/full-screen';
13
-import '../../mobile/network-activity';
14 13
 import '../../mobile/permissions';
15 14
 import '../../mobile/proximity';
16 15
 import '../../mobile/wake-lock';

+ 24
- 0
react/features/base/react/components/native/LoadingIndicator.js Vedi File

@@ -0,0 +1,24 @@
1
+/* @flow */
2
+
3
+import React, { Component } from 'react';
4
+import { ActivityIndicator } from 'react-native';
5
+
6
+/**
7
+ * Simple wrapper around React Native's {@code ActivityIndicator}, which
8
+ * displays an animated (large) loading indicator.
9
+ */
10
+export default class LoadingIndicator extends Component {
11
+    /**
12
+     * Implements React's {@link Component#render()}.
13
+     *
14
+     * @inheritdoc
15
+     * @returns {ReactElement}
16
+     */
17
+    render() {
18
+        return (
19
+            <ActivityIndicator
20
+                animating = { true }
21
+                size = { 'large' } />
22
+        );
23
+    }
24
+}

+ 1
- 0
react/features/base/react/components/native/index.js Vedi File

@@ -1,3 +1,4 @@
1 1
 export { default as Container } from './Container';
2 2
 export { default as Link } from './Link';
3
+export { default as LoadingIndicator } from './LoadingIndicator';
3 4
 export { default as Text } from './Text';

+ 58
- 0
react/features/mobile/network-activity/components/NetworkActivityIndicator.js Vedi File

@@ -0,0 +1,58 @@
1
+/* @flow */
2
+
3
+import PropTypes from 'prop-types';
4
+import React, { Component } from 'react';
5
+import { connect } from 'react-redux';
6
+
7
+import { LoadingIndicator } from '../../../base/react';
8
+
9
+/**
10
+ * The React <tt>Component</tt> which renders a progress indicator when there
11
+ * are ongoing network requests.
12
+ */
13
+class NetworkActivityIndicator extends Component {
14
+    /**
15
+     * <tt>NetworkActivityIndicator</tt> React <tt>Component</tt>'s prop types.
16
+     *
17
+     * @static
18
+     */
19
+    static propTypes = {
20
+        /**
21
+         * Indicates whether there is network activity i.e. ongoing network
22
+         * requests.
23
+         *
24
+         * @private
25
+         */
26
+        _networkActivity: PropTypes.bool
27
+    };
28
+
29
+    /**
30
+     * Implements React's {@link Component#render()}.
31
+     *
32
+     * @inheritdoc
33
+     * @returns {ReactElement}
34
+     */
35
+    render() {
36
+        return this.props._networkActivity ? <LoadingIndicator /> : null;
37
+    }
38
+}
39
+
40
+/**
41
+ * Maps (parts of) the redux state to the React <tt>Component</tt> props of
42
+ * <tt>NetworkActivityIndicator</tt>.
43
+ *
44
+ * @param {Object} state - The redux state.
45
+ * @private
46
+ * @returns {{
47
+ *     _networkActivity: boolean
48
+ * }}
49
+ */
50
+function _mapStateToProps(state) {
51
+    const { requests } = state['features/network-activity'];
52
+
53
+    return {
54
+        _networkActivity: Boolean(requests && requests.size)
55
+    };
56
+}
57
+
58
+export default connect(_mapStateToProps)(NetworkActivityIndicator);

+ 3
- 0
react/features/mobile/network-activity/components/index.js Vedi File

@@ -0,0 +1,3 @@
1
+export {
2
+    default as NetworkActivityIndicator
3
+} from './NetworkActivityIndicator';

+ 2
- 0
react/features/mobile/network-activity/index.js Vedi File

@@ -1,2 +1,4 @@
1
+export * from './components';
2
+
1 3
 import './middleware';
2 4
 import './reducer';

+ 2
- 18
react/features/welcome/components/BlankPage.native.js Vedi File

@@ -2,10 +2,10 @@
2 2
 
3 3
 import PropTypes from 'prop-types';
4 4
 import React, { Component } from 'react';
5
-import { ActivityIndicator } from 'react-native';
6 5
 import { connect } from 'react-redux';
7 6
 
8 7
 import { destroyLocalTracks } from '../../base/tracks';
8
+import { NetworkActivityIndicator } from '../../mobile/network-activity';
9 9
 
10 10
 import { isWelcomePageAppEnabled } from '../functions';
11 11
 import LocalVideoTrackUnderlay from './LocalVideoTrackUnderlay';
@@ -23,14 +23,6 @@ class BlankPage extends Component {
23 23
      * @static
24 24
      */
25 25
     static propTypes = {
26
-        /**
27
-         * Indicates whether there is network activity i.e. ongoing network
28
-         * requests.
29
-         *
30
-         * @private
31
-         */
32
-        _networkActivity: PropTypes.bool,
33
-
34 26
         /**
35 27
          * The indicator which determines whether <tt>WelcomePage</tt> is (to
36 28
          * be) rendered.
@@ -58,15 +50,12 @@ class BlankPage extends Component {
58 50
      * Implements React's {@link Component#render()}.
59 51
      *
60 52
      * @inheritdoc
61
-     * @override
62 53
      * @returns {ReactElement}
63 54
      */
64 55
     render() {
65 56
         return (
66 57
             <LocalVideoTrackUnderlay style = { styles.blankPage }>
67
-                <ActivityIndicator
68
-                    animating = { this.props._networkActivity }
69
-                    size = { 'large' } />
58
+                <NetworkActivityIndicator />
70 59
             </LocalVideoTrackUnderlay>
71 60
         );
72 61
     }
@@ -79,16 +68,11 @@ class BlankPage extends Component {
79 68
  * @param {Object} state - The redux state.
80 69
  * @private
81 70
  * @returns {{
82
- *     _networkActivity: boolean,
83 71
  *     _welcomePageEnabled: boolean
84 72
  * }}
85 73
  */
86 74
 function _mapStateToProps(state) {
87
-    const { requests } = state['features/network-activity'];
88
-
89 75
     return {
90
-        _networkActivity:
91
-            Boolean(requests && (requests.length || requests.size)),
92 76
         _welcomePageEnabled: isWelcomePageAppEnabled(state)
93 77
     };
94 78
 }

Loading…
Annulla
Salva