0

I have a total of 4 pages in the application

  • 2 in the shell - TabBar
  • The other 2 outside of it

When installing the app for the first time, the user must be taken to the Login screen, as he does not have yet been authenticated. If it is already authenticated (it has a token), it is taken to the Notifications screen.

The problem I am facing is that even though these checks are working (user being taken to the correct screens), when he goes to the Login page (either because it is his first installation of the app or because his account has already been closed and he wants to open another) a check that I put on the notifications page (in the OnAppearing () function) is triggered at the same time as the Login page is shown next.

I wonder if anyone would know a possible solution.

AppShell.xaml

<TabBar>
        <Tab Icon="notificacao_icone.png"
             Title="Notificações">
            <ShellContent ContentTemplate="{DataTemplate local:NotificacoesPage}" />
        </Tab>

        <Tab Icon="configuracoes_icone.png"
             Title="Configurações">
            <ShellContent ContentTemplate="{DataTemplate local:ConfiguracoesPage}" />
        </Tab>
</TabBar>

AppShell.xaml.cs

public partial class AppShell : Shell
    {
        public AppShell()
        {
            InitializeComponent();

            Routing.RegisterRoute(nameof(LoginPage), typeof(LoginPage));
            Routing.RegisterRoute(nameof(TokenPage), typeof(TokenPage));
            Routing.RegisterRoute(nameof(NotificacoesPage), typeof(NotificacoesPage));
            Routing.RegisterRoute(nameof(NotificacaoDetalhePage), typeof(NotificacaoDetalhePage));
            Routing.RegisterRoute(nameof(ConfiguracoesPage), typeof(ConfiguracoesPage));

            MainThread.BeginInvokeOnMainThread(async () =>
            {
                await Task.Delay(500);

                // Carrega configurações do banco de dados
                var _config = BdRepository.tableExists("Configuracao");

                try
                {
                    if (!_config)
                    {
                        throw new Exception();
                    }
                    else
                    {
                        var _configuracao = ConfiguracaoRepository.GetAll();

                        if (string.IsNullOrEmpty(_configuracao.cad_token))
                        {
                            throw new Exception();
                        }
                        else
                        {
                            if (_configuracao.cad_token_validado_sn == "S")
                            {
                                // Redireciona para tela de notificacoes                        
                                await Shell.Current.GoToAsync($"{nameof(NotificacoesPage)}", false);
                            }
                            else
                            {
                                // Token nao validado, redireciona para tela de Token
                                await Shell.Current.GoToAsync($"{nameof(TokenPage)}", false);
                            }
                        }
                    }
                }
                catch (Exception)
                {
                    // Redireciona para o cadastro
                    await Shell.Current.GoToAsync($"{nameof(LoginPage)}", false);
                }

            });
        }
    }
José Guilherme
  • 57
  • 1
  • 10
  • Can not clear why display Login contentPage that firing notifications page OnAppearing()? – Cherry Bu - MSFT Mar 24 '21 at 07:59
  • I want this validation of the pages (which will be shown first) to be performed correctly. At the moment, even though the login page is actually shown to the user as the "first", in fact, the entire notification page is being executed (View, ViewModel, etc., which includes the methods within OnAppearing () ) under the hood before the correct page for that validation. – José Guilherme Mar 24 '21 at 12:43

0 Answers0