Selaa lähdekoodia

Update android-specific-use-cases.md

Guy Carmeli 7 vuotta sitten
vanhempi
commit
2b182556c3
1 muutettua tiedostoa jossa 22 lisäystä ja 0 poistoa
  1. 22
    0
      docs/android-specific-use-cases.md

+ 22
- 0
docs/android-specific-use-cases.md Näytä tiedosto

@@ -304,5 +304,27 @@ When Shared Element Transition is used, a cross-fade transition is used between
304 304
 
305 305
 To disable the cross-fade animation, set `animated: false` when pushing the second screen. Disabling this animation is useful if you'd like to animate the reset of the elements on screen your self.
306 306
 
307
+## Compatibility with HeadlessJs
308
+In most cases, `Navigation.startSingleScreenApp()` or `Navigation.startTabBasedApp` are called from global context. If the bundle is parsed when the app is not running, this will result in the app opening even though the developer had no intent to open the app.
309
+
310
+`Navigation.startSingleScreenApp()` or `Navigation.startTabBasedApp` are called from global context since RNN assums react context isn't created when the app is launched. When a background task completes, react context is put into a **paused state** and not destroyed. Therefore we should also handle the use case where our app is opened when react context is created , and the bundle has already been parsed. We do that by listening to `RNN.AppLaunched` event.
311
+
312
+```js
313
+import {Navigation, NativeEventsReceiver} from 'react-native-navigation';
314
+
315
+Promise.resolve(Navigation.isAppLaunched())
316
+  .then(appLaunched => {
317
+    if (appLaunched) {
318
+      startApp(); // App is launched -> show UI
319
+    } else {
320
+      new NativeEventsReceiver().appLaunched(startApp); // App hasn't been launched yet -> show the UI only when needed.
321
+    }
322
+  });
323
+
324
+function startApp() {
325
+  Navigation.startTabBasedApp({ ... });
326
+}
327
+```
328
+
307 329
 ## Reloading from terminal
308 330
 You can easily reload your app from terminal using `adb shell am broadcast -a react.native.RELOAD`. This is particularly useful when debugging on device.