locked
Busy spinner between tabs RRS feed

  • Question

  • User390160 posted

    Hello All,

    I have been working my first xamarin app for awhile. I have a shell application, I am using MVVM, and I am struggling with the first time I navigate to a tab, in that it takes awhile to load. I am not sure how to show a busy spinner, because the view contains the busy spinner and by the time the view has rendered to show the control, there is no need for a busy spinner. So how can I get a busy spinner to show?

    Sunday, May 10, 2020 8:36 PM

All replies

  • User382871 posted

    So how can I get a busy spinner to show? Xamarin.Forms provides the ActivityIndicator` control which could be used to display an animation to show that the application is engaged in a lengthy activity.

    Set binding for the status properties of ActivityIndicator. <ActivityIndicator VerticalOptions="Center" IsVisible="{Binding IsBusy}" IsRunning="{Binding IsBusy}"/> Add the IsBusy property in view model class. private bool _isBusy; public bool IsBusy { get{return _isBusy;} set { _isBusy=value; RaisePropertyChanged(); } } Load the page views. ``` public async void LoadData() { IsBusy=true; //Show the Indicator

    //load data and do other stuffs if you need to do;
    
    IsBusy=false;   //Hide the Indicator
    

    } ```

    Tutorial: https://docs.microsoft.com/en-us/xamarin/xamarin-forms/user-interface/activityindicator

    Check the link: https://stackoverflow.com/a/53749293/11083277

    Monday, May 11, 2020 8:09 AM
  • User390160 posted

    Jarvan

    I am quite familiar with what you have shown above, in face that is EXACTLY how my code is set up. HOWEVER, the INITIAL tab load is SLOW. It takes about a second or so versus after the tab has loaded, going back to the tab loads immediately. I am using syncfusion controls. I removed most of their controls from the view and it then loads extremely fast. It has nothing to do with the ViewModel getting data. Infact I removed the calls to the data layer and it was still slow on the initial loading.

    Monday, May 11, 2020 2:42 PM
  • User390160 posted

    So I changed my code and split up the Initialize method. (i will copy in the code below) On the Galaxy 10 it sped things up a lot. On the SamSung G920V Android 7 .... clunky at best The tab takes a second or two before it even appears (for any tab navigation) Then the view appears, then the busy spinner, then the data loads. Honestly it looks horrible.

    public async void Initialize() { IsBusy = true;

            Task atmospherics = Task.Run(() => 
            {
                SetDefaults();
                ExecuteLoadAtmospherics();
                SetAtmospherics();
                SetWindDirectionDisplay(WindDirection);
            });
    
            Task loadData = Task.Run(() =>
            {
                RangeCardTargets = new ObservableCollection<TargetProfile>();
                AvailableRangeCards = new ObservableCollection<RangeCard>();
                AvailableRangeCards.CollectionChanged += AvailableRangeCards_CollectionChanged;
    
                ExecuteLoadUserRifles();
                ExecuteLoadRangeCards();
            });
    
            await Task.Delay(1000);
    
            Task.WaitAll(atmospherics, loadData);
    
            /* We need to capture the current solver state when its loaded */
            PreviousSolverResultType = (SolverResultType)Preferences.Get(ApplicationSettingsIdentifiers.SolverResultType, 0);
            SubscribeToMessages();
            HasInitialized = true;
    
            IsBusy = false;
        }
    
    Monday, May 11, 2020 4:05 PM
  • User382871 posted

    The tab takes a second or two before it even appears (for any tab navigation) Try to comment the following code, it'll delay the data loading. await Task.Delay(1000);

    Tuesday, May 12, 2020 6:57 AM
  • User390160 posted

    I am confused at what you're saying? Are you saying comment out those two lines?
    Those are purposely there to get the busy spinner to SHOW. otherwise the view has not loaded yet and the busy spinner will NOT show.
    The tab delay is ONLY on INITIAL load. After that, all the control the view on the tab have loaded. I an remove all the controls from the view and the tab loads snappy.
    I can comment out the code above and the tab still loads slow in INITIAL load. I switched to an older phone, Adroid 7, tab navigation was clunky at best....even removing all data from the tabs.

    Tuesday, May 12, 2020 1:38 PM
  • User382871 posted

    On the Galaxy 10 it sped things up a lot. On the SamSung G920V Android 7 .... clunky at best Did this issue only occur for the Android 7 device? What about ios? Does the application work well on ios?

    Wednesday, May 13, 2020 7:50 AM
  • User390160 posted

    I am the only developer so we are doing android first then bringing IOS up to date. Android 7 is horrible....its extremely glitchy and slow.
    I removed all controls from the tabs and they load slow no matter what in Android 7....with absolutely no control or data on the tab.....the initial visit is very slow in Android 7

    Wednesday, May 13, 2020 1:55 PM
  • User382871 posted

    with absolutely no control or data on the tab.....the initial visit is very slow in Android 7 I tested a shell application about the issue on Android 7, it works fine. Would you mind sharing a basic demo to reproduce the issue? It'll help to get the cause.

    Thursday, May 14, 2020 8:30 AM
  • User390160 posted

    Are you using an emulator or an actual device? That can make a difference. All I did was create a basic shell application (pasted in below) Simple navigation on android 7 is not snappy like it is with Android 10. When I add the syncfusion controls back in, initial tab navigation is very slow in android 7, tab navigation in general is not smooth like Android 10. Android 10 is less than snappy on initial tab load but at least has a smooth transition.

    Thursday, May 14, 2020 2:45 PM
  • User390160 posted

    Well apparently it did not let me paste in the code.
    Basically just followed this example https://docs.microsoft.com/en-us/xamarin/xamarin-forms/app-fundamentals/shell/flyout I have a flyout with 4 tabs, each tab has a page.

    Thursday, May 14, 2020 2:48 PM
  • User382871 posted

    Are you using an emulator or an actual device? That can make a difference. ... Basically just followed this example I test the code in an android 7 emulator. Did you test the demo on another android 7 device? The issue may be caused by the device, try test to vertify that. And will the official sample work well on your Android 7 device?

    Friday, May 15, 2020 7:33 AM
  • User390160 posted

    Sorry I have not head the time yet. I will do a factory reset and test. However, I have another question i have been struggling with. Do you know much about Plugin BLE and connecting to a device that is Android.BlueTooth.BluetoothDevice.Dual ? My understanding is this device supports classic and LE. However I cannot connect to this device at all. The other devices I have that are Android.BlueTooth.BluetoothDevice.Le I can connect to flawlessly

    Thursday, May 21, 2020 4:23 AM