Переглянути джерело

[RN] Fix passing url prop to Root and App components

React (pun intended) to prop changes, that is, load the new specified URL.

In addition, fix a hidden bug in loading the initial URL from the linking
module: we prefer a prop to the URL the app was launched with, in case somehow
both are specified. We (the Jitsi Meet app) are not going to run into this
corner case, but let's be defensive just in case.
j8
Saúl Ibarra Corretgé 8 роки тому
джерело
коміт
cc9249ba1a
2 змінених файлів з 30 додано та 10 видалено
  1. 5
    0
      react/features/app/components/AbstractApp.js
  2. 25
    10
      react/index.native.js

+ 5
- 0
react/features/app/components/AbstractApp.js Переглянути файл

@@ -137,6 +137,11 @@ export class AbstractApp extends Component {
137 137
                 store: this._maybeCreateStore(nextProps)
138 138
             });
139 139
         }
140
+
141
+        // Deal with URL changes
142
+        if (typeof nextProps.url !== 'undefined') {
143
+            this._openURL(nextProps.url || this._getDefaultURL());
144
+        }
140 145
     }
141 146
 
142 147
     /**

+ 25
- 10
react/index.native.js Переглянути файл

@@ -56,18 +56,33 @@ class Root extends Component {
56 56
             url: this.props.url
57 57
         };
58 58
 
59
-        // Handle the URL, if any, with which the app was launched.
60
-        Linking.getInitialURL()
61
-            .then(url => this.setState({ url }))
62
-            .catch(err => {
63
-                console.error('Failed to get initial URL', err);
59
+        // Handle the URL the application was launched with, but props have
60
+        // precedence.
61
+        if (typeof this.props.url === 'undefined') {
62
+            Linking.getInitialURL()
63
+                .then(url => {
64
+                    this.setState({ url });
65
+                })
66
+                .catch(err => {
67
+                    console.error('Failed to get initial URL', err);
64 68
 
65
-                // XXX Start with an empty URL if getting the initial URL fails;
66
-                // otherwise, nothing will be rendered.
67
-                if (this.state.url !== null) {
69
+                    // Start with an empty URL if getting the initial URL fails
70
+                    // otherwise, nothing will be rendered.
68 71
                     this.setState({ url: null });
69
-                }
70
-            });
72
+                });
73
+        }
74
+    }
75
+
76
+    /**
77
+     * Implements React's {@link Component#componentWillReceiveProps()}.
78
+     *
79
+     * New props can be set from the native side by setting the appProperties
80
+     * property (on iOS) or calling setAppProperties (on Android).
81
+     *
82
+     * @inheritdoc
83
+     */
84
+    componentWillReceiveProps(nextProps) {
85
+        this.setState({ url: nextProps.url || null });
71 86
     }
72 87
 
73 88
     /**

Завантаження…
Відмінити
Зберегти