Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shell login/logout title don't follow databinding #1

Open
ncarandini opened this issue May 25, 2020 · 13 comments
Open

Shell login/logout title don't follow databinding #1

ncarandini opened this issue May 25, 2020 · 13 comments

Comments

@ncarandini
Copy link
Owner

The shell tab item:

<Tab Title="{Binding LogInOutTitle}" Icon="{Binding LogInOutIconName}">
    <ShellContent ContentTemplate="{DataTemplate views:LoginPage}" />
</Tab>

has an issue with the Title, that don't update from "Login" to "Logout" when the user logs in.
Oddly enought, the Icon works fine.

@biapar
Copy link
Collaborator

biapar commented May 26, 2020

Maybe an error into ViewModelBase.cs. The flag IsLogged is always false.

@ncarandini
Copy link
Owner Author

@biapar there is no IsLogged variable in the ViewModelBase.cs.
I have:

public bool IsUserLogged => AuthenticationService.UserContext?.IsLoggedOn ?? false;

Moreover, on the AppShellViewModel I don't use it as I have this method tied to a AuthenticationStateChanged event:

private void OnAuthenticationStateChanged(object sender, EventArgs e)
{
    LogInOutTitle = !AuthenticationService.UserContext?.IsLoggedOn ?? true ? "Login" : "Logout";

    OnPropertyChanged(nameof(LogInOutTitle));
    OnPropertyChanged(nameof(LogInOutIconName));
}

and on the AppShell I have:

<Tab Title="{Binding LogInOutTitle}" Icon="{Binding LogInOutIconName}">
    <ShellContent ContentTemplate="{DataTemplate views:LoginPage}" />
</Tab>

Finally, when running the app with the mocked authentication service, you can see that the icon change but the text don't:
image
To me this smell as a Xamarin Forms Shell bug.

@biapar
Copy link
Collaborator

biapar commented May 26, 2020

In this class ViewModelBase : BaseViewModel

 async Task UserLogin()
        {
            if (!IsLogging)
            {
                IsLogging = true;
                try
                {
                    // TODO: Analytics.TrackEvent("UserLogin");
                    await AuthenticationService.SignInAsync();
                }
                catch (Exception)
                {
                }
                finally
                {
                    IsLogging = false;
                }
            }
        }

@biapar
Copy link
Collaborator

biapar commented May 26, 2020

Other strange thing is that I'm able to register a new user, login via Facebook but the app don't receive the token.
I see the users into the ADB2C users.

@ncarandini
Copy link
Owner Author

ncarandini commented May 27, 2020

@biapar read carefully, here I'm using a IsLogging variable to mark the ongoing logging operation, not IsLogged ! The semantic is completely different (and the name also 😄 ). It's true while logging, then is is set to false.

@biapar
Copy link
Collaborator

biapar commented May 28, 2020

Ok. I did not see that the icon change in tab bar. I'll check again. My mistake.

@ncarandini
Copy link
Owner Author

ncarandini commented May 28, 2020

  1. Did you see that you missed the name of the variable (IsLogging instead of IsLogged )?
    if so, please acknowledge the fact. Otherwise I can't know if I'm still missing something about your comments.
  2. The icon changes and you can see it also in the image I've posted. the login icon has the frame hole on the left side and the arrow going from outside left to inside right, while the logout icon has the frame hole on the right side and the arrow going from inside left to outside right. Find the difference!

@biapar
Copy link
Collaborator

biapar commented May 28, 2020

  1. I remove the IsLogging = false; from finally branch because I see always the login link also if I logged. But there is a strange think that I see while debugging that cause that variable go to false. In the SignInAsync() function the token is null.
finally
            {
                //Why pass AccessToken null if I logged and before it was not null????? -> BP20200527
                await SetAccessTokenAsync(userContext?.AccessToken);
                UserContext = userContext;
                OnAuthenticationStateChanged();
            }

image

  1. I see that. I'm trying to understand why the label don't change.

@biapar
Copy link
Collaborator

biapar commented May 28, 2020

Solved with a workaround. I use the messages. I remove binding on Title.

In AppShellViewModel:

private void OnAuthenticationStateChanged(object sender, EventArgs e)
        {
            LogInOutTitle = !(AuthenticationService.UserContext?.IsLoggedOn) ?? true ? "Login" : "Logout";

            MessagingCenter.Send<AppShellViewModel, string>(this, "changeTitle", LogInOutTitle);

            OnPropertyChanged(nameof(LogInOutTitle));
            OnPropertyChanged(nameof(LogInOutIconName));
        }

In AppShell

MessagingCenter.Subscribe<AppShellViewModel, string>(this, "changeTitle", (sender, arg) =>
             {
                 this.tabLogin.Title = arg;
             });

image

@ncarandini
Copy link
Owner Author

//Why pass AccessToken null if I logged and before it was not null?????

Usually, but I have to further investigate if this is the case, just for security reason. But this has nothing to do with IsLogging that is a flag that is true only while logging, and then has to be set to false, so it's wrong to remove it.

@biapar
Copy link
Collaborator

biapar commented May 29, 2020

I restored the original code. The tab title don't change also if the flags are ok.

@ncarandini
Copy link
Owner Author

The workaround works, but why using Messaging Center when there is already an event you can subscribe? Hope you don't mind if I'll do it differently.

@ncarandini
Copy link
Owner Author

I restored the original code. The tab title don't change also if the flags are ok.

True, I've created an issue on Xamarin forms for the bug and a repro

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants