React Navigation 6.x => Listen to any Screen event from any Navigator (root and nested ones) - react-navigation

I'm using reaxt-navigation 6 in a react-native 0.68 project:
"#react-navigation/bottom-tabs": "6.3.1",
"#react-navigation/drawer": "6.4.1",
"#react-navigation/native": "6.0.10",
"#react-navigation/stack": "6.2.1",
We can listen to "screen scoped" events from inside a screen quite easily with props.navigation.addEventListener from inside a screen.
Is there a way to listen "globally" for any screen event with only one addEventListener call (from outside any screen) ?

Related

How to hide TimePicker and DatePicker on lifecycle events in Xamarin Forms

I'm running into an issue on android where our TimePicker and DatePicker stay visible when we navigate OnPause(). We need to redirect our users back to the login screen when they background the application, but if the TimePicker or DatePicker is active when they do this it stays on the screen. It appears above the login screen and pressing cancel or ok crashes the app.
We are hooking into the native android lifecycle events (not just using Xamarins built in hooks) and we redirect OnResume(). I've tested this in a barebones app though and it still happens OnPause().
Here is our TimePicker causing us the issue:
<TimePicker x:Name="VitalTimePicker" HorizontalOptions="Fill" VerticalOptions="Fill" IsVisible="false" PropertyChanged="OnTimePickerPropertyChanged"/>
And here is an example of changing screens on a lifecycle event:
protected override void OnSleep()
{
App.Current.MainPage = new NavigationPage(new NotesPage());
}
Any ideas? I was thinking of clearing the Pickers but I can't seem to find how to do that
Edit
Just to add a little more context
The Application class (app.xaml.cs) has lifecycle hooks that we use to catch when our users background the app. In here we call MainPage = new NavigationPage(new LoginPage()); which takes the app back to the login page.
I've added
protected override void OnDisappearing()
{
VitalTimePicker.Unfocus();
VitalDatePicker.Unfocus();
}
to the view i'm working from and it seems to be called when we background the application, but for some reason the TimePicker is staying on the screen when our login page pops up again.
You can programmatically close DatePickers and TimePickers using the method Unfocus(). I'd recommend closing them before you call the next page, as I don't know if they will be able to be referenced and closed after the other screen has been initialized.
Create a method that calls VitalTimePicker.Unfocus() and the same for any other picker you have, and call this method before changing to login screen and you should be good to go.

Application lifecycle test when togging system menus: screen goes black when onvisibilityChange:hidden

I am integrating youtube on cobalt 11. And now I'm testing the application lifecycle test.
I send the suspend event when I push the menu button (youtube goes to background)
I send the unpause event when I switch back to youtube. (youtube comes to foreground)
I send the deepLinke event after the unpause event
Sequence of events:
window.onfocus
window.onblur
....................?launch=remote
window.onfocus
..................:visible
onvisibilityChange:hidden
window.onblur
visible
When onvisibilityChange:hidden, youtube goes to the background; is that right?
This makes the screen turn black.
And why 1. window.onfocus and 2. window.onblur occur again after youtube has already resumed?
If you send the kSbEventTypeSuspend event, then Cobalt will assume that it is hidden and stop rendering to the display. If Cobalt is meant to remain visible, then do not send the kSbEventTypeSuspend event, instead you can send the kSbEventTypePause event. See the Cobalt lifecycle document for more information: https://cobalt.googlesource.com/cobalt/+/release_11/src/cobalt/doc/lifecycle.md .

The equivalent to onResume() in Windows Phone 7

I'm looking for some app life cycle help from the wp7 experts. My app has a refresh step in a specific page but I only want to launch this when the user brings the app to life from the background.
Note- The life cycle step I'm looking for isn't called when the page is init() only when I'm navigated (back) to or the user has taken a phone call and then re-opens the app (keeping the same page open)
Thank you in advance
what you are looking for is called Tombstoning and you can find a great article at http://wildermuth.com/2010/10/17/Architecting_WP7_-_Part_5_of_10_Tombstoning
The events are:
Launching (opened from tile)
Deactivated (user takes a call or something)
Activated (back from the call)
Closing (Leaves you app via the "Back" button)
You are looking for the Activated event. These are in your App.xaml.cs/vb file. Hook into the event, and update your data model. When your page is bound to that model it will get the data.
If you are not using MVVM, and can't really refresh from that event, you can do it using the PhoneApplicationService.Current.StartupMode property. It has two options Activate (what you are looking for) and Launch (loaded fresh from the tile). It would look something like
Init()
{
if (PhoneApplicationService.Current.StartupMode == StartupMode.Activate)
{
Refresh()
}
}

Show a Dialog Box from non event thread

I need to show a Dialog box, from an app started via an alternate entry point, when a push message arrives.
To do this I need to create an Application instance from the alternate entry point and listen for incoming push.
The problem is when I extend my application class from UiApplication, and call enterEventDispatcher() from the alternate entry point it shows an application icon in running applications forever.
I need to listen for push messages and alert user by a dialog without having an application icon.
So is there any way I can show a dialog from an alternate entry point without a UI event thread?
You can use global dialog. Just use this code.
synchronized (Application.getEventLock()) {
UiEngine ui = Ui.getUiEngine();
Screen screen = new Dialog(Dialog.D_OK, "Look out!!!", Dialog.OK,
Bitmap.getPredefinedBitmap(Bitmap.EXCLAMATION),
Manager.VERTICAL_SCROLL);
ui.pushGlobalScreen(screen, 1, UiEngine.GLOBAL_QUEUE);
}

Detect when app resigns active in cocoa?

Is there any way to detect when an app is no longer active? That is, listen for changes to this:
[NSApp isActive]
In your app delegate, implement your choice of -applicationDidResignActive: or -applicationWillResignActive:.
Alternately, listen for the NSApplicationDidResignActiveNotification or NSApplicationWillResignActiveNotification notifications on NSApp.

Resources