I'm looking for some guidance on how to handle the Appearing / Disappearing in Xamarin Forms Android inside a Tabbed page.
I have a app similar to Snapchat, a 3 tabbed app with the 'Main' tab having a camera live stream.
Now opening the camera happens in "OnAppearing" and closing in "OnDisappearing".
Android
First load
MainPage:
OnAppearing
OnDisappearing
OnAppearing
SecondPage:
OnAppearing
ThirdPage:
OnAppearing
MainPage to SecondPage:
MainPage:
OnDisappearing
SeconPage: nothing
ThirdPage: nothing
SecondPage to ThirdPage:
MainPage: nothing
SeconPage:
OnDisappearing
ThirdPage: nothing
ThirdPage to SecondPage:
MainPage: nothing
SeconPage:
OnAppearing
ThirdPage:
OnDisappearing
SecondPage to MainPage:
MainPage:
OnAppearing
SeconPage:
OnDisappearing
ThirdPage: nothing
iOS
First load
MainPage:
OnAppearing
SecondPage: nothing
ThirdPage: nothing
MainPage to SecondPage:
MainPage:
OnDisappearing
SeconPage:
OnAppearing
ThirdPage: nothing
SecondPage to ThirdPage:
MainPage: nothing
SeconPage:
OnDisappearing
ThirdPage:
OnAppearing
ThirdPage to SecondPage:
MainPage: nothing
SeconPage:
OnAppearing
ThirdPage:
OnDisappearing
SecondPage to MainPage:
MainPage:
OnAppearing
SeconPage:
OnDisappearing
ThirdPage: nothing
Due to the inconsistenties I added a CurrentPageChanged eventhandler in the tabbed page.
protected override void OnCurrentPageChanged()
{
//Check which page is shown and fire a method isShown / isHidden
}
Now it is also possible that a Modal is opened on top of the camera:
So there the camera should close as well, when the modal is closed, the camera re-opened.
Now doing these fires the OnAppearing / OnDisappearing correctly on both OS.
Except when the app get's minified (home button), then again there are inconsistenties.
So we are on the 'MainPage' and we open the modal:
Android
Without minifying app
MainPage:
OnDisappearing
#close modal
MainPage:
OnAppearing
Minifying app in between
MainPage:
OnDisappearing
#minify
#reopen
MainPage:
OnAppearing
#close modal
MainPage: nothing
iOS
Without minifying app
MainPage:
OnDisappearing
#close modal
MainPage:
OnAppearing
Minifying app in between
MainPage:
OnDisappearing
#minify
#reopen
MainPage: nothing
#close modal
MainPage:
OnAppearing
As you can see, opening and closing the camera using the CurrentPageChanged, Appearing and Disappearing is challenging due to the inconsistenties.
Has anyone tackled this problem before ?
I've been thinking to add an event to the Modal, and fire that event when it will close itself, and close the camera prior to opening that modal so I should not need onAppearing / onDisappearing anymore. But in one case I do need it, when the user initially denied permission to the camera, we show a dialog to open the settings for them and change it, when they come back, OnAppearing should recheck permissions and open the camera.