FreshMvvm icon indicating copy to clipboard operation
FreshMvvm copied to clipboard

FreshTabbedFONavigationContainer ViewIsAppearing events on FormsAppCompatActivity

Open SplayConsulting opened this issue 9 years ago • 11 comments

There is an issue with the ViewIsAppearing event on Tabbed navigation containers.

In the sample app, the ViewIsAppearing runs nicely on each page when its tab is selected. I tested this by adding an alert on each one's ViewIsAppearing event.

If you take the same sample project and add the Holo theme and set the base class of the Droid MainActivity to global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity Then run the tabbed sample you will see that when the tabbed container loads, it loads each tab page in the background firing the ViewIsAppearing on a few of them.

It doesn't fire them in sequence, in the case of three tabs, it fires the first one, then the first one again, then the last one. When I navigate to the last one & click the middle one, it fires the ViewIsAppearing on the first one even though it actually visibly loads the middle one.

So, to summarize, with FormsAppCompatActivity the tabbed containers fire the ViewIsAppearing event on each tab page on initial load and the second tab's ViewIsAppearing event is mixed up with the first tabs event.

SplayConsulting avatar Oct 13 '16 10:10 SplayConsulting

This is a issue in Xamarin.Forms.

rid00z avatar Oct 13 '16 10:10 rid00z

Really? Is there a way to get around it?

SplayConsulting avatar Oct 13 '16 11:10 SplayConsulting

I had same issue with below simple sample: the Page1PageModel's ViewIsAppearing fires twice each time. Is this issue in Xamarin.Forms?

 public App()
        {
            var main = new FreshTabbedFONavigationContainer("App1")
            {
                BarBackgroundColor = Color.Blue,
                BarTextColor = Color.White
            };
            main.AddTab<Page1PageModel>("Page1", "page1.png");
            main.AddTab<Page2PageModel>("Page2", "page2.png");

            MainPage = main;
        }

jzhouw avatar Oct 27 '16 15:10 jzhouw

I'm willing to believe it's a Xamarin.Forms issue, as it still has some start-up issues, but @rid00z can you point to the source that states it's an issue? And perhaps a solution or workaround?

We have the same issue with the FreshTabbedNavigationContainer. I can confirm it's at least Android only, just tested it with the iOS simulator and the ViewIsAppearing only get's called when you expected it to be called.

While waiting for an answer I'll go back to the drawing board (and Google) and see if I can find something to solve this.

Arie-Kanarie avatar Dec 01 '16 14:12 Arie-Kanarie

@rid00z I agree with @Arie-Kanarie . Can you tell why it's a problem with Forms so I can fill a bug report and maybe provide a solution for them? I wonder how it's a Forms problem since Forms can't even deal with events like ViewIsAppearing. All Pages in a TabbedPage always show as "visible". So I don't know how your ViewIsAppearing event works. @SplayConsulting and @Arie-Kanarie there's an easy workaround. Since the same instance is firing twice, and not two different instances, you can create a variable to control it. Something like:

        private bool _hasShownMyPopUp = false;
        protected override void ViewIsAppearing(object sender, EventArgs e)
        {
            base.ViewIsAppearing(sender, e);
            loadMyStuff(); //leave the stuff that is undone in ViewIsDisappearing outside of the if
            if(!_hasShownMyPopUp )
            {
                _hasShownMyPopUp = true;
                showMyPopUp();
            }
        }

Ugly, I know, but it works.

EDIT: There's a problem. ViewIsAppearing is being fired twice because ViewIsDisappearing is being fired right after ViewIsAppearing is called the first time. So my workaround may cause problems when undoing things that were done in ViewIsAppearing. This kind of stuff will need to be called again after ViewIsDisappearing. Careful with that.

dpedrinha avatar Aug 03 '17 02:08 dpedrinha

This is a issue in Xamarin.Forms.

Has this been raised with Xamarin and is there any effort underway to resolve this?

My app uses the FreshTabbedNavigationContainer. My PageModel classes load their data when the page appears using ViewIsAppearing, and this works great in iOS. However, this "issue" makes the Android app initialization take a LONG time.

If this isn't resolved, or a workaround isn't suggested, I may have to look at replacing FreshMvvm with a different MVVM framework, and I'd hate to do that.

barryculhane avatar Aug 14 '17 18:08 barryculhane

Can you replicate this issue with Xamarin without FreshMVVM? I know I couldn't. So I don't think they will accept any bug report (cuz it's not their fault). About migrating to another MVVM framework. What do you have in mind? I'm looking for something with less bugs and with better support too.

dpedrinha avatar Aug 16 '17 04:08 dpedrinha

Hi, I will look into this issue asap and provide a resolution asap.

Thanks

On Wed, 16 Aug 2017 at 12:16 pm, dpedrinha [email protected] wrote:

Can you replicate this issue with Xamarin without FreshMVVM? I know I couldn't. So I don't think they will accept any bug report (cuz it's not their fault). About migrating to another MVVM framework. What do you have in mind? I'm looking for something with less bugs and with better support too.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/rid00z/FreshMvvm/issues/111#issuecomment-322662372, or mute the thread https://github.com/notifications/unsubscribe-auth/ABeXvYtJDKQJ3C7fHqV_tmQefrxh3JXWks5sYm0MgaJpZM4KVvin .

--

[image: XAM-Consulting Pty Ltd] http://www.xam-consulting.com/

[image: Twitter] https://twitter.com/XAMConsulting [image: LinkedIn] https://www.linkedin.com/company-beta/5791295/

Michael Ridland / Director / Xamarin & Microsoft MVP [email protected] / 0404 865 350

XAM Consulting Pty. Limited. Web | Cloud | Apps | Xamarin 210/29 Kiora Rd, Miranda NSW 2228 xam-consulting.com http://www.xam-consulting.com/

rid00z avatar Aug 16 '17 12:08 rid00z

Hello Michael, any news on this problem?

dpedrinha avatar Sep 06 '17 06:09 dpedrinha

Any updates on this issue? I have a XF app, running on Android and the ViewIsAppearing is being called multiple times. Interestingly, immediately after the first ViewIsAppearing is called, ViewIsDisappearing is called.

mwerickson avatar Oct 05 '17 15:10 mwerickson

I was facing the same issue today. But after doing a bit of googling , I found this is a known issue and it is not specific to FreshMvvm. Its more to do with Xamarin.Android. More information here https://bugzilla.xamarin.com/show_bug.cgi?id=44211 . And it seems to be resolved in Xamarin Forms 3.0.0. I would check and let you know.

libin85 avatar Jun 25 '18 04:06 libin85